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

View
 

BW_LAB_3

Page history last edited by zahraa@... 4 years, 12 months ago

Part A: Making Sound

 

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

 

Changing the numerator of the noteDuration will change how fast the song plays.

 

    int noteDuration = 500 / noteDurations[thisNote];

 

  1. b.     What song is playing? ;-)

 

Star wars song

 

Part B: Writing to the LCD

 

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

 

According to the spec sheet, a voltage of 5.0V will power the LCD display.

 

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

The 10K potentiometer was not wired correct so the contrast was not correct. I fixed this by grounding the element.

 

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

 

  lcd.print("ben!");

 

 

 

Part C. 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 = 1;  // variable to store the value coming from the sensor

 

void setup() {

}

 

void loop() {

    sensorValue = analogRead(sensorPin) / 4;

    // sets the value (range from 0 to 255):

    analogWrite(ledPin, sensorValue);

  }

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

Flat – 9.1 kOhms

Bend – 30 kOhms

 

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

With a voltage of V = 3.3 V, and using a 27 kOhm resistor for the voltage divider, we should expect voltages ranging from

 

V out = [9.1 / (9.1 +27 )](3.3V) = 0.83 V

V out = [30 / (30 + 27 ) ](3.3V) =  1.74 V

 

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

 

The range of LED changes less because the range of voltage change is less using the voltage divider.

 

 

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

  // Print a message to the LCD.

  lcd.print("Analog readout");

}

 

void loop() {

  // set the cursor to column 0, line 1

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

  sensorValue = analogRead(sensorPin);

  lcd.setCursor(0, 1);

  lcd.print(sensorValue);

}

3. Force Sensitive Resistor

 

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

The force sensor resistance ranges from 10 kOhm to 100 kOhm.

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

The force applied is an inverse power law, with a 1/R relationship for force to resistance.

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

/*sensor readout code

 *

 *

 */

 

// 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 sensorPin0 = A0;    // select the input pin for the potentiometer

int sensorPin1 = A1;    // select the input pin for the potentiometer

int sensorValue0 = 1;  // variable to store the value coming from the sensor

int sensorValue1 = 1;  // 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);

  // Print a message to the LCD.

  lcd.print("Analog readout");

}

 

void loop() {

  // set the cursor to column 0, line 1

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

  sensorValue0 = analogRead(sensorPin0);

  lcd.setCursor(0, 1);

  // print the number of seconds since reset:

  lcd.print(sensorValue0);

 

    sensorValue1 = analogRead(sensorPin1);

  lcd.setCursor(5, 1);

  // print the number of seconds since reset:

  lcd.print(sensorValue1);

}

4. Timer

 

/*sensor readout code

 *

 *

 */

 

// include the library code:

#include "pitches.h"

#include <LiquidCrystal.h>

 

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

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

 

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

int sensorPin1 = A1;    // select the input pin for the potentiometer

int sensorValue0 = 1;  // variable to store the value coming from the sensor

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

int timerValue0 = 100;  // variable to store the value coming from the sensor

int timerValue1 = 100;  // variable to store the value coming from the sensor

 

 

 

// notes in the melody:

int melody[] = {

  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4

};

 

// note durations: 4 = quarter note, 8 = eighth note, etc.:

int noteDurations[] = {

  4, 8, 8, 4, 4, 4, 4, 4

};

 

 

void setup() {

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

  lcd.begin(16, 2);

  // Print a message to the LCD.

  lcd.print("Analog readout");

}

 

void loop() {

  // set the cursor to column 0, line 1

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

  sensorValue0 = analogRead(sensorPin0);

  sensorValue1 = analogRead(sensorPin1);

 

if (sensorValue1 >500)

  {timerValue0 = timerValue0 + 1;

  }

 

if (sensorValue0 >500)

  {timerValue0 = timerValue0 - 1;

  }

 

timerValue1 = timerValue0 - (millis() / 1000);

 

if (timerValue0 <= 0)

  {timerValue0 = 0;

}

 

if (timerValue1 <= 0)

  {timerValue1 = 0;

  for (int thisNote = 0; thisNote < 8; 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);}

 

}

 

       lcd.setCursor(0, 1);

   lcd.print(timerValue0);

 

    lcd.setCursor(5, 1);   

     lcd.print(timerValue1);

}

 

 

 

 

 

Comments (1)

zahraa@... said

at 4:10 pm on Aug 10, 2015

good job

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