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

View

# Gregory Manker--Lab 4

last edited by 7 years, 4 months ago

PART A

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

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 ADC has 10 bits of resolution, and we're using log2(1024) = all 10 bits!

PART B

1.

a. Describe the voltage change over the sensing range of the sensor. A sketch of voltage vs. distance would work also. Does it match up with what you expect from the datasheet?

In my case, the output voltage started at 1.7 when I held my piece of paper right against the sensor. Values increased to about 3.12 very quickly, and then decreased very slowly to about .042 V. Thus, my data follows the pattern laid out in the graph on the SparkFun spec sheet, but my axes are slightly different because my Vo at x=0 is different.

int sensorPin = A0;

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

void setup() {

Serial.begin(9600);

}

void loop() {

Serial.print("Voltage: ");

Serial.println("");

delay(1000);

}

* input: raw data value from bend sensor

* The bend sensor scales values to a number between 0 and 1023.

* In order for these values to be interpreted as voltages, they

* must be scaled using a linear function.

*/

}

2.

#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

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

void setup()

{

// initialize the serial communications:

Serial.begin(9600);

// initialize the LCD

lcd.begin(16,2);

}

void loop()

{

lcd.clear();

// Print the X values

// Print the Y Values

Serial.print("\t");

// Print the Z Values

Serial.print("\t");

Serial.println();

delay(1000);

}

Part C.

1.

PART D

1.

a. Turn in a copy of your final state diagram.

Initial:

FINAL:

2.

a. How many byte-sized data samples can you store on the Atmega32U4?

1000 bytes EEPROM == 1000 byte-size data samples.

b. How would you get your analog data from the ADC to be byte-sized?

I would create a linear mapping function that takes values between 0 and 1023 and maps them from 0 to 256. Because I have to use discrete values (I can't send a value of 147.5... that's definitely not a byte), I would round each number depending on whether it's closer to the the value above or below it. This means I'll lose some resolution, but my output value will be 8 bits--as desired.

3.