Sensors and Programming
Sensors and Programming
Temple University
School of Communications and Theater
Water
Temple University
School of Communications and Theater
Binary Sensors
i.e. switches
Context is important
Temple University
School of Communications and Theater
Resistive Sensors
sense a range of values
Light level - photocell Position - flex sensors Tactile Pressure conductive foam Temperature - thermistor
Temple University
School of Communications and Theater
Advanced Sensors
accelerometers
distance - ultrasonic, IR capacitive proximity microphones GPS
Temple University
School of Communications and Theater
Power
Analog Inputs
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
ProtoShield
plugs into top of Arduino board
Assembly instructions for the other (Ladyada) version may be found at: http://www.ladyada.net/make/pshield/make.html
Temple University
School of Communications and Theater
Arduino Shields
Extend Arduino Capabilities
Example Shields: Xbee (wireless communications) Wave (audio playback, MP3) GPS & data logging Lithium Backpack (battery power) Motor Shield Button Shield Video (Atari quality)
Temple University
School of Communications and Theater
Program can then run without PC Program restarts whenever Arduino power is applied or reset button is pressed Arduino can be powered by USB or external 7-12V supply
Temple University
School of Communications and Theater
Variables declared at beginning used to store numeric values or text Functions Setup (only executed once) Loop (main part of program, continuously repeated) Digital I/O Pins are general purpose, configure them in Setup
pinMode(PinNumber, OUTPUT);
Analog capable outputs (pins 9,10,11) should be set as outputs if needed Analog input pins (0-5) do not need to be configured
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
Program Exercises
From Arduino Examples
Blink LED (binary output) Fade LED (analog output) binary input if { } else { }
Attach a photosensor (analog input) Adjust blink rate based on light level Send light level values to Mac using Serial.print FYI, example programs from the book can be found here:
http://makezine.com/getstartedarduino/ Copy and and paste them into an Arduino window, modify if desired, and then upload them to the board.
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
Active Sensor Requires Power Generates an analog signal Generally 0-5V output Example: distance sensors
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
More on Diodes
Resistors Follow Ohms law: V = IR Diodes DO NOT follow Ohms Law Diodes have a voltage drop across them (like a resistor) But diode voltage is (relatively) independent of current thru the diode
Temple University
School of Communications and Theater
Temple University
School of Communications and Theater
Programming
Conditional: If { } else { } Loop: For { } Input and Output pinMode(pin#, input or output) digitalWrite(pin#, HIGH or LOW) digitalRead(pin#) analogWrite(pin#, 0-255) analogRead(pin#) Serial Communications Serial.begin(baud rate) Serial.println(number)
Temple University
School of Communications and Theater
Assignments
Build LED flasher kit Build protoshield
See earlier slide for example image of NKC electronics version Assembly instructions for the Ladyada version may be found at: http://www.ladyada.net/make/pshield/make.html
Read Chapter 5 and Appendix C in Getting Started with Arduino Extra Credit:
In class we worked with two Arduino programs, one (Blink) flashed an LED on and off every second, the other (Fading) made the brightness of an LED fade slowly in and out. Connect 2 LEDs to the Arduino and write a program (or modify the Blink or Fading program) to make one LED fade in and out and the other flash on and off.
Temple University
School of Communications and Theater