1 / 12

Sensors, Arduino , Data

Sensors, Arduino , Data. Xmedia Spring 2012. Agenda. Sensors Flex Sensor Force Sensing Resistor (FSR) Arduino Uploading code Basics Connecting to a circuit PWM Sensors Reading analog data using the serial monitor Methods for scaling the data. Flex Sensor. Variable resistor

jared
Download Presentation

Sensors, Arduino , Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sensors, Arduino, Data Xmedia Spring 2012

  2. Agenda • Sensors • Flex Sensor • Force Sensing Resistor (FSR) • Arduino • Uploading code • Basics • Connecting to a circuit • PWM • Sensors • Reading analog data using the serial monitor • Methods for scaling the data

  3. Flex Sensor • Variable resistor • Changes resistance based on the angle of the bend. • Range: 10 kΩ to 110 kΩ • Positive and negative legs. Orientation does not matter.

  4. Resistive Sensors Flex or bend sensor Resistance increases with bend ~11k -> ~30k (straight -> bent) Photo resistor (i.e. light sensor) Resistance increases when covered ~2k -> ~60k (lots of light -> little light) Force sensitive resistor (FSR, i.e. pressure sensor) Resistance decreases with pressure ~4k -> ~0.5k (light touch -> lots of pressure) Different sensors have different specifications Read the datasheet or test using a multimeter

  5. Arduino

  6. Arduino – Environment • Board • Sometimes it is actually the board you have. • Other times it is not and you have to guess. • Serial Ports • Mac - /dev/cu/whatever • PC – usually COM 5

  7. Arduino – Blinking an LED • Connect LED between pin 13 and GND • Connect Arduino to computer • Upload Code • Compile – play button • Select port – dev/cu. Or COM • Upload – right arrow button

  8. Arduino – Blinking an LED // Example 01 : Blinking LED #define LED 13 //Sets the name LED to pin 13 void setup() { pinMode(LED, OUTPUT); // sets the digital pin LED as output } void loop() { digitalWrite(LED, HIGH); // turns the LED on delay(1000); // waits for a second digitalWrite(LED, LOW); // turns the LED off delay(1000); // waits for a second }

  9. Arduino – Fading an LED using PWM • PWM – pulse width modulation • Approximates analog behavior by turning on and off quickly • Min 0; Max 255 • analogWrite(pin, val); • automatically sets the digital pin to use PWM • Connect LED between pin 9 and GND • Needs a resistor. Calculate the correct value. • Connect Arduino to computer • Write and upload code

  10. Arduino – Fading an LED using PWM // Example 04: Fade an LED in and out like on // a sleeping Apple computer #define LED 9 // the pin for the LED inti = 0; // We’ll use this to count up and down void setup() { pinMode(LED, OUTPUT); // tell Arduino LED is an output } void loop(){ for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in) analogWrite(LED, i); // set the LED brightness delay(10); // Wait 10ms because analogWrite // is instantaneous and we would // not see any change } for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out) analogWrite(LED, i); // set the LED brightness delay(10); // Wait 10ms } }

  11. Arduino – Reading Analog Sensor Data • analogRead(pin); • Min 0; Mac 1023 • Serial.println(val); - debugging for now • Build Circuit, connect Arduino, upload code • Serial monitor – to view debug values

  12. Arduino – Reading Analog Sensor Data // Example 06B: Set the brightness of LED to // a brightness specified by the // value of the analogue input #define LED 9 // the pin for the LED intval = 0; // variable used to store the value // coming from the sensor void setup() { pinMode(LED, OUTPUT); // LED is as an OUTPUT // Note: Analogue pins are // automatically set as inputs } void loop() { val = analogRead(0); // read the value from // the sensor Serial.println(val); analogWrite(LED, val/4); // turn the LED on at // the brightness set // by the sensor delay(10); // stop the program for // some time }

More Related