Professional Documents
Culture Documents
Class 4
Class 4
Class 4
28 Oct 2006 - machineproject - Tod E. Kurt
Recap: Programming
Edit Compile
Reset
Upload
Like always, just make sure. Make led_blink come alive again. Do it. Trust me.
but note, it doesnt work the other way: you cant set it to LOW then wire the switch to +5V.
Seems a little counter-intuitive, think of it as setting the default value of the input
=
A B C
Piezoelectrics
Big word piezein is greek for squeeze Some crystals, when squeezed, make a spark Turns out the process goes the other way too Spark a quartz crystal, and it exes use this to Piezo buzzersback and forth, make sound (ex something it moves air)
Piezo buzzers dont have quartz crystals, but instead a kind of ceramic that also exhibits piezoelectric properties. I pronounce it pie-zoh. Or sometimes pee-ay-zoh.
Piezo Buzzers
Two wires, red & black. Polarity matters: black=ground Apply an oscillating voltage to make a noise The buzzer case supports the piezo element and has resonant cavity for sound
Oscillating voltage alternately squeezes and releases the piezo element. Must apply ucuating voltage, a steady HIGH or LOW wont work. diagrams from:
http://www.maxim-ic.com/appnotes.cfm/appnote_number/988
Piezo Buzzer
Arduino board pin 7 piezo buzzer + gnd
Piezo leads are very thin. The breadboard holes grab them better than the header sockets, which is why the jumper leads are used.
Play a Melody
sound_serial Play the piezo beeper with the Serial Monitor
Making it Quieter
Easiest way: add a resistor
Arduino board pin 7
(brown, black, orange)
10k
piezo buzzer
gnd
Like most things in electronics, if you want less of something, add a resistor. A better value would probably be 1k, but we dont have that on hand. This may not seem important now, but wait for the next project.
This is in the handout, but is also in Examples/pwm_sound/play_melody (pin changed) Melody denition is sort of like the old cell ringtone style Melody playing logic is hard to follow.
Make a Theremin
ooo-weee-ooooo The original spooky sound machine
Works by measuring your bodys electric eld
As heard on Star Trek, Beach Boys, horror movies, Mars Attacks!, and bad New Age songs. Works sorta like those touch switches, but no touching here. That is, your body becomes a variable capacitor.
Make a Theremin
Take photocell circuit from before, bolt it on
+5V
piezo buzzer +
photocell 10k
analog pin 0
gnd
Make a Theremin
theremin Move hand over photocell to change pitch
Play with val processing & cycles count to alter sensitivity, pitch and timbre
Can get several thousand volts, makes a spark You probably have seen a big example of this
already:
replace lighter
I have a demo piezo igniter from one of these lighters. Its fun to shock yourself. Puts out several thousand volts. (ionization voltage of air =~ 30kV/cm)
Piezo Read
To read a piezo you can just hook it into an analog input, but: You need to drain off any voltage with a resistor, or it just builds up You should have a protection diode to limit big voltages, else fry your inputs
piezo buzzer + 5.1v zener 1M
(brown, black, green)
Arduino board
Note polarity of piezo still matters. The protection diode is a special kind of diode called a zener diode. It acts invisible until the voltage gets over its designed value (5.1 volts in this case), then it acts like a short circuit.
Piezo Read
Arduino board
Create two little busses for GND and A0, and hook components across it. Black bar on diode indicates bar of diode.
Piezo Read
piezo_read Whack the piezo to generate a number based on force of whack
Waits for input to go over threshold, then to drop below threshold
Number is t, the number of times it looped waiting for the value to drop below THRESHOLD/2.
time whack! t
Depending on how fast you can watch the input, this technique works either really well or not that well. There are much faster ways of watching inputs that loops with analogRead() But for now it works okay
Take a Break
(see Craft magazine!)
Processing
Processing makes Java programming as fun & easy as Arduino makes AVR programming Started as a tool to make generative art Is also often used to interface to devices like Arduino
And its totally open source like Arduino. Processing GUI and Arduino GUI are from the same code, which is why it looks & acts similar.
Using Processing
First, install
Processing
Load up Sketchbook
Examples Motion Bounce
The Processing application folders are in the handout, no installation is needed. Also try Examples Motion Collision. Its a lot of fun. Notice how Run launches a new window containing the sketch. The black area at the bottom is a status window, just like in Arduino.
About Processing
Processing sketches have very similar structure
to Arduino sketches
setup() set up sketch, like size, framerate draw() like loop(), called repeatedly
So turn off Arduinos Serial Monitor when connecting via Processing and vice-versa.
Processing Serial
common Processing serial use
four steps 1. load library 2. set portname 3. open port 4. read/write port 1. 2. 3. be sure to set to the same as Serial Port in Arduino GUI
4.
All you need to do talk to Arduino in Processing. The import statement says you want to do serial stuff. The new Serial creates a serial port object within Processing Then you can that object (or used the passed in one) to read from in the serialEvent() function
Spookier, Please
arduino_ spookysounds
Every time the piezo is knocked... a scary eye opens and a spooky sound plays
piezo val is printed, but not used: just its existance is
This sketch is in the handout. You can add your own sounds (must be 16-bit WAV or AIFF). Hook a piezo up to your front door, and plug your computer into your stereo. Every time someone knocks on your door, a scary sound is played
Processing to Arduino
real quick
http_rgb_led
Fetch a web page, get a color value from it, send the color to Arduino with RGB LED
This is not to build, just quickly cover. Its not in the handout, but, full details at: http://todbot.com/blog/2006/10/23/diy-ambient-orb-with-arduino-update/
Fun Uses
External Power
Arduino can run off USB power or external power
External power connector USB connector
voltage regulator
External Power
You can use an AC adpater Connector is standard barrel connector Make sure its center positive Voltage can be 9-15 V DC Amps is > 200mA
Actually input voltage can be from like 7.5V to 35V, but dont go over 15V so the voltage regulator doesnt have to work so hard.
center positive
External Power
Or you can use a battery
External Power
An easier way to connect a battery
External Power
Battery life
How long does Arduino last on 9V battery?
Arduino board draws about 40 mA by itself Each LED adds about 20mA when on Each servo maybe 100 mA when running Switches, pots, etc. are effectively zero Battery capacity rated in milliamp-hours (mAh) 9V batteries have about 400 mAh capacity
Summary
Youve learned many different physical building blocks resistive sensors switches/buttons LEDs piezos servos
fast prototyping
Summary
And youve learned many software building blocks serial communication pulse width modulation digital I/O data driven code
multiple tasks
Summary
Some things we didnt cover, like:
+5V Arduino board pin 7 DC motor 1k TIP120 gnd gnd M 1N4004 Arduino board pin 7 1k TIP120 1N4004 +5V 5V relay
to load
motors
relays
Summary
Hope you had fun and learned something
Tod E. Kurt
tod@todbot.com
220
end