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

View
 

Yuhui (Alexander) Li Lab 4

Page history last edited by Yuhui Li 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:

  Serial.print(analogRead(xpin));

  // print a tab between values:

  Serial.print("\t");

  Serial.print(analogRead(ypin));

  // print a tab between values:

  Serial.print("\t");

  Serial.print(analogRead(zpin));

  Serial.println();

  // delay before next reading:

  delay(100);

 

  int x = analogRead(xpin);

  int y = analogRead(ypin);

  int z = analogRead(zpin);

 

  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

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

 

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

 

http://youtu.be/0PYBx-30d64

Comments (2)

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

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