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

lab4 batu

Page history last edited by Batuhan Altundas 10 years, 7 months ago

 

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

 

/*

  Analog input, analog output, serial output

 

 Reads an analog input pin, maps the result to a range from 0 to 255

 and uses the result to set the pulsewidth modulation (PWM) of an output pin.

 Also prints the results to the serial monitor.

 

 The circuit:

 * potentiometer connected to analog pin 0.

   Center pin of the potentiometer goes to the analog pin.

   side pins of the potentiometer go to +5V and ground

 * LED connected from digital pin 9 to ground

 

 created 29 Dec. 2008

 modified 9 Apr 2012

 by Tom Igoe

 

 This example code is in the public domain.

 

 */

 

// These constants won't change.  They're used to give names

// to the pins used:

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

const int analogOutPin = 9; // Analog output pin that the LED is attached to

 

int sensorValue = 0;        // value read from the pot

int outputValue = 0;        // value output to the PWM (analog out)

 

void setup() {

  // initialize serial communications at 9600 bps:

  Serial.begin(9600); 

}

 

void loop() {

  // read the analog in value:

  sensorValue = analogRead(analogInPin);            

  // map it to the range of the analog out:

  outputValue = map(sensorValue, 0, 1023, 0, 255);  

  // change the analog out value:

  analogWrite(analogOutPin, outputValue);           

 

  // print the results to the serial monitor:

  Serial.print("sensor = " );                       

  Serial.print(sensorValue);      

  Serial.print("\t output = ");      

  Serial.println(outputValue);   

 

  // wait 2 milliseconds before the next loop

  // for the analog-to-digital converter to settle

  // after the last reading:

  delay(2);                     

}

 

 

 

 

 

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

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?

10bit up to 1024 (btw  0&1023)

 

 

 

a. What resistance do you see with a Multimeter when the sensor is flat? When it is bent?10Ohm and 42K

b. What kind of voltages should we expect for the Teensy analog pin based on the sensor resistance? about 5V to 1V 

c. How does the range of the LED's brightness change compared to the potentiometer? pot changes linearly while flex changes exponentially due to the vltage divider

 

d. look up

 

a. What resistance values do you see from your force sensor? 20 to 8k

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

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

 


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?

     it works as there is an object 4m or closer an changes exponentially

 


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

 

// These constants won't change.  They're used to give names

// to the pins used:

 

const int X = A0;  // Analog input pin that the potentiometer is attached to

const int Y = A1;

const int Z = A3;\

 

int vx = 0;        // value read from the pot

int vy = 0;

int vz = 0;

int outputValue = 0;        // value output to the PWM (analog out)

 

void setup() {

  // initialize serial communications at 9600 bps:

  Serial.begin(9600); 

}

 

void loop() {

  // read the analog in value:

  vx = analogRead(X);          
  vy = analogRead(Y); 
  vz = analogRead(Z); 

 

 

  // print the results to the serial monitor:

 

  Serial.print("x = " );                       

  Serial.print(vx);      

 

  Serial.print("\t y = " );                       

  Serial.print(vy);      

 

  Serial.print("\t z = " );                       

  Serial.print(vz);      

 

 

 

  // wait 2 milliseconds before the next loop

  // for the analog-to-digital converter to settle

  // after the last reading:

  delay(2);                     

}

 

 

 

 

Comments (0)

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