harrymj Lab 4


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?

10 bits, all used here because of correction to power pot from 5V as opposed to 3.3V.

 

Part B:

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?

The values increase from roughly 60 a long distance away to roughly 650 at about two inches away, then proceed to decrease from there. This matches what I would expect from the datasheet, which shows a max at roughly 7cm.

 


a. Include your accelerometer read-out code in your write-up.

 

const int xpin = A1;

const int ypin = A2;

const int zpin = A3;

 

int xVal, yVal, zVal;

 

void setup() {

  // initialize the serial communication:

  Serial.begin(9600);

}

 

void loop() {

 

  xVal = analogRead(xpin);

  yVal = analogRead(ypin);

  zVal = analogRead(zpin);

 

//print the x, y, and z values. 

  Serial.print("x: ");

  Serial.print(xVal);

  Serial.print("\t");

 

  Serial.print("y: ");

  Serial.print(yVal);

  Serial.print("\t");

 

  Serial.print("z: ");

  Serial.print(zVal);

  Serial.println("");

 

 

  // wait a bit for the analog-to-digital converter 

  // to stabilize after the last reading:

  delay(20);

}


 

Part C:

 

a. Upload a picture of your rotary encoder in action!

 

I used an IDC ribbon cable cut off to connect the encoder to the breadboard. One end of the IDC cable was soldered to the three leads of the encoder, and the other side was soldered to a male breakaway header that plugs into the breadboard. The wires are covered with heat shrink tubing on both sides.

 

 

 

Part D:

1. 

My data logger is a crude recreation of a "black box" recording system. When the accelerometer detects a sudden movement in the X direction, it logs the accelerometer for the next 1.024 seconds at 1KSPS. During this time, an LED is lit to indicate recording. When not in record mode, the data can be played back to a computer for "graphing and analysis" by pressing a button.

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

 

2.

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

1024

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

Remove the two least significant bits by dividing by 4. This maps 10 bit ADC to byte size.

 

a. Use the lab camera or your own camera/cell phone to record and upload a short demo video of your logger in action.