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

View

# Timer Lab

last edited by 7 years, 5 months ago

PART A

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

int noteDurations[] = {

8, 16, 16, 8,8,8,8,8 };

Double the length (change to eighth and 16th notes)

b. What song is playing? ;-)

Star wars theme song!

PART B

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

5 V

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

Everything worked the first time!

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

lcd.print("hello, world!"); -> lcd.print("BRENDAN FREUND");

PART C

1. POTENTIOMETER

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

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

int ledPin = 13;      // select the pin for the LED

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

int brightness = 0;

void setup() {

// declare the ledPin as an OUTPUT:

pinMode(ledPin, OUTPUT);

}

void loop() {

// read the value from the sensor:

brightness = map(sensorValue, 0, 1023, 0, 255);

analogWrite(ledPin, brightness);

}

2. FLEX SENSOR

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

It ranges from about 24kohm flat to 28 kohm bent

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

From the values I measured, my sensor yields a small voltage range of 1.50 – 1.65 V (using the voltage divider equation).

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

It’s much smaller. I adjusted my map function to map(sensorValue, 150, 350, 0, 255) to get a more visible change in brightness.

#include <LiquidCrystal.h>

int sensorPin = A0;

// initialize the library with the numbers of the interface pins

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

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("BRENDAN FREUND");

}

void loop() {

// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

}

3. FORCE SENSITIVE RESISTOR

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

Extremely high resistance (around 6Mohm), to 15kohm when pressed fully.

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

Seems to be pretty linear until the end when it peaks at a minimum resistance.

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

int sensorPin1 = A0;

int sensorPin2 = A1;

int ledPin1 = 13;      // select the pin for the LED

int ledPin2 = 10;

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

int sensorValue2 = 0;

int brightness1 = 0;

int brightness2 = 0;

// initialize the library with the numbers of the interface pins

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

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// declare the ledPin as an OUTPUT:

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

// Print a message to the LCD.

lcd.print("BRENDAN FREUND");

}

void loop() {

// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

brightness1 = map(sensorValue1, 0, 700, 0, 255);

analogWrite(ledPin1, brightness1);

lcd.print(sensorValue1);

lcd.setCursor(4, 1);

brightness2 = map(sensorValue2, 0, 700, 0, 255);

analogWrite(ledPin2, brightness2);

lcd.print(sensorValue2);

}