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

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Alex - Lab3: Digital Timer

Page history last edited by Alex Sartin 7 years, 1 month ago

Part A. Making Sounds

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

I would change the array noteDurations[] to half of their values. Those number correspond to the time of each note played.

 

b. What song is playing? ;-)

The Star Wars Theme song

 

Part B. Writing to the LCD

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

5V or 3.3V.    -- I used 5V from the Arduino board.

 

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

I fortunately made no mistakes. I just double checked all the wiring before turning it up.

 

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

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

 

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

int brightness = 0;

 

void setup() {

  pinMode(ledPin, OUTPUT);   // declare the ledPin as an OUTPUT:

} 

void loop() {

  sensorValue = analogRead(sensorPin);    

  brightness = map(sensorValue, 0, 668, 0, 255); 

  analogWrite(ledPin, brightness);

  delay(500);                          

}

 

2. Flex Sensor

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

Sensor flat: 10 kOhms

Sensor bent: 11.9 kOhms

 

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

Vanalog=(Rsensor/Rsensor+R)*Vin

Vin=3.3V and R=24Kohms

 

1) When the sensor is flat: Rsensor=9.5 kOhms

Vanalog=(24K/9.5K+24K)*3.3   -->  Vanalog=02.36V

 

2)When the sensor is bent: Rsensor=11.9 kOhms

Vanalog=(24K/11.9K+24K)*3.3   -->  Vanalog=2.2V

 

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

Since I used the function MAP() to make the LED output voltage from 0V to 5V both the potentiometer and the Flex sensor could turn off the LED and make it full brightness.

 

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

int brightness = 0;

 

void setup() {

  pinMode(ledPin, OUTPUT);   // declare the ledPin as an OUTPUT:

  lcd.begin(16, 2);

  lcd.display();

  lcd.print("Res= ");

  lcd.setCursor(7,0);  

  lcd.print("ohms");

} 

void loop() {

  sensorValue = analogRead(sensorPin); 

  lcd.setCursor(4,0);  

  lcd.print(sensorValue);

  brightness = map(sensorValue, 280, 312, 0, 255); 

  brightness = constrain(brightness, 0, 255);

  analogWrite(ledPin, brightness);

  delay(300);                    

}

 

3. Force Sensitive Resistor

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

From 700ohms to 100Kohms

 

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

Resistance drops linearly when force is applied.

 

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

int sensorPin1 = A0;    // Reads the force sensor 1 on pin A0

int sensorPin2 = A1;   //  Reads the force sensor 2 on pin A1

int sensorValue1 = 0; 

int sensorValue2 = 0;  

 

void setup() {

  lcd.begin(16, 2);

  lcd.display();    //start and turn on the display

}

 

void loop() {

  sensorValue1 = analogRead(sensorPin1);    //read the sensors

  sensorValue2 = analogRead(sensorPin2);  

  if(sensorValue1 > sensorValue2){

      lcd.setCursor(0,0);  

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

      }

  else if (sensorValue1==sensorValue2 || sensorValue1==sensorValue2*1.01 || sensorValue1==sensorValue2*0.99){

      lcd.setCursor(0,0);  

      lcd.print("It is a tie");

      }

  //If none of the above:

  else{ 

      lcd.setCursor(0,0);  

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

      }

  delay(300);                      

}

 

Part D. Timer

http://youtu.be/pXxM70sJh7M

 

 

Comments (1)

Vivien Tsao said

at 12:17 am on Jul 29, 2013

Good job! 10/10

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