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


Lab 3 - Cam Bennett

Page history last edited by Cam Bennett 8 years ago

Make a Digital Timer!


Part A. Making Sounds


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

     On line 35 ( int noteDuration = 1000/noteDurations[thisNote];) change the 1000 to 500.  

b. What song is playing? ;-)

     The Star Wars Theme.

Part B. Writing to the LCD


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


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

     The LCDs we were using had 18 pins instead of 16, so I mistakenly wired pins 13-16 instead of pins 11-14. To fix it, I simply used the right pins.

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

      On Line 48 ( lcd.print("hello, world!");) change the text in the quotes to Cam.

Part C. Fancy Inputs

1. Potentiometer

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


int sensorPin = A0; 
int ledPin = 12;     
int sensorValue = 0;


void setup() {
  pinMode(ledPin, OUTPUT); 

void loop() {
  sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 255);
  analogWrite(ledPin, sensorValue); 

2. Flex Sensor


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

     11K Ohms when it is flat, aroudn 25K Ohms when bent at a right angle.

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

     Assuming the flex sensor is connected to 5 volts, 3.3 volts when it is flat and 2.5 when bent(approximately).

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

     The range of the brightness change is much less than with the pot. 

d. 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 = A8; 
int sensorValue = 0;

void setup() {
  lcd.begin(16, 2);

void loop() {
  sensorValue = analogRead(sensorPin);

3. Force Sensitive Resistor


Just like the Flex sensor, the FSR changes resistance—in this case, when pressure is applied to the FSR. Here's the datasheet. We can reuse the same circuit as before. (It's okay to remove the LED, though.)


Now build two FSR circuits to enable a game of thumb wrestling. Take another FSR from the parts shelf, but be sure to return it when done! (We don't have enough for everyone to have 2). Use the LCD to indicate who is squeezing their FSR harder!

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

     Resistance is infinite when untouched. When depressed with superhuman strength like my own, it drops to around 250 KOhms.

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

     The relationship is not linear. It's going ok, although resistance wants to live together and force is still a bit afraid of commitment. In actuality, the graph would look something like resistance = constant/force, as resistance drops very quickly with a little force but slows its decrease eventually. At very high forces, the amount of force required to decrease resistance by even 1K Ohm is high.

c. 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 sensorPinA = A8;
int sensorPinB = A7;
int sensorValueA = 0;
int sensorValueB = 0;

void setup() {
  lcd.begin(16, 2);

void loop() {
  sensorValueA = analogRead(sensorPinA);
  sensorValueB = analogRead(sensorPinB);
  if(sensorValueA > sensorValueB) {
    lcd.print("Player 1 Wins!!!!");
  } else if (sensorValueB > sensorValueA) {
    lcd.print("Player 2 Wins!!!!");
  } else {


Part D. Timer

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


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


Comments (1)

Benjamin Tee said

at 1:52 am on Aug 6, 2012

good job! Didn't see your video...

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