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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Jay Cammon Digital Timer Lab 3

Page history last edited by xinyi xie 5 years, 11 months ago

Part I

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

 

To make the song play faster make the integer pauseBetweenNotes smaller by maultiplying noteDuration by a smaller number (a number less than 1). 

Ex. int pauseBetweenNotes = noteDuration * 0.5 -- fast

      int pauseBetweenNotes = noteDuration * 3.5 -- slow

 

b. What song is playing? ;-)

 

Star Wars Theme Song

Part II

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

 

The minimum voltage needed to power this display is 2.7 V and the maximum voltage is 5V. This can be found on the LCD Controller Page.

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

 

I did not have my wires fully plugged in because they were too short. So, I had to change the wire to ake sure it could reach the Arduino board. Sadly, I also forgot a few times to connect the USB to the Arduino, after removing it to check the circuit.

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

 

We need to change the lcd.print (); line.

Ex.  lcd.print("Jay Cammon, Jr.");

Part III A

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

 

/*

  Analog Input

 Demonstrates analog input by reading an analog sensor on analog pin 0 and

 turning on and off a light emitting diode(LED)  connected to digital pin 13.

 The amount of time the LED will be on and off depends on

 the value obtained by analogRead().

 

 The circuit:

 * Potentiometer attached to analog input 0

 * center pin of the potentiometer to the analog pin

 * one side pin (either one) to ground

 * the other side pin to +5V

 * LED anode (long leg) attached to digital output 13

 * LED cathode (short leg) attached to ground

 

 * Note: because most Arduinos have a built-in LED attached

 to pin 13 on the board, the LED is optional.

 

 

 Created by David Cuartielles

 modified 30 Aug 2011

 By Tom Igoe

 

 This example code is in the public domain.

 

 http://arduino.cc/en/Tutorial/AnalogInput

 

 */

 

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

int ledPin = 9;      // 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);

  // turn the ledPin on

  digitalWrite(ledPin, HIGH);

  // stop the program for <sensorValue> milliseconds:

  delay(sensorValue);

  // turn the ledPin off:

  digitalWrite(ledPin, LOW);

  // stop the program for for <sensorValue> milliseconds:

  delay(sensorValue);

}

Part III B

 

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

When Flat - 10 Mohms

When Bent - 1. 01Mohms

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

When Flat  - 2.2V

When Bent - 1.8V

 

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

Potentiometer has more intense brightness because it has a  from 19 Mohm - 6 Mohms. Meanwhile the flex sensor stays around 6 - 7 Mohms.

The potentiometer gives the brightness of the LED a wider range.

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

/*

  Analog Input

 Demonstrates analog input by reading an analog sensor on analog pin 0 and

 turning on and off a light emitting diode(LED)  connected to digital pin 13.

 The amount of time the LED will be on and off depends on

 the value obtained by analogRead().

 

 The circuit:

 * Potentiometer attached to analog input 0

 * center pin of the potentiometer to the analog pin

 * one side pin (either one) to ground

 * the other side pin to +5V

 * LED anode (long leg) attached to digital output 13

 * LED cathode (short leg) attached to ground

 

 * Note: because most Arduinos have a built-in LED attached

 to pin 13 on the board, the LED is optional.

 

 

 Created by David Cuartielles

 modified 30 Aug 2011

 By Tom Igoe

 

 This example code is in the public domain.

 

 http://arduino.cc/en/Tutorial/AnalogInput

 

 */

 

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);

  // turn the ledPin on

  digitalWrite(ledPin, HIGH);

  // stop the program for <sensorValue> milliseconds:

  delay(sensorValue);

  // turn the ledPin off:

  digitalWrite(ledPin, LOW);

  // stop the program for for <sensorValue> milliseconds:

  delay(sensorValue);

}

 

Part III C

 

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

There is a minimum resistance of 10 M ohms but the max varies to the amount of pressure (force) applied to the sensors.

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

Linearly because as the force increases so does the resistance simultaneously.

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

 

/*

  Analog Input

 Demonstrates analog input by reading an analog sensor on analog pin 0 and

 turning on and off a light emitting diode(LED)  connected to digital pin 13.

 The amount of time the LED will be on and off depends on

 the value obtained by analogRead().

 

 The circuit:

 * Potentiometer attached to analog input 0

 * center pin of the potentiometer to the analog pin

 * one side pin (either one) to ground

 * the other side pin to +5V

 * LED anode (long leg) attached to digital output 13

 * LED cathode (short leg) attached to ground

 

 * Note: because most Arduinos have a built-in LED attached

 to pin 13 on the board, the LED is optional.

 

 

 Created by David Cuartielles

 modified 30 Aug 2011

 By Tom Igoe

 

 This example code is in the public domain.

 

 http://arduino.cc/en/Tutorial/AnalogInput

 

 */

 

 

#include <LiquidCrystal.h>

 

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

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

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

int brightness = 0;

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

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);

  // initialize serial:

  Serial.begin(9600);

 

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

 // sends sensor value back over the sensor connection to the computer

  Serial.println(sensorValue);

  // change the brightness for next time through the loop:

  brightness = sensorValue/3.5;

  // turn the ledPin on

    analogWrite(ledPin, brightness);    

  Serial.println(brightness); 

  // turn the ledPin on

 

 

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

  lcd.begin(16, 2);

  // Print a message to the LCD.

  lcd.print(sensorValue);

  // stop the program for for <sensorValue> milliseconds:

 

}

 

 

 

Digital Timer Code

 

/*

  Melody

 

 Plays a melody

 

 circuit:

 * 8-ohm speaker on digital pin 8

 

 created 21 Jan 2010

 modified 30 Aug 2011

 by Tom Igoe

 

This example code is in the public domain.

 

 http://arduino.cc/en/Tutorial/Tone

 

 */

#include "pitches.h"

 

// 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);

 

// notes in the melody:

int melody[] = {

  NOTE_D3,NOTE_D3,NOTE_D3,NOTE_G3,NOTE_D4,NOTE_C4,NOTE_B3,NOTE_A3,NOTE_G4,NOTE_D4, \

  NOTE_C4,NOTE_B3,NOTE_A3,NOTE_G4,NOTE_D4,NOTE_C4,NOTE_B3,NOTE_C4,NOTE_A3,0};

 

int noteDurations[] = {

  10,10,10,2,2,10,10,10,2,4, \

  10,10,10,2,4,10,10,10,2,4};

 

 

 

void setup() {

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

  lcd.begin(16, 2);

 

  for (int time = 10; time > 0; time--){

    lcd.print(time);

    delay(1000);

  }

  // iterate over the notes of the melody:

  for (int thisNote = 0; thisNote < 20; thisNote++) {

 

    // to calculate the note duration, take one second

    // divided by the note type.

    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

    int noteDuration = 1000 / noteDurations[thisNote];

    tone(8, melody[thisNote], noteDuration);

 

    // to distinguish the notes, set a minimum time between them.

    // the note's duration + 30% seems to work well:

    int pauseBetweenNotes = noteDuration * 1.30;

    delay(pauseBetweenNotes);

    // stop the tone playing:

    noTone(8);

  }

}

 

void loop() {

// Turn off the display:

  lcd.noDisplay();

  delay(500);

  // Turn on the display:

  lcd.display();

  delay(500);

}

 

Digital timer Video

https://www.youtube.com/watch?v=EeFL_LFchXs

 

Comments (1)

xinyi xie said

at 10:39 am on Jul 23, 2014

Great job!

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