a. How would you change the code to make the song play twice as fast? If we wanted the song to play twice as fast, we would need to cut the note durations in half. Or, we can change the value of “pauseBetweenNotes” to one-half its current value.
✔
b. What song is playing? ;-) Star Wars’ theme song!
✔
a. What voltage level do you need to power your display?
2.7 to 5.5 volts for low power operation support.
✔
b. What was one mistake you made when wiring up the display? How did you fix it?
I mistakenly wired pin 5 on the arduino to pin 10 on the lcd. I corrected this by connecting pin 5 on the arduino to pin 11 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 lcd.print("adam");
✔
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);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
// turn the ledPin on
analogWrite(ledPin, sensorValue);
// stop the program for <sensorValue> milliseconds:
delay(30);
// turn the ledPin off:
analogWrite(ledPin, sensorValue);
// stop the program for for <sensorValue> milliseconds:
delay(30);
}
✔
a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent?
Flat: 10.9 kohms
Bent with sensors facing inward: 8.2 kohms
Bent with sensors facing outward 27.5 kohms
✔
b. What kind of voltages should we expect for the Arduino analog pin based on the sensor resistance?
We’ll use the following formula for a voltage divider circuit: Vout = (R2 / (R1 + R2)) * Vin
With, Vin = 3.3 V
R2 = 27 kohms
R1min = 8.2 kohms, and R1max = 27.5 kohms
Vout_min = (27 / (8.2 + 27)) * 3.3 = 2.53 V
Vout_max = (27 / (27.5 + 27)) * 3.3 = 1.63 V
✔
c. How does the range of the LED's brightness change compared to the potentiometer?
The POT has a much greater range of resistance than the flex sensor, therefore the LED brightness varies more with the POT than the flex sensor.
✔
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);
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
//outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
//analogWrite(analogOutPin, outputValue);
lcd.setCursor(0, 0);
lcd.print((sensorValue * 5.0)/1023.0);
Serial.println(sensorValue);
delay(300);
}✔
a. What resistance values do you see from your force sensor?
Approximately 20 mega-ohms when the sensor detects no force and approximately 0.18 kilo-ohms when the sensor detects plenty of force.
✔
b. What kind of relationship does the resistance have as a function of force applied? (e.g., linear?) The resistance takes the form of a logarithmic function as force is applied.✔
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);
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin0 = A0; // Analog input pin that the FSR is attached to
const int analogInPin1 = A1; // Analog input pin that the FSR is attached to
int sensorValue0 = 0; // value read from the FSR1
int sensorValue1 = 0; // value read from the FSR2
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
// read the analog in value:
sensorValue0 = analogRead(analogInPin0);
sensorValue1 = analogRead(analogInPin1);
Serial.println(sensorValue0);
Serial.println(sensorValue1);
lcd.setCursor(0, 0);
lcd.print("Thumb 1: ");
lcd.print((sensorValue0 * 5.0)/1023);
lcd.setCursor(0, 1);
lcd.print("Thumb 2: ");
lcd.print((sensorValue1 * 5.0)/1023);
delay(300);
}
✔
a. Make a short video showing how your timer works, and what happens when time is up!
b. Post a link to theLab 3 Timers Hall of Fame.