Ryan Curtis
EE 47
Summer 2015
Lab 3
Part A
a. How would you change the code to make the song play twice as fast?
Change to following line:
int noteDuration = 1000 / noteDurations[thisNote];
So that it reads:
int noteDuration = 500 / noteDurations[thisNote];
✔
b. What song is playing? ;-)
It is playing the theme song from Star Wars.
✔
Part B
a. What voltage level do you need to power your display?
You need around 5V to power the LCD display.
✔
b. What was one mistake you made when wiring up the display? How did you fix it?
I made a mistake in the wiring of the potentiometer and had to rearrange the leads until it was able to turn on the LCD
✔
c. What line of code do you need to change to make it flash your name instead of "Hello World"?
I changed the line lcd.print("Hello World"); to be lcd.print("Ryan Curtis");
✔
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 = 13; // 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);
// adjust the brightness of LED
analogWrite(ledPin, sensorValue/170);
}
✔
Correct, but It needs to be divided by 4 also because the analog input resolution is 10 bits, and the PWM output is 8 bits. The program will work without that division, although the LED will change value from high to low 4 times over a full potentiometer rotation.
2.
a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent?
It is about 9000 Ohms when flat and about 30000 Ohms when bent.
✔
b. What kind of voltages should we expect for the Arduino analog pin based on the sensor resistance?
We should expect between 3 and 5 V on the pin from the sensor.
✔
c. How does the range of the LED's brightness change compared to the potentiometer?
The range of brightness on the LED is much larger than on the potentiometer.
✔
d. Include a copy of your Lowly Multimeter code in your lab write-up.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// adjust the brightness of LED
analogWrite(ledPin, sensorValue/170);
// Print a message to the LCD.
lcd.clear();
lcd.print(sensorValue);
}
✔
3.
a. What resistance values do you see from your force sensor?
It reads resistance values between 1000 and 10000 ohms depending on the force applied.
✔
b. What kind of relationship does the resistance have as a function of force applied? (e.g., linear?)
There is a linear relationship between the two but it has a negative slope. This means that an increase in the force will cause a linear decrease in the resistance.
✔
c. Include a copy of your FSR thumb wrestling code in your lab write-up.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPinL = A0; // select the input pin for the potentiometer
int sensorPinR = A1; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValueL = 0; // variable to store the value coming from the sensor
int sensorValueR = 0; // variable to store the value coming from the sensor
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensors:
sensorValueL = analogRead(sensorPin1);
sensorValueR = analogRead(sensorPin2);
lcd.clear();
if(sensorValue1 > sensorValue2)
lcd.print("LEFT");
else if(sensorValue1 < sensorValue2)
lcd.print("RIGHT");
else
lcd.print("Tie");
}
✔
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.