Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Circuits – Lab 2 Arduino and Sensors

Similar presentations


Presentation on theme: "Basic Circuits – Lab 2 Arduino and Sensors"— Presentation transcript:

1 Basic Circuits – Lab 2 Arduino and Sensors
Xmedia Spring 2011

2 Agenda Resistive Sensors Serial Communication Processing

3 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 int val = 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

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 – Resistive Sensor
// 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 int val = 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

6 Arduino – Notes about code
analogRead(pin); Returns 0 to 1023 analogWrite(pin, val); Max val = 255 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 }

7 Arduino – Serial Communication
#define LED 9 int val = 0; void setup() { Serial.begin(9600); pinMode(LED, OUTPUT); } void loop() { val = analogRead(0); Serial.println(val); analogWrite(LED, val/4); delay(10); import processing.serial.* Serial sPort; int val; void setup() { println(Serial.list()); //find the port that is your arduino sPort = new Serial(this, Serial.list()[2], 9600); //set the position of the array so it corresponds //to your arduino } void draw() while(sPort.available() > 0) val = sPort.read(); println(val); background(val);

8 Processing – Notes about code
Serial sPort; //creates the serial port object sPort = new Serial(this, Serial.list()[2], 9600); //instantiates the object and //opens the port sPort.available(); //returns the number of bytes in the buffer to be read sPort.read(); //returns the next byte in the buffer Each value added to the buffer by the Arduino is one byte (0 to 1023). The buffer may contain more than one byte. If you need to transmit data that requires more than one byte, you need to set up a protocol. void serialEvent(Serial sPort) {} //event method called when data is //available

9 Scaling Function

10 Lighting 3 LEDs in Parallel
Each LED gets its own resistor Build this circuit Measure the voltage across each branch Measure the current out of the battery and before each LED

11 Current Split - Parallel
Sum of the current through each branch equals the current from the power source Voltages are the same in each branch

12 Lighting 3 LEDs in Series
One resistor for all the LEDs Build this circuit Measure the voltage across each LED Measure the current out of the battery and before each LED

13 Voltage Split - Series Voltage across each component is different
Current through each component is the same

14 Voltage Divider Vout = Vin * R2 / (R1 + R2)
If R1 is variable, as R1 increases Vout decreases

15 Calculating Resistance
Series Rtotal = R1 + R Rn Paralell 1/Rtotal = 1/R1 + 1/R2 + … + 1/Rn


Download ppt "Basic Circuits – Lab 2 Arduino and Sensors"

Similar presentations


Ads by Google