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

View
 

Arslan_Mert_LAB4

Page history last edited by zahraa@... 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. 

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

 

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

  sensorValue1 = analogRead(sensorPin1);

  sensorValue2 = analogRead(sensorPin2);

  sensorValue3 = analogRead(sensorPin3);

  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;

int address = 0;

int address1 = 0;

int adressGet = 0;

 

void setup() {

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

  pinMode(A0, INPUT);

  pinMode(A1, INPUT);

  pinMode(2, INPUT);

}

 

void loop() {

  state = analogRead(A1);

  while (state < 512) {

    button = digitalRead (2);

    if (button == HIGH) {

      int value = analogRead (A0) / 4;

      EEPROM.write (address, value);

      address = address + 1;

      }

      delay(500);

      if(address == EEPROM.length()) {

        address = 0;

      }

    }

    while (state >= 512) {

      button = digitalRead (2);

    if (button == HIGH) {

      int value = EEPROM.read (address1);

      Serial.println(value);

      address1 = address1 + 1;

        }

      delay(500);

      if(address1 == EEPROM.length()) {

        address1 = 0;

      }

  }

 

}

 

Comments (1)

xyyue@... said

at 2:13 pm on Aug 11, 2015

Well done.

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