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


Lab4 (2)

Page history last edited by knottb@... 5 years, 11 months ago

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


The analog value range from 0 to 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?


Since 1024 = 2^10, the ADC has10 bits of prescision.


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?


When the IR sensor is pointed at the ceiling, the input reads a value in the range 25-29. When I put my hand directly in front of the IR sensor, the input reads 300-320. As I move my hand away, the value of the input increases until it reaches about 630, when my hand is about 2-3 inches away from the sensor. As I move my hand further away, the reading from the IR sensor decreases. This agrees quite well with the datasheet which says that there should be a peak about 6cm (which is between 2 and 3 inches) with a sharp slope as the object approaches the sensor, and a less sharp slope in the other direction.


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


The X-reading increases when the board is held so the G side faces up and the Z0 side faces down and decreases when the G side faces down and the Z0 side faces up. The Y-reading increases when the side of the accelerometer board with pins 1-5 is up and the side with pins 6-9 are down and decreases when pins 6-9 are up while pins 1-5 are down. The Z-reading increases when the board is connected to a breadboard that is right-side-up and decreases when the breadboard is upside-down.


void loop()


// Print the direction that the board is facing.

if (analogRead(xpin) < 300){ Serial.println("X decreased");}

if (analogRead(xpin) > 400){ Serial.println("X increased");}

if (analogRead(ypin) < 300){ Serial.println("Y decreased");}

if (analogRead(ypin) > 400){ Serial.println("Y increased");}

if (analogRead(zpin) < 300){ Serial.println("Z decreased");}

if (analogRead(zpin) > 400){ Serial.println("Z increased");}


// delay before next reading:




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


We can store 1024 bytes of data on the Atmega32U4 since it is 1KB.


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


This can be done by dividing our 10-bit data by 2 bits (dividing by four).


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




#include <EEPROM.h>

boolean buttonstate = false;

int addr = 0;


void setup() {

// initialize the serial communication:




void loop() {


boolean buttonpressed = (analogRead(A0) < 300);

if (buttonpressed && !buttonstate) {

buttonstate = true;



} else if (!buttonpressed && buttonstate) {

buttonstate = false;



if (analogRead(A3) == 0) {

for(int i = 0; i < addr; i++) {

int value = EEPROM.read(i);



while(analogRead(A3) == 0) {



// Reset if addr overflows

if (addr == 1024)

addr = 0;




Comments (0)

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