Cole Hoffer - Lab 4


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?

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?

10 bits and using 10

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?

As my distance from the sensor decreases, the voltage increases and vice versa. However, when I am moving towards the sensor, the voltage will continue to increase until I am about 3 inches away, in which then I was move closer the voltage will actually decrease. The graph on the datasheet supports my findings, including the close proximity change. 

2. Accelerometer

 

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

#include <LiquidCrystal.h>

 

 

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

int sensorPin_x = A3;

int sensorPin_y = A2; 

int sensorPin_z = A1; 

int sensorValue_x = 0;

int sensorValue_y = 0;

int sensorValue_z = 0;

 

void setup() {

   lcd.begin(16, 2);

   Serial.begin(9600);

}

 

void loop() {

   sensorValue_x = analogRead(sensorPin_x);

   sensorValue_y = analogRead(sensorPin_y);   

   sensorValue_z = analogRead(sensorPin_z);    

   lcd.setCursor(0,0);

   lcd.print(sensorValue_x);

   lcd.setCursor(7,0);

   lcd.print(sensorValue_y);

   lcd.setCursor(3,1);

   lcd.print(sensorValue_z);

 

   Serial.println("X");

   Serial.println(analogRead(A3));

   Serial.println("Y");

   Serial.println(analogRead(A2));

   Serial.println("Z");

   Serial.println(analogRead(A1));

 

   delay(1000);

   Serial.println();

   Serial.println();

   Serial.println();

}

 

Part C. Count/Time-Based Sensors

1. Rotary Encoder

 

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

2. Reading and writing values to the EEPROM

 

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

1000 (1KB)

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

It must be a value between 0 and 256 so you would divide your analog value by 4 in order for its maximum to be 256 (1023/4 = 256)

3. Create your data logger!