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

  • Want to organize your cloud files? Sign up for a free webinar to see how Dokkio (a new product from PBworks) can help you find, organize, and collaborate on your Drive, Gmail, Dropbox, and Slack files: Weds, May 27 at 2PM Eastern / 11AM Pacific
View
 

Lab_3_Kevin_Hsu

Page history last edited by Kevin Hsu 7 years, 1 month ago

PART A

a. The note durations are stored in the integer array, noteDurations. To make a song play twice as fast, I would multiply the elements by 2.

b. Star Wars!

 

PART B

a. The LCD display calls for 5 volts, which can be supplied by the Arduino.

b. Luckily, my wiring worked the first time. However, I did feel that the display was too dark, so I adjusted the potentiometer for more contrast, and also connected pins 15 and 16 to 3 volts and ground respectively for the backlight.

c. I changed the lcd.print line to lcd.print("kevin hsu!"); to flash my name.

 

PART C

1. Potentiometer controlling LED

int sensorPin = A0;   

int ledPin = 13;    

int val = 0; 

void setup() {

  pinMode(ledPin, OUTPUT);  

}

void loop() {

  int val = analogRead(sensorPin);

  val = map(val, 0, 1023, 0, 255);

  analogWrite(ledPin, val);             

}

 

2. Flex sensor

a. I measured 22.4 kOhm when it is unbent, and 30.1 kOhm when bent.

b. vout = (r2/(r1+r2)) * vin

vout = (22k/22k+24k) * 3.3 = 1.58 (Unbent)

vout = (30/30+24)*3.3 = 1.83 (Bent)

c. Because the sensor is more imprecise and varying, the LED does not completely fade to unlit.

d. 

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

void setup() {

  pinMode(ledPin, OUTPUT);  

  lcd.begin(16, 2);

}

void loop() {

  int val = analogRead(sensorPin);

  val = map(val, 200, 500, 0, 255);

  analogWrite(ledPin, val);    

  lcd.print(val);  

  lcd.clear();

}

 

3. Force Sensitive Resistor

a. When there is light pressure, I measure 0.2 Mohm, and when is a lot of pressure, I measure 0.3 kOhm.

b. The resistance vs. force graph from the data sheet looks linear after about 20 g's of force. It increases to infinite resistance (a short circuit) before then.

c. 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

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

int sensorPin2 = A1;

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

int val2 = 0;

void setup() {

  lcd.begin(16, 2);

}

void loop() {

  int val1 = analogRead(sensorPin1);

  int val2 = analogRead(sensorPin2);

  if (val1 > val2) {

    lcd.print("Player 1 is winning!");

  }

  else if  (val2 > val1) {

    lcd.print("Player 2 is winning!");

  }

  else {

    lcd.print("Press to play thumb wars.");  

  }  

    lcd.clear();

}

 

PART D - TIMER

Link to video: https://www.youtube.com/watch?v=y6U4JYWPK-E

Credits to github.com/electricmango for the song.

 

 

 

Comments (0)

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