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

Zajac_Lab4

Page history last edited by Benjamin Tee 9 years, 2 months ago

Richard Zajac

EE47: Press Play

Lab 4 – The Report

Class of Thu, July 21

 

 

 

1.

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

 

/*

 

Created by David Cuartielles

Modified 20 Jul 2011

By Richard Zajac

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 = 9; // 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

sensorValue /= 10;

// write value of LED sensor

analogWrite(ledPin, sensorValue);

}

2.

 

a. Based on the readings from the serial monitor, what is the range of the analog values being read?

 

Based on the readings, the range is 0-1023 

 

b. How many bits of resolution does the analog to digital converter (ADC) on the Atmega32U4 have [hint: where might you look to find this sort of thing]? How many are you using with the range of values you're seeing?

 

The Atmega’s ADC has 10 bits of resolution. 

 

Given the 0-1023 range, all 10 bits are within the usable values. 

 

3.

 

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

I see a resistance of around 13K when flat. 

I see a resistance of around 33K when bent. 

 

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

 

For flex sensor (flat), {22K/22K+13K} x 5 = 3.14V

 

For flex sensor (bent), 2.0V

 

Expected voltages should then be in the 2.0-3.14V range.

 

 

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

 

With the potentiometer, there is less change.

 

d.

/*

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 20 Jul 2011

By Richard Zajac

This example code is in the public domain.

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

*/

#include <LiquidCrystal.h>

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

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

int ledPin = 9; // select the pin for the LED

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

int modSensorValue = 0;

void setup() {

lcd.begin(16, 2);

lcd.print("Multimeter ReadOut");

// declare the ledPin as an OUTPUT:

pinMode(ledPin, OUTPUT);

}

void loop() {

// read the value from the sensor:

sensorValue = analogRead(sensorPin);

lcd.setCursor(0, 1);

lcd.print(sensorValue);

modSensorValue = map(sensorValue, 350, 750, 0, 255);

// write value of LED sensor

analogWrite(ledPin, modSensorValue);

}

 

4.

 

a.

 

Without applying force, the values had, to pay homage to the final space shuttle mission, skyrocketed. I was able to get the values down to around 300 Ohms using heavy pressure.

b.

I saw a logarithmic relationship where with more force; there is less resistance, as corroborated by the datasheet.

 

c.

 

#include <LiquidCrystal.h>

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

int sensorPin = A0;

int sensorPin2 = A1;

int sensorValue = 0;

int sensorValue2 = 0;

void setup() {

lcd.begin(16, 2);

lcd.print("FSR_Wrestling");

pinMode(ledPin, OUTPUT);

}

void loop() {

sensorValue = analogRead(sensorPin);

sensorValue2 = analogRead(sensorPin2);

lcd.setCursor(0, 1);

if(sensorValue2 > sensorValue) lcd.print("Wrestler2-WIN");

else lcd.print("Wrestler1-WIN");

}

Part B:

 

1.

 

a.

Closer proximity results in lower readings, and further proximity results in higher readings up until a certain point where the readout ‘cliffs’, and varies very little, then ‘sticks’. The variance ranges from approximately 300mV to just over 3 Volts.

2.

 

a.

/*

ADXL3xx

Reads an Analog Devices ADXL3xx accelerometer and communicates the

acceleration to the computer. The pins used are designed to be easily

compatible with the breakout boards from Sparkfun, available from:

http://www.sparkfun.com/commerce/categories.php?c=80

http://www.arduino.cc/en/Tutorial/ADXL3xx

The circuit:

analog 0: accelerometer self test

analog 1: z-axis

analog 2: y-axis

analog 3: x-axis

created 2 Jul 2008

by David A. Mellis

modified 4 Sep 2010

by Tom Igoe

This example code is in the public domain.

Modified by Richard Zajac

*/

 

#include <LiquidCrystal.h>

 

// initialize the library with the numbers of the interface pins

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

 

// these constants describe the pins. They won't change:

const int xpin = A3; // x-axis of the accelerometer

const int ypin = A2; // y-axis

const int zpin = A1; // z-axis (only on 3-axis models)

int xRead = 0;

int yRead = 0;

int zRead = 0;

 

void setup() {

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

lcd.begin(16,2);

}

void loop() {

lcd.clear();

xVal = analogRead(xpin);

yVal = analogRead(ypin);

zVal = analogRead(zpin);

lcd.setCursor(0,0);

lcd.print("X axis: ");

lcd.setCursor(2,0);

lcd.print(xRead);

lcd.setCursor(7,0);

lcd.print("Y axis: ");

lcd.setCursor(9,0);

lcd.print(yRead);

lcd.setCursor(0,1);

lcd.print("Z axis: ");

lcd.setCursor(2,1);

lcd.print(zRead);

delay(100);

}

D.

 

1.

 

a.

✔ Nicely drawn

2.

a.

The Atmega 32U4 has 1 Kb of EEPROM. Therefore, there are 1024 byte-sized data samples that can be stored on the 32U4 

 

b.

To make the data byte sized, divide 1024 by 4 to get to 256, and thus, byte sized data. 

 

Youtube link:

http://www.youtube.com/user/rickyzstl

 

✔ Very nice idea of a proximity detector using the IR sensor. Great narrative and nice use of visual feedback to represent the states (e.g., alarm). 

 

 

Comments (0)

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