Arduino Spooky Projects Class2 PDF
Arduino Spooky Projects Class2 PDF
Arduino Spooky Projects Class2 PDF
Class 2
14 Oct 2006 - machineproject - Tod E. Kurt
Recap: Programming
Edit
Compile
Reset
Upload
Known Good
Configuration
Rule #1 of experimenting:
Before trying anything new,
Get back to a known working state
I have a box of multi-colored straws for whatever color LED you like
Digital Input
Most inputs youll use are variations on switches
Switches make or break a connection
knife switch
(SPST)
toggle switch
(SPDT)
magnetic
hexidecimal
tilt
lever
Tiny Switches
gap
connect
when
pushed
Homemade Switches
Trick Penny
Penny on a surface.
When the penny is lifted, alarms go off
Homemade Switches
Trick Penny
Homemade Switches
Smart Wind Chimes
When the wind blows hard enough,
youre sent email
Digital Input
Switches make or break a connection
But Arduino wants to see a voltage
Specifically, a HIGH (5 volts)
or a LOW (0 volts)
HIGH
LOW
Switch to Volts:
Positive Logic
Digital inputs can
pull-down
Press is HIGH
Release is LOW
Switch to Volts:
Inverted Logic
Resistor pulls up
input to 5 volts
Press is LOW
Release is HIGH
pull-up
Or buy pre-cut
Using digitalRead()
In setup(): use pinMode(myPin,INPUT)
to make pin an input
Multiple Switches
Same sub-circuit,
just duplicate
Multiple Switches
spooky, remember?
Take a Break
Analog Input
To computers, analog is chunky
image from:
http://www.engr.colostate.edu/~dga/me307/lectures.html
Analog Input
Analog Input
Arduino (ATmega8) has six ADC inputs
(ADC = Analog to Digital Converter)
Reads voltage between 0 to 5 volts
Resolution is 10-bit (1024 states)
In other words, 5/1024 = 4.8 mV smallest
voltage change you can measure
Analog Input
Sure sure, but how to make a varying voltage?
With a potentiometer. Or just pot.
+5V
measure
gnd
Color coding: red goes to power, blue to ground, purple to measure here (its a mix, see?)
Potentiometers
Moving the knob is like moving
where the arrow taps the voltage on the resistor
And thats actually how it works, btw, if you take apart a pot.
But I might have the directions reversed (clockwise vs. anti-clockwise).
schematic symbol
Pretty cheap too. Can get a grab bag of 100 misc from Jameco for $20
Photocell Circuit
Vcc
pin A0
gnd
Looks a lot like the pot circuit, doesnt it?
Photocell Arduino
Sketch
Can use as before, sketch analog_read_led
Change to 0
Booo!
I design
your eyes
LED Eyeballs
Use your two orange LEDs
Little bit of hot glue and youre set
Blue LEDs have a voltage drop of ~3.4V, two in series makes ~6.8V which is greater than the 5V the
Arduino puts out.
Dont put LEDs in parallel. http://members.misty.com/don/ledd.html
Notice pin 10. Thats important.
LED Eyes
brightness
off
time
I can
Glowing Eyes
Going Further
Glowing LEDs
The last sketch is data driven
So you can plug in any brightness function
Make a flickering candle or a bad neon
light
Going Further
Photocells
Think of some interesting uses
What about multiple photocells?
Homemade Sensors
Make some of your own!
Next Week
Motion with Servos
R,G,B color mixing for mood lighting
Controlling Arduino from a computer
Controlling a computer from Arduino
END Class 2
http://todbot.com/blog/spookyarduino
Tod E. Kurt
tod@todbot.com