Song Mingxun Lab 3


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

Change the int noteDuration= 1000 to int noteDuration = 500 to make the song play twice as fast.


b. What song is playing? ;-) 

It is playing the Star Wars Song.

c

 

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

The typical voltage level is about 5 volts.

✔ 

 

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

I messed up wiring the potentiometer. I fixed it by correctly orientating it to the wires. I forgot to connect the third pin to ground.

✔ 

 

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

Change lcd.print("hello, world!"); to lcd.print("Mingxun Song!");

✔ 

 

 

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 = 0;  // variable to store the value coming from the sensor

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);

  pinMode(sensorPin, INPUT);

  Serial.begin(9600);

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

  // turn the ledPin on

  Serial.println(sensorValue);

 analogWrite(ledPin, sensorValue/4);

 }

✔ great

 

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

When it is flat, the resistance is 7.88 k ohm. When it is bent, the resistance is 20 k ohm.

✔ 

 

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

According to the equation V out= R2/(R2+R1) x V in R2 is 27 K ohm. R1 is 7.88 K ohm to 20 K ohm. V in is 3.3 V. For a straight flex sensor, the voltage is about 2.55 volts and 1.9 volts

✔ 

 

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

At first the range of brightness of the LED was quite small because I didn't adjust the sensor value, but then I changed the sensor value to get 0, the range was better because I can actually see the LED changing. The range is less dramatic as the potentiometer.

✔ 

The voltage divider, comprising a fixed resistor and flex sensor, will not have as much range for Vout as the potentiometer, because of its fixed resistor. That is, the range will be lower, because it cannot reach 0V

 

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 = 0;  // 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.

 

   pinMode(ledPin, OUTPUT);

  pinMode(sensorPin, INPUT);

  Serial.begin(9600);

}

 

void loop() {

lcd.setCursor(0, 1);

   sensorValue = analogRead(sensorPin);

   lcd.print((sensorValue-300)/5);

    Serial.println(sensorValue);

 analogWrite(ledPin, (sensorValue-300)/5);

 

}

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

I had from 0 ohm to 6 kohm resistance value from my force sensor.

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

The relationship of the resistance as a function of force applied is a linear relationship because it observation, the resistance seemed to increase incrementally as I increase the force.

 


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

int fsrPin = A0; 

int LEDpin = 13;     

int fsrValue;      

int LEDbrightness;

 

void setup(void) {

  Serial.begin(9600);  

  pinMode(LEDpin, OUTPUT);

}

 

void loop(void) {

  fsrValue = analogRead(fsrPin);

 

  Serial.println(fsrValue);

  LEDbrightness = map(fsrValue, 0, 1023, 0, 255);

  analogWrite(LEDpin, LEDbrightness);

 

  delay(100);

}

a. Make a short video showing how your timer works, and what happens when time is up! I made a video of my timer which says wake up or else at first and counts from 1 to 10 and once 10 is reached, it will say self destruct. Furthremore, it is not a hardware issue because there is no clear function placed in your code. The LCD tries to change 100 to 91 by changing it first to 900 to 910. It doesn't need to change the last 0 because there is no value for the third number.