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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.


Lab 4: Data Logger!

Page history last edited by evclark@stanford.edu 8 years, 2 months ago

Part A.  Writing to the Serial Monitor 

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 bit ADC according to the datasheet. We are using all 10 bits because we get a range from 0 to 1023 in increments of 1, meaning 2^10 gradations, meaning 10 bits.



Part B. Voltage Varying Sensors 


1. IR Distance Sensor

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?

 Experimentally: 20 mV to 2.4 V. Difference = 2.4V.

 Datasheet: .4 V to 3.1 V. Difference = 2.7V


2. Accelerometer

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

#include <LiquidCrystal.h>


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


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


void setup()


  // initialize the serial communications:





void loop()


  int x = analogRead(xpin);

  int y = analogRead(ypin);

  int z = analogRead(zpin);



  lcd.print("x     y     z");


  lcd.setCursor(0, 1);



  lcd.setCursor(6, 1);



  lcd.setCursor(12, 1);






Part C. Count/Time-Based Sensors

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




Part D. Logging values to the EEPROM and reading them back


1. Design your logger

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

DDR State Diagram:

2. Reading and writing values to the EEPROM

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?

     -Round it down to 8 bit precision: 0-255.


3. Create your data logger!

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


b. Post a link to the Lab 4 Data Logger Hall of Fame.


DDR Code:





Comments (0)

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