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

  • Social distancing? Try a better way to work remotely on your online files. Dokkio, a new product from PBworks, can help your team find, organize, and collaborate on your Drive, Gmail, Dropbox, Box, and Slack files. Sign up for free.

View
 

Srivatsan, Akshay – Lab 3

Page history last edited by xyyue@... 4 years, 9 months ago

Part A: Making Sounds

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

Take every number in noteDurations and multiply it by two. Since the actual duration is 1000 divided by the number in the array, doubling the number will halve the duration.

 

b. What song is playing? ;-)

The Star Wars theme.

 

Part B: Writing to the LCD

 

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

5V

 

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

When I finished soldering the display, I wanted to test it by hooking it up to the power supply. Unfortunately, I connected power and ground in reverse, and the display didn't activate. I only realized my mistake later, when I was wiring up the rest of the display. I finished connecting it, and luckily the display still works.

 

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

The line that reads 'lcd.print("hello, world!");'. I need to change the string to "Akshay Srivatsan". 

 

Part C: Fancy Inputs

1. Potentiometer

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

  sensorValue = analogRead(sensorPin);

  analogWrite(ledPin, sensorValue/1024.0*255);

}

✔ great

 

2. Flex Sensor

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

Flat: 8.7 kOhm

Bent: 26.6 kOhm

 

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

Flat: 2.5 V

Bent: 1.7 V

 

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

It will no longer reach the "off" state (since there is a minimum resistance significantly greater than zero). The overall range will be smaller, since the flex sensor outputs a smaller range of voltages.

 

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

  lcd.begin(16, 2);

}

 

void loop() {

  sensorValue = analogRead(sensorPin);

  analogWrite(ledPin, (sensorValue-300)/220.0*255); //I measured a range from ~310 to ~510. Scaling 300-500 to 0-255 should give me the full range of brightnesses.

  lcd.clear();

  lcd.print(sensorValue);

}

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

26k Ohms to 0.8 kOhm (and infinite resistance when not pressed at all).

 

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

According to the Datasheet, there is an inverse relationship (R = 1/F).

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

 

/* Voltage Range of ~1.7 V to ~3.2 V */

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

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);

  lcd.begin(16, 2);

}

 

void loop() {

  lcd.clear();

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);

  if (sensorValue1 == sensorValue2) {

    lcd.write("Tie!");

  }

  else if (sensorValue1 > sensorValue2) {

    lcd.write("Player 1 wins!");

  }

  else if (sensorValue1 < sensorValue2) {

    lcd.write("Player 2 wins!");

  }

  delay(50);

}

Video:

 

Comments (1)

zahraa@... said

at 2:33 pm on Aug 10, 2015

good job

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