| 
  • 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 4 - SPENCER SHULEM

Page history last edited by Benjamin Tee 9 years ago

My computer at the moment has been having kernal panics for the past few hours and I can't really use it... I could only et my lab off of my computer, but not the images and I can't get the video to upload to computer without... well a computer. I am planning on fixing my computer by the end of this weekend, but it's really messed up - I've reinstalled the OS 3 times this weekend and will probably have to get a new computer. I know I can use the lab computers, but I already wrote the code and had just one bug that I never got around to fix so I would prefer not rewriting it and just waiting until my computer is fixed. I answered all of the questions I could until then. thank you. 

A.

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

 // changes the sensorValue so that the change in brightness is

  //not as sudden

  sensorValue /= 10;

  // set the LED brightness to correspond to the sensor reading

 analogWrite(ledPin, sensorValue);  

}

2.

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

Has an 10 bits of resolution

3.

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

flat: 14 kΩ        bent: 36 kΩ

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

5 V = 3.06 V + Vflex     Voltage Read by Pin = Vflex = 1.94 V   flat

5V = 1.90V + Vflex       Voltage Read by Pin = Vflex = 3.10 V   bent

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

Barely compared to the potentiometer because the pot can go from 10k all the way down to 0 - which is a greater difference.

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 = 9;      // select the pin for the LED

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

 

void setup() {

    lcd.begin(16, 2);

  lcd.print("lowly multimeter");

  pinMode(ledPin, OUTPUT);  

  }

void loop() {

 // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

  lcd.setCursor(0, 1);

  lcd.print(sensorValue);

# and for full range:

#UNCOMMENT:  adjSensorValue = map(sensorValue, 350, 750, 0, 255); 

  analogWrite(ledPin, sensorValue #for full range delete this: /4);                

}

✔ Good commenting practice

4.

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

Applying very little pressure it outputs a resistance of 98kΩ from the force sensor. When there is a lot of  pressure  0.5 kΩ.

// b. What kind of relationship does the resistance have as a function of force applied? (eg, linear?)

Logarithmically

✔ Inverse or proportional?

 

c. 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 sensorPin1 = A0;

int sensorPin2 = A1;

int sensorValue1 = 0;

int sensorValue2 = 0;

int sensor1record = 0;

int sensor2record = 0;

 

void setup() {

   lcd.begin(16, 2);

}

 

void loop() {

 

  lcd.setCursor(0,0);

  sensorValue1 = analogRead(sensorPin1);   

   lcd.print(sensorValue1);

   lcd.print("   ");

   if(sensorValue1>sensor1record)

   {

   sensor1record=sensorValue1;

    lcd.setCursor(7,0);

     lcd.print(sensor1record);

   }

 

   lcd.setCursor(0,1);

  sensorValue2 = analogRead(sensorPin2);   

  lcd.print(sensorValue2);

   lcd.print("   ");

  if(sensorValue2>sensor2record)

  {

    sensor2record=sensorValue2;

    lcd.setCursor(7,1);

   lcd.print(sensor2record);

  }

}

B.

1.

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?

Compared to the graph the voltage should look like this. There is a bump at 5 cm and voltage drops if any closer. Past  5 cm decreases. In the data sheet  the voltage appears to level off near 0.5 V… which mine did as well.

 

2.

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

const int sensorX = A1;

const int sensorY = A2;

const int sensorZ = A3;

 

void setup() {

Serial.begin(9600);

}

 

void loop() {

Serial.print("X = ");

Serial.print(analogRead(sensorX));

Serial.print(" Y = ");

Serial.print(analogRead(sensorY));

Serial.print(" Z = ");

Serial.println(analogRead(sensorZ));

delay(500);

}

D.

1. 

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

2. 

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

1024 bytes in 1kb, you can store 1024 byte-sized data samples.

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

Divide the analog data by 4

3. 

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

 

Comments (0)

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