Bionic Arduino Class2
Bionic Arduino Class2
Class 2
compile
upload
l in k
b k
l i n
b sketch runs
Change the “delay()” values to change blink rate
Known Good
Configuration
Rule #1 of experimenting:
schematic gnd
Snug-fit straws on
the end of your
LEDs to make
them glow more
visibly
I have a box of multi-colored straws for whatever color LED you like
Random Behavior
“CandleLight”
Uses simple
pseudo random
number generator
to mimic flame
Use random(min,max)
to pick a number between
min & max.
+5V–
50k
measure–
gnd–
When a resistor goes across a voltage difference, like +5V to Gnd, the voltage measured at any point
along a resistor’s length is proportional to the distance from one side.
If you take apart a pot, there’s a little wiper just like in the schematic symbol.
But I might have the directions reversed (clockwise vs. anti-clockwise).
What good are pots?
Why are we using Analog In 2? Because it’s in the middle. There’s no reason, any of the 6 analog
inputs would work the same.
Pot & LED Circuit
This is what your board should have on it now
+5V
Arduino
+5V board
resistor
220 (red-red-brown)
50k pin 2 pin 9
potentiometer
gnd LED
gnd
gnd
resistor resistor
pin 9 pin 9
LED
gnd gnd
gnd
We’ve been using the one on the left because it makes more sense.
But you’ll see the method on the right as well.
The reason for this is that some circuits can switch to Gnd better than they can switch to +5V.
RGB LEDs
Normal LED
anode +
anode +
cathode –
cathode –
RGB LED
anode +
red cathode –
anode +
blue cathode –
green cathode –
red blue green
Arduino
board
pin 11
pin 10
pin 9
220 (red,red,brown)
gnd
green blue red With RGB you can
make any color
(except black)
Arduino
board
pin 11
pin 10
pin 9
220 (red,red,brown)
gnd
green blue red
slightly bend the longest lead and plug it into the +5v (red) bus
plug remaining leads into rows (12,14,&16 here)
connect 220 (red-red-brown) resistors across middle to matching rows
run wires from resistors to pins 9,10,11 of Arduino, can color-code if you want
It just ramps up and down the red,green,& blue color values and writes them with analogWrite()
from [Link]
Pot-controlled RGB
+5V
common anode
RGB LED
Arduino
+5V board
pin 11
pin 10
50k pin 2 pin 9
pot 220 (red,red,brown)
gnd
green blue red
gnd
Pot-controlled RGB
“RGBPotMixer”
schematic symbol
Pretty cheap too. Can get a grab bag of 100 misc from Jameco for $20
Photocell Circuit
pin A2
brown-black-orange
gnd
sensor
thermistor to analog
input
(temperature) resistor
photocell
(light)
flex sensor
(bend, deflection)
• TX – sending to PC
• RX – receiving from PC
• Used when programming
or communicating
Arduino Says “Hi”
“SerialHelloWorld”
Click on “Serial
Monitor” button to
see output
In “Serial Monitor”,
type “H”, press Send
[Link]() tells
you if data present to read
This sketch is in the handout
Always check [Link]() or if [Link]() != -1 to determine if there’s actual data to read.
Can modify it to print “hello world” after it receives something, but before it checks for ‘H’.
This way you can verify it’s actually receiving something.
Arduino Communications
is just serial communications
LOW
USB to serial
Arduino
microcontroller
Processing
sketch
-OR-
Java program
-OR-
...
Also, USB is a host/peripheral protocol. Being a USB “host” means needing a lot of processing
power and software, not something for a tiny 8kB microcontroller.
It can be a peripheral. In fact, there is an open project called “AVR-USB” that allows AVR chips like
used in Arduino to be proper USB peripherals. See: [Link]
Controlling the Computer
• The “readSerialString()”
function at right takes a
character string and sticks
available serial data into it
Piezo buzzers don’t 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
piezo
Arduino
buzzer
board
+
pin 7
–
gnd
Piezo leads are very thin. The breadboard holes grab them better than the header sockets, which is
why the jumper leads are used.
Or you can jam a jumper wire in the holes to hold in the piezo leads.
Play a Melody
“SoundSerial”
piezo
Arduino Arduino
buzzer
board board
10k
+ +
pin 7 pin 7 piezo
(brown, buzzer
– –
black,
orange)
gnd gnd
Like most things in electronics, if you want less of something, add a resistor.
A better value would probably be 1k, but we don’t have that on hand.
This may not seem important now, but wait for the next project.
Play a Stored Melody
“PlayMelody”
No touching needed!
We’ll use light in lieu of RF Leon Theremin
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.
Light Theremin
“Theremin”
Okay so maybe it sounds more like a bad video game than a spooky movie
The glitchy sound is cause because of the time it takes to read the sensor
There are ways around such stuff, but requires more complex programming using timers &
interrupts
The sound can get annoying quick
Other Serial Devices
to Roomba
Ambient Orb doesn’t connect to computer though. Uses the pager network.
Ambient Devices: [Link]
END Class 2
[Link]
Tod E. Kurt
tod@[Link]