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


harrymj Lab 4

Page history last edited by Harry Johnson 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?


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:




void loop() {


  xVal = analogRead(xpin);

  yVal = analogRead(ypin);

  zVal = analogRead(zpin);


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

  Serial.print("x: ");




  Serial.print("y: ");




  Serial.print("z: ");





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

  // to stabilize after the last reading:




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:


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.



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


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.



Comments (0)

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