+ All Categories
Home > Documents > Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

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

Date post: 23-Dec-2015
Category:
Upload: curtis-green
View: 217 times
Download: 0 times
Share this document with a friend
Popular Tags:
15
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011
Transcript
Page 1: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Basic Circuits – Lab 2Arduino and Sensors

XmediaSpring 2011

Page 2: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Agenda

• Parallel vs. Series• Voltage Divider

• Arduino• Uploading code• Basics

• Connecting to a circuit• PWM

• Sensors• Reading analog data

Page 3: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

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

Page 4: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Current Split - Parallel

• Sum of the current through each branch equals the current from the power source

• Voltage drops are the same across each branch

Page 5: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

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

Page 6: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Voltage Split - Series

• Voltage across each component is different

• Current through each component is the same

Page 7: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Voltage Divider

• Vout = Vin * R2 / (R1 + R2)

• If R1 is variable, as R1 increases Vout decreases

Page 8: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Calculating Resistance

• Series• Rtotal = R1 + R2 + . . . + Rn

• Paralell• 1/Rtotal = 1/R1 + 1/R2 + … + 1/Rn

Page 9: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Arduino

Page 10: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

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

Page 11: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Arduino – Blinking an LED// Example 01 : Blinking LED#define LED 13 // LED connected to// digital pin 13void setup(){pinMode(LED, OUTPUT); // sets the digital// pin as output}void loop(){digitalWrite(LED, HIGH); // turns the LED ondelay(1000); // waits for a seconddigitalWrite(LED, LOW); // turns the LED offdelay(1000); // waits for a second}

Page 12: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Arduino – Fading an LED using PWM

• PWM – pulse width modulation• Approximates analog behavior by turning on and off

quickly

• analogWrite(pin, val);• Connect LED between pin 9 and GND• Connect Arduino to computer• Write and upload code

Page 13: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

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 LEDint i = 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 brightnessdelay(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 brightnessdelay(10); // Wait 10ms}}

Page 14: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

Arduino – Reading Analog Sensor Data

• analogRead(pin);• Serial.println(val); - debugging for now• Build Circuit, connect Arduino, upload

code• Serial monitor – to view debug values

Page 15: Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.

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 LEDint 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 sensorSerial.println(val);analogWrite(LED, val/4); // turn the LED on at// the brightness set// by the sensordelay(10); // stop the program for// some time}


Recommended