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

  • Social distancing? Try a better way to work remotely on your online files. Dokkio, a new product from PBworks, can help your team find, organize, and collaborate on your Drive, Gmail, Dropbox, Box, and Slack files. Sign up for free.



Page history last edited by Vivien Tsao 6 years, 9 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?

From 0 to 1023 units.

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 of resolution. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. 10bits as well


Part B. Voltage Varying Sensors

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?


From 0 to 8cm, voltage inceases drastically from 0V to 3V

From 8cm onwards, voltage dreases more gradually.

It match up with what I expect from the datasheet.


2. Accelerometer

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






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:





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.




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


void setup()


// initialize the serial communications:




void loop()



lcd.setCursor(1, 1);


lcd.setCursor(5, 1);


lcd.setCursor(12, 1);















Part C. Count/Time-Based Sensors


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



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


When button 1 is high, my datalogger is basically recording down the sensor reading from the infra-red sensor during the logging which is determined by the distance of an object from the sensor, assuming that the object is only within a 8cm range. When button 2 is high, data from the EEPROM will be displayed on the serial monitor. Finally when button 3 is high, any data from EERPOM will be cleared and the datalooger is either recording not displaying data, therefore in its idle state.

  ? ok





















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




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


I can use the map function to map the analog data in the range of 0-1023 to 0-255. As the number in the range of 0-255 can be represented by 8 bits.

✓ :) 

Comments (1)

Vivien Tsao said

at 5:40 pm on Aug 10, 2013

Good job!

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