Deniz Lab 3


 

            SPEAKER

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

If we change noteDuration*1.30 to

noteDuration*0.65 then the song would play twice as fast

✔ 

b.  What song is playing? ;-)

First song was mario theme song; after changing the code, new song is Star Wars theme song.

✔ 

 

 

LCD

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

5 Volts

✔ 

 

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

There was a problem with the power supply I used, then I started using Arduino’s 5 V output and the problem was solved.

✔ 

 

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

lcd.print("hello, world!") line needs to be changed to lcd.print("Deniz") to make my name flash.

✔ 

 

            POTENTIOMETER

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

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

int led = 9;           // the pin that the LED is attached to

int brightness = 0;    // how bright the LED is

 

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

   // select the pin for the LED

 

 

 

// the setup routine runs once when you press reset:

void setup() {

  // declare pin 9 to be an output:

  pinMode(led, OUTPUT);

}

 

// the loop routine runs over and over again forever:

void loop() {

  // set the brightness of pin 9:

  analogWrite(led, brightness);

 

  sensorValue = analogRead(sensorPin);

 

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

  brightness = sensorValue

  ;

 

  // reverse the direction of the fading at the ends of the fade:

  if (brightness == 0 || brightness == 7000) {

    sensorValue = -sensorValue;

  }

  // wait for 30 milliseconds to see the dimming effect

 delay(30);

}

✔ 

 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.

 

 

            FLEX SENSOR

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

When it is flat resistance is near to 10kohms, when it is bent, it changes between 6kohms to 20 kohms depending on which side you bent to.

✔ 

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

Va = I*27 kohm (the circuit between arduino analog pin and ground)

Since the circuit is same between the arduino’s 3.3 V output and the ground, the current would be same.

We can say that the total resistance is between 27+6 = 33 kohm and 27+20 = 47 kohm,

3.3V = I*33kohm      or,

3.3V = I*47kohm. If we write I to the first equation,

Va is between : 3.3*27/47 and 3.3*27/33 Volts. Which means hhe voltages we expect fort he arduino analog pin are between 1.9 and 2.7 Volts

✔ 

 

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

Range is smaller than the potentiometer because in this circuit, after a certain value, overflowing occurs.

 

 

/*

 

 

  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

 * LCD VSS pin to ground

 * LCD VCC pin to 5V

 * 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/LiquidCrystal

 */

 

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

int sensorPin;

 

void setup() {

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

  lcd.begin(16, 2);

  int sensorValue=0;

  int sensorPin=A0;

 

}

 

void loop() {

  sensorValue = analogRead(sensorPin);

  lcd.setCursor(0,0);

  lcd.print(sensorValue);

  // set the cursor to column 0, line 1

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

  lcd.setCursor(0, 1);

  // print the number of seconds since reset:

  lcd.print(millis() / 1000);

}

 

FORCE SENSITIVE RESISTOR

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

60 to 0.8 kohms

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 is exponentially decreasing, the rate of the decrease is higher first, then the change rate slows down.

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

 

/*

 

 

  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

 * LCD VSS pin to ground

 * LCD VCC pin to 5V

 * 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/LiquidCrystal

 */

 

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

int sensorPin1;

int sensorValue2;

int sensorPin2;

 

void setup() {

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

  lcd.begin(16, 2);

  int sensorValue1=0;

  int sensorPin1=A0;

  int sensorPin2=A1;

  int sensorValue2=0;

}

 

void loop() {

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);

 

  lcd.setCursor(0,0);

  lcd.print(sensorValue1);

  // set the cursor to column 0, line 1

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

  lcd.setCursor(0, 1);

  // print the number of seconds since reset:

  lcd.print(sensorValue2);

}