ZihengChen_Lab3


Part A Making Sounds

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

The code can be changed in the following way by replacing 1000 with 500.

    int noteDuration = 1000 500 /noteDurations[thisNote];

b. What song is playing? ;-)

star war theme song.

Part B Write to your LCD

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

VDD used in the experiment is 5V. According to the data sheet of the LCD, standard supply voltage VDD = 4.5V.

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

The process of wiring up the wires needs to be done very carefully. I made a mistake when connecting pin4 of LCD to pin12 of Arduino by insert the wire from pin12 Arduino into pin3 LCD. The screen did not display "Hello World" when program was uploaded. Instead, the second line was lighted as a whole and first line had nothing. I infer I was near there but there was some wiring mistake. Then I connect pin12 Arduino to pin4 LCD, problem solved. 

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

Change the line lcd.print("hello world");

With those code, I make LCD blink my name.

     void loop() { 

       lcd.setCursor(0, 0);

       lcd.print("Ziheng Chen");

       delay(500);

       lcd.noDisplay();

       delay(500);

       lcd.display();  

     }

Part C Fancy input

 

1a. 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 = 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 with sensorValue

  analogWrite(ledPin,sensorValue/4);              

}

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

Normal: 11 kOhms

Forward: 9 kOhms

Backward: 50 kOhms

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

Vpin = Vcc * (R0/(R0+Rflex)) = 33 V * (24 kOhm/(24 kOhm + Rflex))  

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

According to the above expression, when 9 kOmh < Rflex < 50 kOhm, Vpin varies between 10.7V ~ 24V.

The changes with flux sensor is smaller then potentiometer. The minimum input value of potentiometer is 0V theoretically while in this circuit of flex sensor, the minimum is 10.7V

2d. 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 = A0;    

int ledPin = 13; 

int sensorValue = 0;

 

void setup() {

 pinMode(ledPin, OUTPUT);  

 lcd.begin(16, 2); 

}

 

void loop() {

 sensorValue = analogRead(sensorPin);    

 analogWrite(ledPin,sensorValue/10);

 lcd.noDisplay();

 delay(500);

 lcd.display();

 delay(500);

 lcd.setCursor(0,0);

 lcd.print(sensorValue);

  

}

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

?  --> -0.5

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

look like R = const / F

3c. 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 sensorPin = A0;    

int ledPin = 13; 

int sensorValue = 0;

 

void setup() {

 pinMode(ledPin, OUTPUT);  

 lcd.begin(16, 2); 

}

 

void loop() {

 sensorValue = analogRead(sensorPin);    

 analogWrite(ledPin,sensorValue/10);

 lcd.noDisplay();

 delay(500);

 lcd.display();

 delay(500);

 lcd.setCursor(0,0);

 lcd.print(sensorValue); 

}