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

View

# Yuhui (Alexander) Li Lab 4

last edited by 5 years, 10 months ago

Part A

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

0-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?

The ADC has 10-bit. 0-1023 has 1024 numbers, which means that the ADC is 10-bit (2^10=1024)

Part B

1a. 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 actual data matches the datasheet. The voltage increases as I move my hand closer and closer but after a certain point, it starts to decrease rapidly.

b.

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

Serial.begin(9600);

lcd.begin(16,2);

}

void loop()

{

// print the sensor values:

// print a tab between values:

Serial.print("\t");

// print a tab between values:

Serial.print("\t");

Serial.println();

delay(100);

if (x>328&&x<335&&y>342&&y<350&&z>430&&z<438) {

lcd.clear();

lcd.print("No Movement");

}

else {

lcd.clear();

lcd.setCursor(0,0);

if (x>=335) {

lcd.print("Forward");

}

else if (x<=328) {

lcd.print("Backward");

}

lcd.setCursor(0,1);

if (y>=350) {

lcd.write("Left");

}

else if(y<=342) {

lcd.write("Right");

}

lcd.setCursor(6,1);

if(z>=438) {

lcd.write("Down");

}

else if(z<=430) {

lcd.write("Up");

}

}

}

Part C:

1 Part D:

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

1024

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

Analog data ranges from 0-1023. To convert it to be byte sized (255) just divide it by 4 #### xinyi xie said

at 10:48 pm on Aug 2, 2014

Did you record the video of lab 4? #### Yuhui Li said

at 11:03 pm on Aug 2, 2014

Sry i only posted to the hall of fame. It's here now