| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

DanielAssumpcao_Lab3

Page history last edited by Vivien Tsao 7 years ago

Part A

a. How would you change the code to make the song play twice as fast?

You can either double all of the values in noteDuration[] or change  int noteDuration = 1000/noteDurations[thisNote]; to  int noteDuration = 500/noteDurations[thisNote]; You will also need to half the value of pauseBetweenNotes to keep everything proportional.

b. What song is playing? ;-)

The song from Star Wars

Part B 

a. What voltage level do you need to power your display?

Between 4.7 and 5.5 volts 

b. What was one mistake you made when wiring up the display? How did you fix it?

I did not connect the power to the correct pin. I discovered this by measuring the voltage with the multimeter. Then I connected the wire to the correct pin.

c. What line of code do you need to change to make it flash your name instead of "Hello World"?

 change  lcd.print("hello, world!"); to lcd.print("Daniel Assumpcao"); in the setup function

 

Part C

1. a. Post a copy of your new code in your lab writeup.

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 9;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); 
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on

 //Divide sensorValue by 4 because the value of sensorValue ranges from 0 to 1023 and analogWrite takes a value from 0 to 255
  analogWrite(ledPin, sensorValue / 4);                
}

2. a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent

9k ohms when flat, 18 k ohms when bent

b. What kind of voltages should we expect for the Arduino analog pin based on the sensor resistance? 

 For an input voltage of 3.3v

24 k ohms / (24k ohms + 9 k ohms) * 3.3 volts = 2.4 volts

24 k ohms / (24k ohms + 18 k ohms) * 3.3 volts = 1.9 volts

 

1.9 volts - 2.4 volts

c. How does the range of the LED's brightness change compared to the potentiometer?

The range of the LED's brightness is less with the flex sensor than compared to the potentiometer.

 

d. Include a copy of your Lowly Multimeter code in your lab write-up.

int ledPin = 9;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); 
  lcd.begin(16, 2);
  Serial.begin(57600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on
  int adjustedValue = map(sensorValue, 510, 750, 0, 255);
  analogWrite(ledPin, adjustedValue); 
  // Print a message to the LCD.
  lcd.clear();
  lcd.print(sensorValue);
  Serial.println(sensorValue); 
}

3. a. What resistance values do you see from your force sensor?

1k ohms - 100k ohms

b. What kind of relationship does the resistance have as a function of force applied? (e.g., linear?)

The resistance drops linearly as more force is applied.

c. Include a copy of your FSR thumb wrestling code in your lab write-up.

int sensor1Pin = A0;    // select the input pin for the potentiometer

int sensor2Pin = A1;

int sensor1Value = 0;  // variable to store the value coming from the sensor

int sensor2Value = 0;

 

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 

void setup() {

  lcd.begin(16, 2);

  // Print a message to the LCD.

  Serial.begin(57600);

}

 

void loop() {

  // read the value from the sensor:

  sensor1Value = analogRead(sensor1Pin);    

  sensor2Value = analogRead(sensor2Pin);

  // Print a message to the LCD.

  lcd.setCursor(0,0);

  if(abs(sensor1Value - sensor2Value) < 10) {

    lcd.write("Tied    ");

  } else if(sensor1Value < sensor2Value) {

    lcd.write("Player 1");

  } else {

    lcd.write("Player 2");

  }

}

Part D

a. Make a short video showing how your timer works, and what happens when time is up!


b. Post a link to the Lab 3 Timers Hall of Fame.

 

 

 

 

Comments (1)

Vivien Tsao said

at 11:28 pm on Jul 28, 2013

Good job! :)

You don't have permission to comment on this page.