• 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

# Arslan_Mert_LAB4

last edited by 4 years, 12 months ago

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

The analog values read 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?

The analog to digital converter on the Atmega32U4 has 10 bits of resolution according to the Atmel Corporation website.

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?

The voltage increases as the distance increases. When the distance is low, the resistance is high. So the voltage is directly proportional to distance. There is only one exception to this, which occurs when the distance is extremely low, then the voltage spikes up. For some reason this seems to be the exact opposite of the graph on the data sheet.

// include the library code:

#include <LiquidCrystal.h>

int sensorPin1 = A0;

int sensorPin2 = A1;

int sensorPin3 = A2;// select the input pin for the potentiometer

int ledPin = 9;      // select the pin for the LED

int sensorValue1 = 0;

int sensorValue2 = 0;

int sensorValue3 = 0;// variable to store the value coming from the sensor

// initialize the library with the numbers of the interface pins

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

void setup() {

pinMode(ledPin, OUTPUT);

pinMode(sensorPin1, INPUT);

pinMode(sensorPin2, INPUT);

pinMode(sensorPin3, INPUT);

lcd.begin(16, 2);

}

void loop() {

// read the value from the sensor:

lcd.print("X:");

lcd.print(sensorValue3);

lcd.print("Y:");

lcd.print(sensorValue2);

lcd.print("Z:");

lcd.print(sensorValue1);

// Turn off the display:

lcd.noDisplay();

delay(500);

// Turn on the display:

lcd.display();

delay(500);

lcd.clear();

No state diagram -0.5

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

As stated in the LAB sheet itself, the Atmega32U4 can store 1k bytes.

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

The analog data will be between 0 and 1023, while a byte can store only up to 255. This means that dividing the analog data by 4 will roughly scale it down to fit in a byte.

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

My computer is currently not powering the arduino, but the code for my Data Logger is below. It basically uses a potentiometer to set the state, and then another as the sensor being measured. Each time a button is pressed, depending on the state it either stores or retrieves the data, one by one and in order. The video will be posted as soon as possible.

#include <EEPROM.h>

int state = 0;

int button = 0;

void setup() {

// put your setup code here, to run once:

pinMode(A0, INPUT);

pinMode(A1, INPUT);

pinMode(2, INPUT);

}

void loop() {

while (state < 512) {

if (button == HIGH) {

int value = analogRead (A0) / 4;

}

delay(500);

}

}

while (state >= 512) {

if (button == HIGH) {

Serial.println(value);

}

delay(500);

}

}

} 