| 
  • 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
 

Nadan_Paul_Lab3

Page history last edited by zahraa@... 5 years, 1 month ago

Part A. Making Sounds 

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

Divide the noteDuration by 2 by changing the line

     int noteDuration = 1000 / noteDurations[thisNote];

to

     int noteDuration = 500 / noteDurations[thisNote];

b. What song is playing? ;-)

The Star Wars opening theme.

✔ 

 

Part B. Writing to the LCD

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

5 volts.

✔ 

 

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

One of the potentiometer pins wasn't plugged into the breadboard all the way, so the display wouldn't turn on. I fixed it by moving the potentiometer to a spot with more free space around it so I could attach it correctly.

✔ 

 

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

Change the line

     lcd.print("hello, world!");

to

     lcd.print("hello, Paul!");

✔ 

 

Part C. Fancy Inputs

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

int sensorPin = A0;

int ledPin = 9;

int sensorValue = 0;

 

void setup() {

}

 

void loop() {

  sensorValue = analogRead(sensorPin)/4;

  analogWrite(ledPin, sensorValue);

}

✔ great

 

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

When the sensor is flat the resistance is 8kΩ. When it is bent the resistance is 23kΩ.

 

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

Vout = R2/(R1+R2)*Vin

R2 = 27kΩ

Vin = 3.3V

R1 = 8 to 23kΩ

Vout = 27kΩ/((8 to 23kΩ)+27kΩ)*3.3V = 2.5V to 1.8V

✔ 

 

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

The range with the flex sensor is much smaller than with the potentiometer.

✔ 

 

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

#include <LiquidCrystal.h>

 

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

 

int sensorPin = A0;

int ledPin = 9;

int sensorValue = 0;

 

void setup() {

  lcd.begin(16, 2);

}

 

void loop() {

  sensorValue = analogRead(sensorPin);

  // Sensor value ranges from 380 to 530

  analogWrite(ledPin, (sensorValue-380)*255/150);

  lcd.clear();

  lcd.setCursor(0, 1);

  lcd.print(sensorValue);

  delay(100);

}

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

The resistance ranged from 0.3Ω when I was pressing pretty hard to about 60kΩ when I pressed as softly as I could. With no pressure at all, the sensor blocks all of the current, so the resistance is essentially infinite.

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

The resistance is inversely related to the force.

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

#include <LiquidCrystal.h>

 

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

 

int sensorPin1 = A0;

int sensorPin2 = A1;

int sensorValue1 = 0;

int sensorValue2 = 0;

 

void setup() {

  lcd.begin(16, 2);

}

 

void loop() {

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);

  lcd.setCursor(0, 1);

  if(sensorValue1>sensorValue2) {

    lcd.print("Player 1 wins!");

  } else if(sensorValue1<sensorValue2) {

    lcd.print("Player 2 wins!");

  } else {

    // The extra spaces are to clear any previous text

    lcd.print("It's a tie!   ");

  }

}

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

 

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

Comments (1)

zahraa@... said

at 6:04 pm on Aug 11, 2015

well done

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