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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

LAB 4

Page history last edited by Trevor Kalkus! 12 years, 10 months ago

LAB 4

PART 1

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

int sensorPin = A0; // select the input pin for the potentiometer

int ledPin = 9; // select 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)/4;

Serial.println(sensorValue);

// turn the ledPin on

analogWrite(ledPin, sensorValue);

// stop the program for <sensorValue> milliseconds:

}

 

PART 2

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

It reads 0 to 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?

It has 10 (seeing as 2^10 = 1024) but 2 bits of precision is lost (2^8 = 256).

 

PART 3

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

I get about 9.5 kOhms when it’s flat and 40 kOhms when it’s bent.

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

22/(9.5 +22)*5 =

22/(40+22)*5 =

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

The range is much more limited since the flex sensors cannot give as many values.

 

 

 

 

 

 

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

#include <LiquidCrystal.h>

 

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

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

 

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

}

 

void loop() {

lcd.clear();

lcd.print(analogRead(A0));

delay(100);

}

 

PART 4

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

0 to about 350 ohms

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

#include <LiquidCrystal.h>

 

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

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

 

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

}

 

void loop() {

lcd.clear();

lcd.print(analogRead(A0));

lcd.print(" vs ");

lcd.print(analogRead(A1));

delay(100);

}

 

 

 

 

 

PART B

PART 1

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

Far away, the sensor reads in nothing, allowing 0V. As you move closer, the value and voltage increases until you are too close and the sensor can no longer read accurately. The values read up to about 600.

PART 2

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

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

{

// initialize the serial communications:

Serial.begin(9600);

// Provide ground and power by using the analog inputs as normal

// digital pins. This makes it possible to directly connect the

// breakout board to the Arduino. If you use the normal 5V and

// GND pins on the Arduino, you can remove these lines.

pinMode(groundpin, OUTPUT);

pinMode(powerpin, OUTPUT);

digitalWrite(groundpin, LOW);

digitalWrite(powerpin, HIGH);

}

 

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

}

 

 

 

PART D

PART 1

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

 

 

PART 2

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

1 KB

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

The arduino code just divides by 4 to solve the problem.

 

PART 3

a. Use the lab camera to record and upload a short demo of your logger in action.

 

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

 

Comments (0)

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