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

Lab Report 4

Page history last edited by insunj@... 9 years, 5 months ago

Part A. Resistance Varying Sensors

1.  Potentiometer

a. Post a copy of your new code in your lab writeup.

int sensorPin = A0;    // the input pin for the potentiometer
int ledPin = 5;      // the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

 

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); 
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  //value from 0 to 1023
  float brightness = sensorValue*255.0/1023;
  // turn the ledPin on by brightness value
  analogWrite(ledPin, brightness);              
}

 

2.  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~1023

b. How many bits of resolution does the analog to digital converter (ADC) on the Atmega328 have? How many are you really using with the range of voltages you're seeing?
ADC bit resolution = 12 bits

From the range we see, we are really using only 10 bits. (1023 = 2^10-1)

 

3. Flex Sensor

a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent?

726(flat)/ ~360(bent)

b. What kind of voltages should we expect for the Arduino pin based on the sensor resistance? 

360*255/1024 ~ 726*255/1024

c. How does the range of the LED's brightness change compared to the potentiometer?

not in full range (off~brightest) because the mapping is done from 360~726 

 

d. Include a copy of your Lowly Multimeter code in your lab write-up.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 6;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
const int minSensor = 360;
const int maxSensor = 726;

void setup() {
    lcd.begin(16, 2);
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  //value from minSensor to maxSensor
  float brightness = (sensorValue-minSensor)*255.0/(maxSensor-minSensor);
  if(min(255, brightness)==255) brightness = 255;
  if(max(0, brightness)==0) brightness =0;
  lcd.setCursor(0, 1);
  lcd.print(brightness);
  // turn the ledPin on
  analogWrite(ledPin, brightness);               
}

 

4. Force Sensitive Resistor

a. What resistance values do you see from your force sensor?

0 to 1000

b. Include a copy of your FSR thumb wrestling code in your lab write-up.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int sensorPinI = A0;    // the input pin for first FSR
int sensorPinII= A1;      //the input pin for second FSR
int sensorValueI = 0;  // variable to store the value coming from the sensorI

int sensorValueII = 0; 
const int minSensor = 0;
const int maxSensor = 1000;

void setup() {
    lcd.begin(16, 2);
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
}

void loop() {
  // read the values from the sensor:
  sensorValueI = analogRead(sensorPinI);

  sensorValueII = analogRead(sensorPinII);


  lcd.setCursor(0, 1);

  if(max(sensorvalueI, sensorValueII) ==sensorValueI) lcd.print("sensor 1");

  else lcd.print("sensor2");  
}

 

Part B. Voltage Varying Sensors

1. IR Distance Sensor

a. Describe the voltage change over sensing range of the sensor.

it can read distance range of 0.5 inch ~ 15inch (approximate). Resistance read changes from 0 to 660, and LCD voltage read using lowly multimeter code above outputs 0~ 220.

 

2. Accelerometer

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

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// these constants describe the pins. They won't change:
const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
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)

void setup()
{
   lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(powerpin, HIGH);
}

void loop()
{
  lcd.setCursor(0,1);
  lcd.print(analogRead(xpin));

  lcd.setCursor(5,1);
  lcd.print(analogRead(ypin));

  lcd.setCursor(10,1);
  lcd.print(analogRead(zpin));

  // delay before next reading:
  delay(100);
}

 

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

 

1. Design your logger

a. Turn in a copy of your final state diagram.

2. Reading and writing values to the EEPROM

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

1KB EEPROM

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

     analogRead(sensorPin)/4; //each byte of EEPROM hold 0-255, where analog range 0-1023

3. Create your data logger!

 

http://www.youtube.com/watch?v=JeP8kLN1J5M

 

Comments (0)

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