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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

EE47: Lab 3

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

Part A. Making Sounds

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

int noteDuration = 1000 / noteDurations[thisNote];      =>      int noteDuration = 500 / noteDurations[thisNote];

b. What song is playing? ;-)

Star wars =P

 

Part B. Writing to the LCD

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

5 V

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

My soldering iron was rusted over, didn't realize that could happen. David had to show me and help me clean it.

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

lcd.print("hello, world!");        =>       lcd.print("Varun Singh");

Part C. Fancy Inputs

 

1. Potentiometer

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://www.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);

 

  if(sensorValue > 255){

    sensorValue = 255;

  } else if(sensorValue < 0){

    sensorValue = 0;

  }

 

  analogWrite(ledPin, sensorValue);

}

 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. Flex Sensor

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

10k -> 50k

straight -> bent

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

(R2/(R1+R2)) * V(in) = V(out)

✔great response

straight:

(27000/(10000+27000)) * 3.3 =  (27/37) * 3.3 = 2.4 V

 

Bent:

(27000/(50000+27000)) * 3.3 = (27/77) * 3.3 = 1.2V

 

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

There is a far lower range of values in comparison to the potentiometer.

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

/*

  LiquidCrystal Library - display() and noDisplay()

 

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal

 library works with all LCD displays that are compatible with the

 Hitachi HD44780 driver. There are many of them out there, and you

 can usually tell them by the 16-pin interface.

 

 This sketch prints "Hello World!" to the LCD and uses the

 display() and noDisplay() functions to turn on and off

 the display.

 

 The circuit:

 * LCD RS pin to digital pin 12

 * LCD Enable pin to digital pin 11

 * LCD D4 pin to digital pin 5

 * LCD D5 pin to digital pin 4

 * LCD D6 pin to digital pin 3

 * LCD D7 pin to digital pin 2

 * LCD R/W pin to ground

 * 10K resistor:

 * ends to +5V and ground

 * wiper to LCD VO pin (pin 3)

 

 Library originally added 18 Apr 2008

 by David A. Mellis

 library modified 5 Jul 2009

 by Limor Fried (http://www.ladyada.net)

 example added 9 Jul 2009

 by Tom Igoe

 modified 22 Nov 2010

 by Tom Igoe

 

 This example code is in the public domain.

 

 http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

 

 */

 

// 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() {

  pinMode(ledPin, OUTPUT);

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

  lcd.begin(16, 2);

}

 

void loop() {

  sensorValue = analogRead(sensorPin);

 

  lcd.clear();

  lcd.print(sensorValue);

 

  analogWrite(ledPin, sensorValue);

  delay(1000);

}

 

3. Force Sensitive Resistor

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

0-1000 Ohms

Resistance should be very high (infinite or M Ohms) when the FSR is not pressed. Resistance should lower to a few hundred Ohms, or low K Ohms, when pressed hard. -0.25

 

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

It follows a power law until the force saturation (maximum detectable force). (datasheet)

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

/*

  LiquidCrystal Library - display() and noDisplay()

 

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal

 library works with all LCD displays that are compatible with the

 Hitachi HD44780 driver. There are many of them out there, and you

 can usually tell them by the 16-pin interface.

 

 This sketch prints "Hello World!" to the LCD and uses the

 display() and noDisplay() functions to turn on and off

 the display.

 

 The circuit:

 * LCD RS pin to digital pin 12

 * LCD Enable pin to digital pin 11

 * LCD D4 pin to digital pin 5

 * LCD D5 pin to digital pin 4

 * LCD D6 pin to digital pin 3

 * LCD D7 pin to digital pin 2

 * LCD R/W pin to ground

 * 10K resistor:

 * ends to +5V and ground

 * wiper to LCD VO pin (pin 3)

 

 Library originally added 18 Apr 2008

 by David A. Mellis

 library modified 5 Jul 2009

 by Limor Fried (http://www.ladyada.net)

 example added 9 Jul 2009

 by Tom Igoe

 modified 22 Nov 2010

 by Tom Igoe

 

 This example code is in the public domain.

 

 http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

 

 */

 

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

int sensorPin2 = A1; 

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

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

int sensorValue2 = 0; 

 

void setup() {

  pinMode(ledPin, OUTPUT);

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

  lcd.begin(16, 2);

}

 

void loop() {

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);

 

  lcd.clear();

 

  if(sensorValue1 > sensorValue2){

    lcd.write("player one");

  } else {

    lcd.write("player two");

  }

  lcd.setCursor(0,1);

  lcd.write("is winning");

 

  analogWrite(ledPin, sensorValue1);

  delay(100);

}

 

Part D. Timer

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.

 

 

 

 

 

 

 

 

Comments (1)

zahraa@... said

at 9:24 pm on Aug 4, 2015

good job

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