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

Shim, Arthur Lab 3

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

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

Change the pause between the notes to half the time.

 

int pauseBetweenNotes = noteDuration * 1.30;          <-- change the 1.30 to 0.65 to make the song play twice as fast.

 

 

Correct but that might not address the question entirely, because the notes themselves wouldn’t be shorter, only the durations between them. 

 

b. What song is playing? ;-)

Star Wars Theme

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

2.7V to 5.5V

✔ great response

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

I had the wire going from the wrong leads in the potentiometer. I had to go through and check every connection until I found the problem with the potentiometer, then move the wires so that it worked.

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

You need to change this line:

lcd.print("hello, world!"); 

so that it says

lcd.print("Arthur Shim");

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

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

  // turn the ledPin on

  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.

 

 

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

When the sensor is flat, the resistance is about 9 KOhms. When it's bent the resistance is about 20 KOhms.

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

Vout = Vin * R2 / (R1 + R2)

Vout = 3.3 V * 27kOhm / (9 kOhm + 27kOhm) = 2.475 V

Vout = 3.3 V * 27kOhm / (20 kOhm + 27 kOhm) = 1.9 V

✔ great response

We should expect 1.9 V to 2.475 V from the pin.

 

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

The flex sensor never allows the LED to go completely dim. The potentiometer allows us to completely dim the LED meaning it has a greater range.

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

 

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);

 

  // Print a message to the LCD.

  lcd.print(sensorValue);

}

 

void loop() {

  lcd.print("");

   // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

  // turn the ledPin on

  analogWrite(ledPin, sensorValue);

  lcd.clear();

  // Print a message to the LCD.

  lcd.print(sensorValue);

 

  // Turn off the display:

  lcd.noDisplay();

  delay(500);

  // Turn on the display:

  lcd.display();

  delay(500);

}

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

About 0-0.6 mOhms.

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

The resistance is inversely related to the force applied. 

c. Include a copy of your FSR thumb wrestling 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 sensorPin1 = A0;    // select the input pin for the potentiometer

int sensorPin2 = A1;

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

int sensorValue2 = 0;

 

void setup() {

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

  lcd.begin(16, 2);

 

  lcd.print("");

}

 

void loop() {

   // read the value from the sensor:

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);

 

   lcd.clear();

 

  if (sensorValue1 < sensorValue2)

    lcd.print("sensor1");

  else if (sensorValue2 < sensorValue1)

    lcd.print("sensor2");

  else

  lcd.print("tie");

 

  lcd.display();

  delay(500);

}

 

 

 

 

 

 

Comments (1)

xyyue@... said

at 2:48 pm on Jul 29, 2015

Well done!

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