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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Lab 4 - Report

Page history last edited by diego.nunes 6 years, 11 months ago

I HAVE FINISHED THIS AND LAB3 SINCE LAST WEEK, BUT I AM HAVING PROBLEMS ABOUT UPLOADING THINGS =[

I AM FIGURING OUT HOW TO UPLOADING THE IMAGES SO I CAN DELIVER THE REPORT, BUT I ALREADY HAVE ALL THE REPORT READY IN PDF, IM JUST TRYING TO PASS TO HERE.

PLEASE VIVIAN, DONT GRADE ME NOW, I WILL TRY TO FIX ALL THIS WEEKEND

 

(Im sorry for the caps, im just trying to get your attention xD. Thank you very much Vivian, I am really sorry to bother you, I know you must have a schedule to correct all the works from the classroom. I will bring all here until sunday, for sure!)

 

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?

               16 bits. I am using 10 bits.

 

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?

 

To do this experiment, I fixed the sensor in a vertical position with a clear field in front of it. Using the lowly multimeter, I made a couple of tests:

    •     With a clear field, the resistance is too low, almost 0;
    •    If I put my hand within that field as an object, the sensor detects it and its resistance increases whenever my hand gets closer to the sensor. However, there is a threshold     point where the resistance reaches its maximum, and if the object (in that case, my hand) cross that line, the resistance starts to drop until a certain value (not zero);
    •     With a paper as an object, it works the same way as if I would use my hand. 

   

 

2.      Accelerometer

 

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

 

#include <LiquidCrystal.h>

#include <stdio.h>

 

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

 

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

int Xvalue = 0;

int Yvalue = 0;

int Zvalue = 0;

 

void setup()

{

  // initialize the serial communications:

  Serial.begin(9600);

  lcd.begin(16, 2);

}

 

void loop()

{

  lcd.display();

 

  Xvalue = analogRead(xpin);

  Yvalue = analogRead(ypin);

  Zvalue = analogRead(zpin);

 

  lcd.print("X: ");

  lcd.print(Xvalue);

 

  lcd.print(" Y: ");

  lcd.print(Yvalue);

 

  lcd.setCursor(0,2);

  lcd.print("Z: ");

  lcd.print(Zvalue);

 

  delay(1000);

  lcd.clear();

 

  // print the sensor values:

  Serial.print(Xvalue);

  // print a tab between values:

  Serial.print("\t");

  Serial.print(Yvalue);

  // print a tab between values:

  Serial.print("\t");

  Serial.print(Zvalue);

  Serial.println();

  // delay before next reading:

  delay(100);

}

 

Part C. Count/Time-Based Sensors

 

1.      Rotary Encoder

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

               I could not upload the image.

 

 

Part D. Logging values to the EEPROM and reading them back

1.      Design your logger

  1.  

 

 

2.      Reading and writing values to the EEPROM 

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

You can store 1k byte-sized data samples.

 

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

Using the function analogRead().

 

3.      Create your data logger!

 

http://www.youtube.com/watch?v=512BjP0c68E

CODE: 

#include <LiquidCrystal.h>

#include <stdio.h>

#include "pitches.h"

#include <EEPROM.h>

 

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

 

int sensorPin = A0;

int sensor = 0;

const int button = 6;

const int button2 = 9;

int buttonState = 0;

int save = 0;

int menuState = 1;

int var = 0;

int var2 = 0;

int address = 0;

int address_aux = 0;

int aux = 0;

 

void setup() {

 

  lcd.begin(16, 2);

  pinMode(button, INPUT);

 

}

 

void loop() {

 

  lcd.display();

  buttonState = digitalRead(button);

  save = digitalRead(button2);

 

//============================================================================

//These (ifs) below represent the state machine that controls the menu of the timer

//============================================================================

         

  if(buttonState == 0)

     var = 1;

  if(var == 1 && buttonState == 1)

  {

    var = 0;

    menuState = menuState + 1;

    if(menuState == 3)

       menuState = 1;

  }

//============================================================================

//Menu 1: you can use your sensor to save many values into the EEPROM

//============================================================================

 

  if ( analogRead(sensorPin) > 250)

      sensor = 250;

  else

      sensor = analogRead(sensorPin);

 

  if(menuState == 1)            //Set the initial value of the timer with the sensor

  {

      lcd.print("Sensor: ");

      lcd.print( sensor );

      lcd.setCursor(14,0);

      lcd.print("#");

      lcd.print(menuState);

      lcd.setCursor(0,1);

      lcd.print("EEPROM: ");

      lcd.print( aux );

     

      if(save == 0)

      {

         var2 = 1;

         lcd.print(" Saved!");

      }

      if(var2 == 1 && save == 1)

      {

        EEPROM.write(address, sensor);

        aux = EEPROM.read(address);

        address = address + 1;

        var2 = 0;

      }

 

  }

 

//============================================================================

//Menu 2: It will show you the addresses in the EEPROM assigned to the values

//============================================================================

 

  else if (menuState == 2)

  {

        lcd.print("Address: ");

        lcd.print(address_aux);

        lcd.setCursor(14,0);

        lcd.print("#");

        lcd.print(menuState);

        lcd.setCursor(0,1);

        lcd.print("Value: ");

        lcd.print( EEPROM.read(address_aux) );

       

        address_aux = address_aux + 1;

       

        if(address_aux == address + 1)

        {

           menuState = 1;

           address = 0;

           address_aux = 0;

        }

        

        delay(3000);

   

  }

 

  delay(1000);

  lcd.clear();

 

}

 

Comments (0)

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