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

Kingston's Lab Report 3

Page history last edited by Kingston Tam 7 years, 3 months ago

Part A

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

 

I would halve the noteDuration by changing the line from:

    int noteDuration = 1000/noteDurations[thisNote]; 

to: 

    int noteDuration = 1000/noteDurations[thisNote]/2;

 

b. What song is playing? ;-)

 

Star Wars theme tune :)

 

Part B

 

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

 

The input voltage is between 4.7V and 5.5V - typically 5V.

 

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

 

The wiring worked perfectly although I had to adjust potentiometer to get the proper contrast.

 

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

 

I needed to change line 50 from:

  lcd.print("Hello World!");

to

  lcd.print("Kingston"); 

 

Part C.1

a. Post a copy of your new code in your lab writeup.

 

-- Code Start --

 

/*

  Analog Input

 Demonstrates analog input by reading an analog sensor on analog pin 0 and

 turning on and off a light emitting diode(LED)  connected to digital pin 13. 

 The amount of time the LED will be on and off depends on

 the value obtained by analogRead(). 

 

 The circuit:

 * Potentiometer attached to analog input 0

 * center pin of the potentiometer to the analog pin

 * one side pin (either one) to ground

 * the other side pin to +5V

 * LED anode (long leg) attached to digital output 13

 * LED cathode (short leg) attached to ground

 

 * Note: because most Arduinos have a built-in LED attached 

 to pin 13 on the board, the LED is optional.

 

 

 Created by David Cuartielles

 modified 30 Aug 2011

 By Tom Igoe

 

 This example code is in the public domain.

 

 http://arduino.cc/en/Tutorial/AnalogInput

 

 */

 

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

 

  // convert it to analog write

  int outputValue = sensorValue * (255.0 / 1023.0);

 

  // adjust LED pin appropriately

  analogWrite(ledPin, outputValue);

}

 

-- Code End --

 

Part C.2

 

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

 

Resistance when flat: 25.7 kOhms

Resistance when bent: 80 kOhms 

 

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

 

Based of the answers from a.:

 

Voltage on analog pin when flat: voltage = 24000 / (24000 + 25700) * 3.3 = 1.59V

Voltage on analog pin when bent: voltage = 24000 / (24000 + 80000) * 3.3 = 0.76V

 

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

 

The range of LED brightness will be less because it will only range from 0.76V to 1.59V as opposed to 0V to 3.3V for the potentiometer.

 

d. Include a copy of your Lowly Multimeter code in your lab write-up.

 

(will work and give you voltmeter reading on LED display)

 

-- Code Start --

 

/*

  Analog Input

 Demonstrates analog input by reading an analog sensor on analog pin 0 and

 turning on and off a light emitting diode(LED)  connected to digital pin 13. 

 The amount of time the LED will be on and off depends on

 the value obtained by analogRead(). 

 

 The circuit:

 * Potentiometer attached to analog input 0

 * center pin of the potentiometer to the analog pin

 * one side pin (either one) to ground

 * the other side pin to +5V

 * LED anode (long leg) attached to digital output 13

 * LED cathode (short leg) attached to ground

 

 * Note: because most Arduinos have a built-in LED attached 

 to pin 13 on the board, the LED is optional.

 

 

 Created by David Cuartielles

 modified 30 Aug 2011

 By Tom Igoe

 

 This example code is in the public domain.

 

 http://arduino.cc/en/Tutorial/AnalogInput

 

 */

 

 

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

 

double minVoltage = 0.76;

double maxVoltage = 1.59;

double inputMax = 5.0;

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);  

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

  lcd.begin(16, 2);

 

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

 

  // print out sensor read

  lcd.clear();

  lcd.setCursor(0, 0);

  lcd.print(sensorValue);

 

  int outputValue = sensorValue;

 

  // adjust for flex sensor

  outputValue = (outputValue - (minVoltage / inputMax * 1023.0));

  outputValue = outputValue / ((maxVoltage - minVoltage) / inputMax);

 

  // convert it to analog write

  outputValue *= (255.0 / 1023.0);

 

  // just some sanity checks

  if (outputValue < 0) outputValue = 0;

  if (outputValue > 255) outputValue = 255;

 

  // adjust LED pin appropriately

  analogWrite(ledPin, outputValue);

 

}

 

-- Code End --

 

Part C.3

 

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

 

At no pressure, resistance seemed to be off the scale (i.e. very very high resistance).

At full pressure, resistance was at minimum around 0.28 kOhms.

 

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

 

It looks like an exponential relation but it is very hard to work it out because pressure with fingers is not an easy variable to estimate.

 

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

 

-- Code Start --

 

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

 

int player1Time = 0;

 

void setup() {

  // declare the ledPin as an OUTPUT:

  pinMode(ledPin, OUTPUT);  

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

  lcd.begin(16, 2);

 

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

 

  // print out sensor read

  lcd.clear();

  lcd.setCursor(0, 0);

  double sensorValueNormalized = sensorValue / 1023.0 / (3.3 / 5.0);

  if (sensorValueNormalized > 0.5) {

    if (player1Time >= 0) {

      player1Time++;

    } else {

      player1Time = 0;

    }

    if (player1Time > 3) {

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

      digitalWrite(ledPin, HIGH);

    } else {

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

      lcd.print(player1Time);

      digitalWrite(ledPin, LOW);

    }

  } else {

    if (player1Time <= 0) {

      player1Time--;

    } else {

      player1Time = 0;

    }

    if (player1Time < -3) {

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

      digitalWrite(ledPin, HIGH);

    } else {

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

      lcd.print(-player1Time);

      digitalWrite(ledPin, LOW);

    }

  }

  delay(1000);

}

 

-- Code End --

 

Part D

 

a. Make a short video showing how your timer works, and what happens when time is up!

 

Comments (0)

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