Arduino Projects
Arduino Projects
ABOUT .: OOMLOUT :.
Were a plucky little design company focusing on producing delightfully fun open source products
To check out what we are up to
http://www.oomlout.com
ABOUT SPARKFUN
SparkFun is an energetic young company seeking to make electronics fun, accessible, and approachable to everyone - from kids in elementary school to PhD-toting engineers.
http://www.sparkfun.com/
ABOUT PROBLEMS
We strive to deliver the highest level of quality in each and every thing we produce. If you ever find an ambiguous instruction, a missing piece, or would just like to ask a question, well try our best to help out.
help@oomlout.com
(we like hearing about problems it helps us improve future versions)
TBCN
table of contents
02 03 04 06
08 10 12 14 16 18 20 22 24 26 28 30 32 34
Spin Motor Spin - (Transistor and Motor) A Single Servo - (Servos) 8 More LEDs - (74HC595 Shift Register) Music - (Piezo Elements) Button Pressing - (Pushbuttons) Twisting - (Potentiometers) Light - (Photo Resistors) Temperature - (TMP36 Temperature Sensor) Larger Loads - (Relays) Colorful Light - (RGB LED) Measuring Bends - (Flex Sensor) Fancy Sensing - (Soft Potentiometer)
01
01 ASEM
assembling the pieces
.: PUTTING IT TOGETHER :.
Arduino Holder x1
Breadboard x1
Arduino x1
02
02 INST
installing
(software and hardware)
Windows XP
Step 2: Unzip the Software
Unzip arduino-00r r r - version #) -win.zip (r Recommended Path c:\Program Files\
Mac OSX
Step 2: Open The .dmg
Open (mount) arduino-00r (r #) r r -mac.dmg - version
Restart
Finished
Vista, Seven
Step 5: Add new Hardware
Run Device Manager Start > Run > devmgmt.msc Choose the Arduino
Other Devices > Arduino Uno (Uno)
Finished
Update Driver
click Update Driver
Select Driver
click Browse My Computer for Driver Software c:\program files\arduino-00r r \drivers\
.: NOTE: :. .: Encountering problems? :. .: Would like more details? Using Linux? :. .: http://ardx.org/LINU :.
Finished
03
03 PROG
programming primer
STRUCTURE
Each Arduino program (often called a sketch) has two required functions (also called routines).
void setup(){
void loop(){
All the code between the two curly brackets will be run once when your Arduino program first runs.
This function is run after setup has finished. After it has run once it will be run again, and again, until power is removed.
SYNTAX
One of the slightly frustrating elements of C is its formatting requirements (this also makes it very powerful). If you remember the following you should be alright.
// (single line comment) It is often useful to write notes to yourself as you go along about what each line of code does. To do this type two forward slashes and everything until the end of the line will be ignored by your program.
/* */(multi line comment) If you have a lot to say you can span several lines as a comment. Everything between these two symbols will be ignored in your program.
{ } (curly brackets) Used to define when a block of code starts and ends (used in functions as well as loops).
; (semicolon) Each line of code must be ended with a semicolon (a missing semicolon is often the reason for a program refusing to compile).
VARIABLES
A program is nothing more than instructions to move numbers around in an intelligent way. Variables are used to do the moving.
int (integer) The main workhorse, stores a number in 2 bytes (16 bits). Has no decimal places and will store a value between -32,768 and 32,767. long (long) Used when an integer is not large enough. Takes 4 bytes (32 bits) of RAM and has a range between -2,147,483,648 and 2,147,483,647. char (character) Stores one character using the ASCII code (ie 'A' = 65). Uses one byte (8 bits) of RAM. The Arduino handles strings as an array of chars.
boolean (boolean)
A simple True or False variable. Useful because it only uses one bit of RAM.
float (float) Used for floating point math (decimals). Takes 4 bytes (32 bits) of RAM and has a range between -3.4028235E+38 and 3.4028235E+38.
04
03 PROG
programming primer
MATH OPERATORS
Operators used for manipulating numbers. (they work like simple math).
= (assignment) makes something equal to something else (eg. x = 10 * 2 (x now equals 20)) % (modulo) gives the remainder when one number is divided by another (ex. 12 % 10 (gives 2)) + (addition) (subtraction) * (multiplication) / (division)
COMPARISON OPERATORS
Operators used for logical comparison.
== != < > (equal to) (eg. 12 == 10 is FALSE or 12 == 12 is TRUE) (not equal to) (eg. 12 != 10 is TRUE or 12 != 12 is FALSE) (less than) (eg. 12 < 10 is FALSE or 12 < 12 is FALSE or 12 < 14 is TRUE) (greater than) (eg. 12 > 10 is TRUE or 12 > 12 is FALSE or 12 > 14 is
FALSE)
CONTROL STRUCTURE
Programs are reliant on controlling what runs next, here are the basic control elements (there are many more online).
if(condition){ } else if( condition ){ } else { }
This will execute the code between the curly brackets if the condition is true, and if not it will test the else if condition if that is also false the else code will execute.
DIGITAL
pinMode(pin, mode);
Used to set a pin's mode, pin is the pin number you would like to address 0-19 (analog 05 are 14-19). The mode can either be INPUT or OUTPUT.
digitalWrite(pin, value);
int digitalRead(pin); Once a pin is set as an INPUT you can use this to return whether it is HIGH (pulled to +5 volts) or LOW (pulled to ground).
Once a pin is set as an OUTPUT, it can be set either HIGH (pulled to +5 volts) or LOW (pulled to ground).
ANALOG
The Arduino is a digital machine but it has the ability to operate in the analog realm (through tricks). Here's how to deal with things that aren't digital.
int analogWrite(pin, value);
Some of the Arduino's pins support pulse width modulation (3, 5, 6, 9, 10, 11). This turns the pin on and off very quickly making it act like an analog output. The value is any number between 0 (0% duty cycle ~0v) and 255 (100% duty cycle ~5 volts).
int analogRead(pin);
When the analog input pins are set to input you can read their voltage. A value between 0 (for 0 volts) and 1024 (for 5 volts) will be returned.
05
04 ELEC
electronics primer
ELECTRONICS IN BRIEF
No previous electronic experience is required to have fun with this kit. Here are a few details about each component to make identifying, and perhaps understanding them, a bit easier. If at any point you are worried about how a component is used or why it's not working the internet offers a treasure trove of advice, or we can be contacted at help@oomlout.com
Emits light when a small current is passed through it. (only in one direction) Identifying: Looks like a mini light bulb.
No. of Leads: 2 (one longer, this one connects to positive) Things to watch out for: - Will only work in one direction - Requires a current limiting resistor More Details: http://ardx.org/LED
No. of Leads: 2 Things to watch out for: - Will only work in one direction More Details: http://ardx.org/DIOD
Diode
What it Does: The electronic equivalent of a one way valve. Allowing current to flow in one direction but not the other. Identifying: Usually a cylinder with wires extending from either end. (and an off center line indicating polarity)
Resistors
What it Does: Restricts the amount of current that can flow through a circuit. Identifying: Cylinder with wires extending from either end. The value is displayed using a color coding system (for details see next page)
No. of Leads: 2 Things to watch out for: - Easy to grab the wrong value (double
check the colors before using)
Transistor
What it Does: Uses a small current to switch or amplify a much larger current. Identifying: Comes in many different packages but you can read the part number off the package.
(P2N2222AG in this kit and find a datasheet online)
No. of Leads: 3 (Base, Collector, Emitter) Things to watch out for: - Plugging in the right way round (also a
current limiting resistor is often needed on the base pin)
Hobby Servo
DC Motor
What it Does: Takes a timed pulse and converts it into an angular position of the output shaft. Identifying: A plastic box with 3 wires coming out one side and a shaft with a plastic horn out the top. What it Does: Spins when a current is passed through it. Identifying: This one is easy, it looks like a motor. Usually a cylinder with a shaft coming out of one end.
No. of Leads: 3 Things to watch out for: - The plug is not polarized so make sure it is plugged in the right way. More Details: http://ardx.org/SERV No. of Leads: 2 Things to watch out for: - Using a transistor or relay that is rated for the size of motor you're using. More Details: http://ardx.org/MOTO
06
04 ELEC
COMPONENT DETAILS (CONT.)
Piezo Element
What it Does: A pulse of current will cause it to click. A stream of pulses will cause it to emit a tone. Identifying: In this kit it comes in a little black barrel, but sometimes they are just a gold disc. No. of Leads: 2 Things to watch out for: - Difficult to misuse. More Details: http://ardx.org/PIEZ
No. of Leads: 2 - 100s (in this kit there is one with 3 (TMP36) and
one with 16 (74HC595)
electronics primer
IC (Integrated Circuit)
What it Does: Packages any range of complicated electronics inside an easy to use package. Identifying: The part ID is written on the outside of the package. (this sometimes requires a lot of light or a magnifying glass to read).
Things to watch out for: - Proper orientation. (look for marks showing pin 1) More Details: http://ardx.org/ICIC
Pushbutton
What it Does: Completes a circuit when it is pressed. Identifying: A little square with leads out the bottom and a button on the top.
No. of Leads: 4 Things to watch out for: - these are almost square so can be inserted 90 degrees off angle. More Details: http://ardx.org/BUTT No. of Leads: 3 Things to watch out for: - Accidentally buying logarithmic scale. More Details: http://ardx.org/POTE
Potentiometer
What it Does: Produces a variable resistance dependant on the angular position of the shaft. Identifying: They can be packaged in many different form factors, look for a dial to identify.
Photo Resistor
What it Does: Produces a variable resistance dependant on the amount of incident light. Identifying: Usually a little disk with a clear top and a curvy line underneath. No. of Leads: 2 Things to watch out for: - Remember it needs to be in a voltage divider before it provides a useful input. More Details: http://ardx.org/PHOT
LEAD CLIPPING
Some components in this kit come with very long wire leads. To make them more compatible with a breadboard a couple of changes are required. LEDs: Clip the leads so the long lead is ~10mm (3/8) long and the short one is ~7mm (9/32). Resistors: Bend the leads down so they are 90 degrees to the cylinder. Then snip them so they are ~6mm (1/4) long. Other Components: Other components may need clipping. Use your discretion when doing so.
0 1 2 3 4
5 6 7 8 9
07
CIRC-01
THE CIRCUIT:
Parts:
CIRC-01 Breadboard Sheet x1 330 Ohm Resistor Orange-Orange-Brown x1 2 Pin Header x4 5mm Yellow LED x1 Wire
Schematic
Arduino
pin 13
longer lead
+
LED
(light emitting diode)
resistor gnd
(330ohm) (orange-orange-brown)
(ground) (-)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS01S .:view:. assembly video http://ardx.org/VIDE01
08
CODE
CIRC-01
// The setup() method runs once, when the sketch starts void setup() { // initialize the digital pin as an output: pinMode(ledPin, OUTPUT); } // the loop() method runs over and over again, // as long as the Arduino has power void loop() { digitalWrite(ledPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledPin, LOW); // set the LED off delay(1000); // wait for a second }
NOT WORKING?
(3 things to try)
Program Not Uploading This happens sometimes, the most likely cause is a confused serial port, you can change this in tools>serial port>
Still No Success?
A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can. help@oomlout.com
MAKING IT BETTER
Changing the pin: The LED is connected to pin 13 but we can use any of the Arduinos pins. To change it take the wire plugged into pin 13 and move it to a pin of your choice (from 013) (you can also use analog 0-5, analog 0 is 14...) Then in the code change the line:
int ledPin = 13; -> int ledPin = newpin;
Control the brightness: Along with digital (on/off) control the Arduino can control some pins in an analog (brightness) fashion. (more details on this in later circuits). To play around with it. Change the LED to pin 9: (also change the wire) ledPin = 13; -> int ledPin = 9; Replace the code inside the { }'s of loop() with this: analogWrite(ledPin, new number); (new number) = any number between 0 and 255. 0 = off, 255 = on, in between = different brightness Fading: We will use another included example program. To open go to File > Examples > 3.Analog > Fading Then upload to your board and watch as the LED fades in and then out.
Then upload the sketch: (ctrl-u) Change the blink time: Unhappy with one second on one second off? In the code change the lines: digitalWrite(ledPin, HIGH); delay(time on); //(seconds * 1000) digitalWrite(ledPin, LOW); delay(time off); //(seconds * 1000)
http://ardx.org/CIRC01
09
CIRC-02
WHAT WERE DOING:
We have caused one LED to blink, now it's time to up the stakes. Lets connect eight. We'll also have an opportunity to stretch the Arduino a bit by creating various lighting sequences. This circuit is also a nice setup to experiment with writing your own programs and getting a feel for how the Arduino works. Along with controlling the LEDs we start looking into a few simple programming methods to keep your programs small. for() loops - used when you want to run a piece of code several times. arrays[] - used to make managing variables easier (it's a group of variables).
THE CIRCUIT:
Parts:
CIRC-02 Breadboard Sheet x1 330 Ohm Resistor Orange-Orange-Brown x8 2 Pin Header x4 5mm Yellow LED x8 Wire
Schematic
pin 2 pin 3 pin 4 pin 5 LED resistor
330ohm gnd
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS02S .:view:. assembly video http://ardx.org/VIDE02
10
CODE
CIRC-02
* will then turn them off void oneAfterAnotherNoLoop(){ int delayTime = 100; //the time (in milliseconds) to pause //between LEDs digitalWrite(ledPins[0], HIGH); //Turns on LED #0 //(connected to pin 2) delay(delayTime); //waits delayTime milliseconds ... ... digitalWrite(ledPins[7], HIGH); //Turns on LED #7 //(connected to pin 9) delay(delayTime); //waits delayTime milliseconds //Turns Each LED Off digitalWrite(ledPins[7], LOW); //Turns off LED #7 delay(delayTime); //waits delayTime milliseconds ... -----more code in the downloadable version------
NOT WORKING?
(3 things to try)
Starting Afresh
Operating out of sequence
With eight wires it's easy to cross a couple. Double check that the first LED is plugged into pin 2 and each pin there after.
Its easy to accidentally misplace a wire without noticing. Pulling everything out and starting with a fresh slate is often easier than trying to track down the problem.
MAKING IT BETTER
Switching to loops: In the loop() function there are 4 lines. The last three all start with a '//'. This means the line is treated as a comment (not run). To switch the program to use loops change the void loop() code to:
//oneAfterAnotherNoLoop(); oneAfterAnotherLoop(); //oneOnAtATime(); //inAndOut();
Extra animations: Tired of this animation? Then try the other two sample animations. Uncomment their lines and upload the program to your board and enjoy the new light animations. (delete the slashes in front of row 3 and then 4) Testing out your own animations: Jump into the included code and start changing things. The main point is to turn an LED on use digitalWrite(pinNumber, HIGH); then to turn it off use digitalWrite(pinNumber, LOW); . Type away, regardless of what you change you won't break anything.
Upload the program, and notice that nothing has changed. You can take a look at the two functions, each does the same thing, but use different approaches (hint: the second one uses a for loop).
http://ardx.org/CIRC02
11
CIRC-03
THE CIRCUIT:
Parts:
CIRC-03 Breadboard Sheet x1 Toy Motor x1 2 Pin Header x4 Diode (1N4001) x1 Transistor P2N2222AG (TO92) x1 10k Ohm Resistor Brown-Black-Orange x1 Wire
Schematic
Arduino pin 9 resistor (10kohm)
Base Collector
Transistor P2N2222AG
Emitter
Diode
Motor
gnd
(ground) (-)
+5 volts
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS03S .:view:. assembly video http://ardx.org/VIDE03
12
.:NOTE: if your arduino is resetting you need to install the optional capacitor:.
CODE
CIRC-03
void motorOnThenOffWithSpeed(){ int onSpeed = 200;// a number between //0 (stopped) and 255 int onTime = 2500; int offSpeed = 50;// a number between //0 (stopped) and 255 int offTime = 1000; analogWrite(motorPin, onSpeed); // turns the motor On delay(onTime); // waits for onTime analogWrite(motorPin, offSpeed); // turns the motor Off delay(offTime); // waits for offTime }
milliseconds milliseconds
void motorAcceleration(){ int delayTime = 50; //time between each speed step for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255 analogWrite(motorPin, i); //sets the new speed delay(delayTime);// waits for delayTime milliseconds } for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0 analogWrite(motorPin, i); //sets the new speed delay(delayTime);//waits for delayTime milliseconds } }
NOT WORKING?
(3 things to try)
Still No Luck?
If you sourced your own motor, double check that it will work with 5 volts and that it does not draw too much power.
P2N2222AG
(many are reversed).
MAKING IT BETTER
Controlling speed: We played with the Arduino's ability to control the brightness of an LED earlier now we will use the same feature to control the speed of our motor. The Arduino does this using something called Pulse Width Modulation (PWM). This relies on the Arduino's ability to operate really, really fast. Rather than directly controlling the voltage coming from the pin the Arduino will switch the pin on and off very quickly. In the computer world this is going from 0 to 5 volts many times a second, but in the human world we see it as a voltage. For example if the Arduino is PWM'ing at 50% we see the light dimmed 50% because our eyes are not quick enough to see it flashing on and off. The same feature works with transistors. Don't believe me? Try it out. In the loop() section change it to this // motorOnThenOff(); motorOnThenOffWithSpeed(); // motorAcceleration(); Then upload the program. You can change the speeds by changing the variables onSpeed and offSpeed. Accelerating and decelerating: Why stop at two speeds, why not accelerate and decelerate the motor. To do this simply change the loop() code to read // motorOnThenOff(); // motorOnThenOffWithSpeed(); motorAcceleration(); Then upload the program and watch as your motor slowly accelerates up to full speed then slows down again. If you would like to change the speed of acceleration change the variable delayTime (larger means a longer acceleration time).
http://ardx.org/CIRC03
13
CIRC-04
THE CIRCUIT:
Parts:
CIRC-04 Breadboard Sheet x1 Mini Servo x1 2 Pin Header x4 3 Pin Header x1 Wire
Schematic
Arduino
pin 9
Mini Servo
gnd (black)
gnd
(ground) (-)
+5 volts
(5V)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS04S .:view:. assembly video http://ardx.org/VIDE04
14
CODE
CIRC-04
// Sweep // by BARRAGAN <http://barraganstudio.com> #include <Servo.h> Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); } // attaches the servo on pin 9 to the servo object
void loop() { for(pos = 0; pos < 180; pos += { myservo.write(pos); delay(15); } for(pos = 180; pos>=1; pos-=1) { myservo.write(pos); delay(15); } }
1)
// goes from 0 degrees to 180 degrees // in steps of 1 degree // tell servo to go to position in variable 'pos' // waits 15ms for the servo to reach the position // goes from 180 degrees to 0 degrees // tell servo to go to position in variable 'pos' // waits 15ms for the servo to reach the position
NOT WORKING?
(3 things to try)
Fits and Starts If the servo begins moving then twitches, and there's a flashing light on your Arduino board, the power supply you are using is not quite up to the challenge. Using a fresh battery instead of USB should solve this problem.
MAKING IT BETTER
Potentiometer control: We have yet to experiment with inputs but if you would like to read ahead, there is an example program File > Servo > Knob. This uses a potentiometer (CIRC08) to control the servo. You can find instructions online here: http://ardx.org/KNOB Self timing: While it is easy to control a servo using the Arduino's included library sometimes it is fun to figure out how to program something yourself. Try it. We're controlling the pulse directly so you could use this method to control servos on any of the Arduino's 20 available pins (you need to highly optimize this code before doing that).
int servoPin = 9; void setup(){ pinMode(servoPin,OUTPUT); } Open Source Robotic Arm (uses a servo controller as well as the Arduino) void loop() { int pulseTime = 2100; //(the number of microseconds //to pause for (1500 90 degrees // 900 0 degrees 2100 180 degrees) digitalWrite(servoPin, HIGH); delayMicroseconds(pulseTime); digitalWrite(servoPin, LOW); delay(25);
Great ideas: Servos can be used to do all sorts of great things, here are a few of our favorites. Xmas Hit Counter http://ardx.org/XMAS
http://ardx.org/CIRC04
15
CIRC-05
WHAT WERE DOING:
Time to start playing with chips, or integrated circuits (ICs) as they like to be called. The external packaging of a chip can be very deceptive. For example, the chip on the Arduino board (a microcontroller) and the one we will use in this circuit (a shift register) look very similar but are in fact rather different. The price of the ATMega chip on the Arduino board is a few dollars while the 74HC595 is a couple dozen cents. It's a good introductory chip, and once you're comfortable playing around with it and its datasheet (available online http://ardx.org/74HC595 ) the world of chips will be your oyster. The shift register (also called a serial to parallel converter), will give you an additional 8 outputs (to control LEDs and the like) using only three Arduino pins. They can also be linked together to give you a nearly unlimited number of outputs using the same four pins. To use it you clock in the data and then lock it in (latch it). To do this you set the data pin to either HIGH or LOW, pulse the clock, then set the data pin again and pulse the clock repeating until you have shifted out 8 bits of data. Then you pulse the latch and the 8 bits are transferred to the shift registers pins. It sounds complicated but is really simple once you get the hang of it. (for a more in depth look at how a shift register works visit: http://ardx.org/SHIF)
THE CIRCUIT:
Parts:
CIRC-05 Breadboard Sheet x1 Red LED x8 2 Pin Header x4 330 Ohm Resistor Orange-Orange-Brown x8 Shift Register 74HC595 x1 Wire
Schematic
LED resistor (330ohm) gnd
pin pin pin +5 volts 4 3 2 74HC595 +5V 0 1 2 data 3 clock 4 latch 5 6 gnd 7
(ground) (-)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS05S .:view:. assembly video http://ardx.org/VIDE05
16
CODE
CIRC-05
digitalWrite(latch, LOW); //Pulls the chips latch low shiftOut(data, clock, MSBFIRST, value); //Shifts out 8 bits to the shift register digitalWrite(latch, HIGH); //Pulls the latch high displaying the data } ---------- More Code Online ----------
void loop() // run over and over again { int delayTime = 100; //delay between LED updates for(int i = 0; i < 256; i++){ updateLEDs(i); delay(delayTime); } } /* * updateLEDs() - sends the LED states set * in value to the 74HC595 sequence */ void updateLEDs(int value){
NOT WORKING?
(3 things to try)
Frustration? Shoot us an e-mail, this circuit is both simple and complex at the same time. We want to hear about problems you have so we can address them in future editions. help@oomlout.com
MAKING IT BETTER
Doing it the hard way: An Arduino makes rather complex actions very easy, shifting out data is one of these cases. However one of the nice features of an Arduino is you can make things as easy or difficult as you like. Let's try an example of this. In your loop switch the line: updateLEDs(i) -> updateLEDsLong(i); Upload the program and notice nothing has changed. If you look at the code you can see how we are communicating with the chip one bit at a time. (for more details http://ardx.org/SPI ). Controlling individual LEDs: Time to start controlling the LEDs in a similar method as we did in CIRC02. As the eight LED states are stored in one byte (an 8 bit value) for details on how this works try http://ardx.org/BINA. An Arduino is very good at manipulating bits and there are an entire set of operators that help us out. Details on bitwise maths ( http://ardx.org/BITW ). Our implementation. Replace the loop() code with int delayTime = 100; //the number of milliseconds //to delay //between LED updates for(int i = 0; i < 8; i++){ changeLED(i,ON); delay(delayTime); } for(int i = 0; i < 8; i++){ changeLED(i,OFF); delay(delayTime); } Uploading this will cause the lights to light up one after another and then off in a similar manner. Check the code and wikipedia to see how it works, or shoot us an e-mail if you have questions. More animations: Now things get more interesting. If you look back to the code from CIRC02 (8 LED Fun) you see we change the LEDs using digitalWrite(led, state), this is the same format as the routine we wrote changeLED(led, state). You can use the animations you wrote for CIRC02 by copying the code into this sketch and changing all the digitalWrite()'s to changeLED()'s. Powerful? Very. (you'll also need to change a few other things but follow the compile errors and it works itself out).
http://ardx.org/CIRC05
17
CIRC-06
THE CIRCUIT:
Parts:
CIRC-06 Breadboard Sheet x1 2 Pin Header x4 Piezo Element x1 Wire
Schematic
Arduino
pin 9
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS06S .:view:. assembly video http://ardx.org/VIDE06
18
CODE
CIRC-06
void playNote(char note, int duration) { char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; // play the tone corresponding to the note name for (int i = 0; i < 8; i++) { if (names[i] == note) { playTone(tones[i], duration); } } } void setup() { pinMode(speakerPin, OUTPUT); } void loop() { for (int i = 0; i < length; i++) { if (notes[i] == ' ') { delay(beats[i] * tempo); // rest } else { playNote(notes[i], beats[i] * tempo); } // pause between notes delay(tempo / 2); } }
NOT WORKING?
No Sound
(3 things to try)
Tired of Twinkle Twinkle Little Star? The code is written so you can easily add your own songs, check out the code below to get started.
Given the size and shape of the piezo element it is easy to miss the right holes on the breadboard. Try double checking its placement.
MAKING IT BETTER
Playing with the speed: The timing for each note is calculated based on variables, as such we can tweak the sound of each note or the timing. To change the speed of the melody you need to change only one line. int tempo = 300; ---> int tempo = (new #) Change it to a larger number to slow the melody down, or a smaller number to speed it up. Tuning the notes: If you are worried about the notes being a little out of tune this can be fixed as well. The notes have been calculated based on a formula in the comment block at the top of the program. But to tune individual notes just adjust their values in the tones[] array up or down until they sound right. (each note is matched by its name in the names[] (array ie. c = 1915 )
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
Composing your own melodies: The program is pre-set to play 'Twinkle Twinkle Little Star' however the way it is programmed makes changing the song easy. Each song is defined in one int and two arrays, the int length defines the number of notes, the first array notes[] defines each note, and the second beats[] defines how long each note is played. Some Examples: Twinkle Twinkle Little Star
int length = 15; char notes[] = {"ccggaagffeeddc "}; int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
http://ardx.org/CIRC06
19
CIRC-07
THE CIRCUIT:
Parts:
CIRC-07 Breadboard Sheet x1 10k Ohm Resistor Brown-Black-Orange x2 2 Pin Header x4 Pushbutton x2 Red LED x1 Wire
Schematic
Arduino
pin 2 pin 3
Arduino
pin 13
+5 volts resistor
LED
resistor
(330 ohm)
pushbutton
gnd
(ground) (-)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS07S .:view:. assembly video http://ardx.org/VIDE07
20
CODE
CIRC-07
(example from the great arduino.cc site, check it out for other great ideas) /* * Button * by DojoDave <http://www.0j0.org> * * Turns on and off a light emitting diode(LED) connected to digital * pin 13, when pressing a pushbutton attached to pin 7. * http://www.arduino.cc/en/Tutorial/Button */ int ledPin = 13; // choose the pin for the LED int inputPin = 2; // choose the input pin (for a pushbutton) int val = 0; // variable for reading the pin status
void setup() { pinMode(ledPin, OUTPUT); pinMode(inputPin, INPUT); } void loop(){ val = digitalRead(inputPin); if (val == HIGH) { digitalWrite(ledPin, LOW); } else { digitalWrite(ledPin, HIGH); } } // declare LED as output // declare pushbutton as input
// read input value // check if the input is HIGH // turn LED OFF // turn LED ON
NOT WORKING?
(3 things to try)
Underwhelmed?
No worries these circuits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.
MAKING IT BETTER
On button off button: The initial example may be a little underwhelming (ie. I don't really need an Arduino to do this), lets make it a little more complicated. One button will turn the LED on the other will turn the LED off. Change the code to:
int ledPin = 13; int inputPin1 = 3; int inputPin2 = 2; // choose the pin for the LED // button 1 // button 2
Fading up and down: Lets use the buttons to control an analog signal. To do this you will need to change the wire connecting the LED from pin 13 to pin 9, also change this in code. int ledPin = 13; ----> int ledPin = 9; Next change the loop() code to read.
int value = 0; void loop(){ if (digitalRead(inputPin1) == LOW) { value--; } else if (digitalRead(inputPin2) == LOW) { value++; } value = constrain(value, 0, 255); analogWrite(ledPin, value); delay(10); }
void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin1, INPUT); // make button 1 an input pinMode(inputPin2, INPUT); // make button 2 an input } void loop(){ if (digitalRead(inputPin1) == LOW) { digitalWrite(ledPin, LOW); // turn LED OFF } else if (digitalRead(inputPin2) == LOW) { digitalWrite(ledPin, HIGH); // turn LED ON } }
Changing fade speed: If you would like the LED to fade faster or slower, there is only one line of code that needs changing;
delay(10); ----> delay(new #);
Upload the program to your board, and start toggling the LED on and off.
To fade faster make the number smaller, slower requires a larger number.
http://ardx.org/CIRC07
21
CIRC-08
.:Twisting:. .:Potentiometers:.
THE CIRCUIT:
Parts:
CIRC-08 Breadboard Sheet x1 Yellow LED x1 2 Pin Header x4 330 Ohm Resistor Orange-Orange-Brown x1 Potentiometer 10k ohm x1 Wire
Schematic
Arduino
pin 13
+5 volts Arduino
analog pin 0
Potentiometer
LED
(light emitting diode)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS08S .:view:. assembly video http://ardx.org/VIDE08
22
CODE
CIRC-08
/* Analog Input * Demonstrates analog input by reading an analog sensor on analog * pin 0 and turning on and off a light emitting diode(LED) connected to digital pin 13. * The amount of time the LED will be on and off depends on the value obtained by * analogRead(). * Created by David Cuartielles * Modified 16 Jun 2009 * By Tom Igoe * http://arduino.cc/en/Tutorial/AnalogInput */ int sensorPin = 0; int ledPin = 13; int sensorValue = 0; // select the input pin for the potentiometer // select the pin for the LED // variable to store the value coming from the sensor //declare the ledPin as an OUTPUT:
void loop() { sensorValue = analogRead(sensorPin);// digitalWrite(ledPin, HIGH); // delay(sensorValue); // digitalWrite(ledPin, LOW); // delay(sensorValue); // }
value from the sensor: ledPin on program for <sensorValue> milliseconds: ledPin off: program for for <sensorValue> milliseconds:
NOT WORKING?
(3 things to try)
Sporadically Working
This is most likely due to a slightly dodgy connection with the potentiometer's pins. This can usually be conquered by taping the potentiometer down.
Not Working
Make sure you haven't accidentally connected the potentiometer's wiper to digital pin 2 rather than analog pin 2. (the row of pins beneath the power pins)
Still Backward
You can try operating the circuit upside down. Sometimes this helps.
MAKING IT BETTER
Threshold switching: Sometimes you will want to switch an output when a value exceeds a certain threshold. To do this with a potentiometer change the loop() code to.
void loop() { int threshold = 512; if(analogRead(sensorPin) > threshold){ digitalWrite(ledPin, HIGH);} else{ digitalWrite(ledPin, LOW);} }
This will cause the LED to turn on when the value is above 512 (about halfway), you can adjust the sensitivity by changing the threshold value. Fading: Lets control the brightness of an LED directly from the potentiometer. To do this we need to first change the pin the LED is connected to. Move the wire from pin 13 to pin 9 and change one line in the code.
int ledPin = 13; ----> int ledPin = 9;
Upload the code and watch as your LED fades in relation to your potentiometer spinning. (Note: the reason we divide the value by 4 is the analogRead() function returns a value from 0 to 1024 (10 bits), and analogWrite() takes a value from 0 to 255 (8 bits) ) Controlling a servo: This is a really neat example and brings a couple of circuits together. Wire up the servo like you did in CIRC-04, then open the example program Knob (File > Examples > Servo > Knob ), then change one line of code. int potpin = 0; ----> int potpin = 2; Upload to your Arduino and then watch as the servo shaft turns as you turn the potentiometer.
http://ardx.org/CIRC08
23
CIRC-09
THE CIRCUIT:
Parts:
CIRC-09 Breadboard Sheet x1 10k Ohm Resistor Brown-Black-Orange x1 2 Pin Header x4 Photo-Resistor x1 Yellow LED x1 Wire
Schematic
Arduino
pin 13
LED
resistor
(330ohm)
resistor
(10k ohm)
gnd
(ground) (-)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS09S .:view:. assembly video http://ardx.org/VIDE09
24
CODE
CIRC-09
//output } /* * loop() - this function will start after setup * finishes and then repeat */ void loop() { int lightLevel = analogRead(lightPin); //Read the // lightlevel lightLevel = map(lightLevel, 0, 900, 0, 255); //adjust the value 0 to 900 to 0 to 255 lightLevel = constrain(lightLevel, 0, 255); //make sure the value is betwween 0 and 255 analogWrite(ledPin, lightLevel); //write the value }
NOT WORKING?
(3 things to try)
MAKING IT BETTER
Reverse the response: Perhaps you would like the opposite response. Don't worry we can easily reverse this response just change:
analogWrite(ledPin, lightLevel); ----> analogWrite(ledPin, 255 - lightLevel);
Light controlled servo: Let's use our newly found light sensing skills to control a servo (and at the same time engage in a little bit of Arduino code hacking). Wire up a servo connected to pin 9 (like in CIRC-04). Then open the Knob example program (the same one we used in CIRC-08) File > Examples > Servo > Knob. Upload the code to your board and watch as it works unmodified. Using the full range of your servo: You'll notice that the servo will only operate over a limited portion of its range. This is because with the voltage dividing circuit we use the voltage on analog pin 0 will not range from 0 to 5 volts but instead between two lesser values (these values will change based on your setup). To fix this play with the val = map(val, 0, 1023, 0, 179); line. For hints on what to do visit http://arduino.cc/en/Reference/Map .
Upload and watch the response change: Night light: Rather than controlling the brightness of the LED in response to light, let's instead turn it on or off based on a threshold value. Change the loop() code with.
void loop(){ int threshold = 300; if(analogRead(lightPin) > threshold){ digitalWrite(ledPin, HIGH); }else{ digitalWrite(ledPin, LOW); } }
http://ardx.org/CIRC09
25
CIRC-10
.:Temperature:.
.:TMP36 Precision Temperature Sensor:.
THE CIRCUIT:
Parts:
CIRC-10 Breadboard Sheet x1 TMP36 Temperature Sensor x1 2 Pin Header x4
Wire
Schematic
Arduino analog pin 0 +5 volts
TMP36
(precision temperature sensor)
gnd
(ground) (-)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS10S .:view:. assembly video http://ardx.org/VIDE10
26
CODE
/* * * * * * * *
CIRC-10
void loop() // run over and over again { float temperature = getVoltage(temperaturePin); //getting the voltage reading from the //temperature sensor
//TMP36 Pin Variables int temperaturePin = 0;//the analog pin the TMP36's //Vout pin is connected to //the resolution is //10 mV / degree centigrade //(500 mV offset) to make //negative temperatures an option void setup() { Serial.begin(9600);
temperature = (temperature - .5) * 100;//converting from 10 mv //per degree wit 500 mV offset to //degrees ((volatge - 500mV) times 100) Serial.println(temperature); //printing the result delay(1000); //waiting a second } /* * getVoltage() - returns the voltage on the analog input * defined by pin */ float getVoltage(int pin){ return (analogRead(pin) * .004882814);//converting from a 0 //to 1024 digital range // to 0 to 5 volts //(each 1 reading equals ~ 5 millivolts }
//Start the serial connection //with the computer //to view the result open the //serial monitor //last button beneath the file //bar (looks like a box with an //antenna)
NOT WORKING?
(3 things to try)
Nothing Seems to Happen This program has no outward indication it is working. To see the results you must open the Arduino IDE's serial monitor. (instructions on previous page)
Gibberish is Displayed
This happens because the serial monitor is receiving data at a different speed than expected. To fix this, click the pull-down box that reads "*** baud" and change it to "9600 baud".
MAKING IT BETTER
Outputting voltage: This is a simple matter of changing one line. Our sensor outputs 10mv per degree centigrade so to get voltage we simply display the result of getVoltage().
delete the line temperature = (temperature - .5) * 100;
The change to the first line means when we next output it will appear on the same line, then we add the informative text and a new line. Changing the serial speed: If you ever wish to output a lot of data over the serial line time is of the essence. We are currently transmitting at 9600 baud but much faster speeds are possible. To change this change the line:
Serial.begin(9600); ----> Serial.begin(115200);
Outputting degrees Fahrenheit: Again this is a simple change requiring only math. To go degrees C ----> degrees F we use the formula: ( F = C * 1.8) + 32 ) add the line
temperature = (((temperature - .5) * 100)*1.8) + 32; before Serial.println(temperature);
Upload the sketch turn on the serial monitor, then change More informative output: Let's add a message to the serial output to make what is appearing in the Serial Monitor more informative. To the speed from 9600 baud to 115200 baud in the pull down menu. You are now transmitting data 12 times faster.
http://ardx.org/CIRC10
27
CIRC-11
WHAT WERE DOING:
This next circuit is a bit of a test. We combine what we learned about using transistors in CIRC03 to control a relay. A relay is an electrically controlled mechanical switch. Inside the little plastic box is an electromagnet that, when energized, causes a switch to trip (often with a very satisfying clicking sound). You can buy relays that vary in size from a quarter of the size of the one in this kit up to as big as a fridge, each capable of switching a certain amount of current. They are immensely fun because there is an element of the physical to them. While all the silicon we've played with to this point is fun sometimes, you may just want to wire up a hundred switches to control something magnificent. Relays give you the ability to dream it up then control it with your Arduino. Now to using today's technology to control the past. (The 1N4001 diode is acting as a flyback diode, for details on why it's there visit: http://ardx.org/4001)
THE CIRCUIT:
Parts:
CIRC-11 Breadboard Sheet x1 10k Ohm Resistor Brown-Black-Orange x1 2 Pin Header x4 Diode (1N4001) x1 Transistor P2N2222AG (TO92) x1 Yellow LED x1 Relay (SPDT) x1 Red LED x1
Schematic
Arduino pin 2 resistor (10kohm)
Transistor
Base P2N2222AG Collector
com
Emitter
Diode
(flyback)
coil
28
NO
The Internet
NC
+5 volts gnd
(ground) (-)
CODE (no need to type everything in just click) File > Examples > 1.Basic > Blink
(example from the great arduino.cc site, check it out for other great ideas)
/* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We use pin 13 because, * depending on your Arduino board, it has either a built-in LED * or a built-in resistor so that you need only an LED. * * http://www.arduino.cc/en/Tutorial/Blink */ int ledPin = 2; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); } // ***********
CIRC-11
// run once, when the sketch starts // sets the digital pin as output // run over and over again // // // // sets the LED on waits for a second sets the LED off waits for a second
NOT WORKING?
(3 things to try)
Nothing Happens
The example code uses pin 13 and we have the relay connected to pin 2. Make sure you made this change in the code.
The included relays are designed to be soldered rather than used in a breadboard. As such you may need to press it in to ensure it works (and it may pop out occasionally).
MAKING IT BETTER
Watch the Back-EMF Pulse Replace the diode with an LED. Youll see it blink each time it snubs the coil voltage spike when it turns off. Controlling a Motor In CIRC-03 we controlled a motor using a transistor. However if you want to control a larger motor a relay is a good option. To do this simply remove the red LED, and connect the motor in its place (remember to bypass the 330 Ohm resistor).
http://ardx.org/CIRC11
29
CIRC-12
WHAT WERE DOING:
When you first started with CIRC01 you were happy just to get a red LED blinking away. But you're past that now, right? You want orange, you want teal, you want aubergine! Fortunately there's a way to shine multiple colors from a single LED without having to stock up on every shade of the rainbow. To do this we use a RGB LED. An RGB LED isn't a single LED it's actually three LEDs in one small package: one Red, one Green and one Blue. When you turn them on their light mixes together and you get other colors. The color you get is a result of the intensity of the individual red, green and blue LEDs. We control the intensity with Pulse Width Modulation (PWM) which we've used before to control LED brightness and motor speed.
THE CIRCUIT:
Parts:
CIRC-12 Breadboard Sheet x1 330 Ohm Resistor Orange-Orange-Brown x3 2 Pin Header x4 5mm RGB LED x1 Wire
Schematic
Arduino
pin 11 pin 10 pin 9
resistor
(330ohm)
green
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS12
blue
longest lead
red
flat side
gnd
30
CODE
CIRC-12
// Cycle color from green through to blue for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5) { greenIntensity = 255-blueIntensity; analogWrite(BLUE_LED_PIN, blueIntensity); analogWrite(GREEN_LED_PIN, greenIntensity); delay(DISPLAY_TIME); } // Cycle cycle from blue through to red for (redIntensity = 0; redIntensity <= 255; redIntensity+=5) {
blueIntensity = 255-redIntensity; analogWrite(RED_LED_PIN, redIntensity); analogWrite(BLUE_LED_PIN, blueIntensity); delay(DISPLAY_TIME); } } ---------- More Code Online ----------
NOT WORKING?
(3 things to try)
Seeing Red
The red diode within the RGB LED may be a bit brighter than the other two. To make your colors more balanced, use a higher ohm resistor. Or adjust in code. analogWrite(RED_LED_PIN, redIntensity); to analogWrite(RED_LED_PIN, redIntensity/3);
MAKING IT BETTER
Using HTML-style color codes If you're familiar with making web pages you might prefer to specify colors using "hex triplets" like you do when you use HTML and CSS. A hex triplet specifies a color using a series of letters and numbers like `#FF0000` for red or `#800080` for purple. You can learn more about how this works on Wikipedia (http://ardx.org/HEXCOL) and find a list of colors with their associated hex triplets so you don't need to work it out yourself. Download the code from: http://ardx.org/RGBMB A land of diffusion One disadvantage of using a RGB LED made up of three separate LEDs to generate our colors is that sometimes it's possible to see the color of the individual lights. One way to workaround this is to find a way to make the light more diffuse (or scattered) so that the individual colors mix together better. The LED supplied with your kit is diffused rather than clear to help improve the effectiveness of the color mixing. If the light still isn't diffuse enough you can try putting the LED behind some paper or acrylic; or inside a ping pong ball or polystyrene ball.
http://sparkfun.com/RGB
31
CIRC-13
WHAT WERE DOING: In life it's important to be flexible. But what do you do
if you want to measure how flexible an object is? You use a flex sensor. A flex sensor uses carbon on a strip of plastic to act like a variable resistor or potentiometer (CIRC-08) but instead of changing the resistance by turning a knob you change it by flexing (bending) the component. We use a "voltage divider" again (CIRC-08 & 09) to detect this change in resistance. The sensor bends in one direction and the more it bends the higher the resistance gets--it has a range from about 10K ohm to 35K ohm. In this circuit we will use the amount of bend of the flex sensor to control the position of a servo.
THE CIRCUIT:
Parts:
CIRC-13 Breadboard Sheet x1 2 Pin Header x4 3 Pin Header x1 Flex Sensor x1 10k Ohm Resistor Brown-Black-Orange x1 Wire
Mini Servo x1
Schematic
+5 volts
pin 9
Mini Servo
signal (white)
flex sensor
analog pin 0
resistor
(10k ohm)
gnd
(ground) (-)
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS13S
32
CODE
CIRC-13
void loop() { val = analogRead(potpin);// reads the value // of the potentiometer //(value between 0 and 1023) Serial.println(val); val = map(val, 50, 300, 0, 179); #include <Servo.h> // scale it to use it with the servo // (value between 0 and 180) Servo myservo; // create servo object to myservo.write(val); // sets the servo // control a servo // according to the // scaled value int potpin = 0; // analog pin used to // connect the delay(15); // waits for the servo // potentiometer // to get there int val; // variable to read the } //value from the analog pin void setup() { Serial.begin(9600); myservo.attach(9);// attaches the servo // servo on pin 9 to the servo object
NOT WORKING?
(3 things to try)
MAKING IT BETTER
Calibrating the Range While the servo is now moving chances are its range isnt quite perfect. To adjust the range we need to change the values in the map() function. map(value, fromLow, fromHigh, toLow, toHigh) For full details on how it works: http://ardx.org/MAP To calibrate our sensor we can use the debug window (like in CIRC-11). Open the debug window then replace the fromLow value (default 50) with the value displayed when the sensor is un bent. Then replace the fromHigh (default 300) value with the fully bent value. Applications With sensors the real fun comes in using them in neat and un-expected ways here are a few of our favorite flex sensor applications. One Player Rock Paper Scissors Glove A glove that lets you play RPS against yourself. http://ardx.org/RPS Electronic Plant Brace Monitor if your plant is bending towards light and fix it. http://ardg.org/BRACE
http://sparkfun.com/
33
CIRC-14
.:Fancy Sensing:.
.:Soft Potentiometer:.
WHAT WERE DOING: A "soft pot" (short for "soft potentiometer") is like a
regular potentiometer of the style seen in CIRC-08 except, it's flat, really thin, flexible and doesn't have a knob. A potentiometer is also known as a "variable resistor" and for a soft pot the resistance it provides is determined by where pressure is applied. Pressure can be applied with your finger, a stylus or a hard plastic "wiper". By pressing down on various parts of the strip, the resistance varies from 100 to 10k Ohms allowing you to calculate the relative position on the strip. You can use this to track movement on the softpot or discrete "button style" presses. In this circuit well use it to control the color of an RGB LED.
THE CIRCUIT:
Parts:
CIRC-14 Breadboard Sheet x1 Soft Potentiometer x1 2 Pin Header x4 5mm RGB LED x1 Wire
Schematic
Arduino
pin 11 pin 10 pin 9
+5 volts
resistor
(330ohm)
soft-pot
green
Arduino
V+
wiper
analog pin 0
The Internet
.:download:. breadboard layout sheet http://ardx.org/BBLS14S
blue
longest lead
red
gnd
gnd
34
CODE
CIRC-14
int greenValue = constrain( map(sensorValue, 0, 512, 0, 255),0,255)constrain( map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the green value (0-255 //over 0-512 & 255-0 over 512-1023) int blueValue = constrain( map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the blue value 0-255 over //512-1023 // Display the requested color analogWrite(RED_LED_PIN, redValue); analogWrite(GREEN_LED_PIN, greenValue); analogWrite(BLUE_LED_PIN, blueValue); }
void setup() { //no need for any code here } void loop() { int sensorValue = analogRead(0); //read the Soft Pot int redValue = constrain( map(sensorValue, 0, 512, 255, 0),0,255); //calculate the red Value (255-0 //over the range 0-512)
NOT WORKING?
(3 things to try)
Seeing Red
The red diode within the RGB LED may be a bit brighter than the other two. To make your colors more balanced, use a higher ohm resistor. Or adjust in code. analogWrite(RED_LED_PIN, redValue); to analogWrite(RED_LED_PIN, redValue/3);
Bizarre Results
The most likely cause of this is if youre pressing the potentiometer in more than one position. This is normal and can actually be used to create some neat results.
MAKING IT BETTER
HSB Color (Hue, Saturation & Brightness) Our RGB LED displays colors using RGB color codes. However this is often not the easiest way of working with colors (as noted by the less than reader friendly code above). A much more intuitive system is HSB. Full Details: http://ardx.org/HSB To convert from RGB to HSB all that is required is some slightly complicated math. For an example program visit: http://ardx.org/CODE14MB based on www.kasperkamperman.com's original code: http://ardx.org/KASP Now when you use the soft pot youll notice a much cleaner and fuller fade from red through to violet. Faux Buttons Because of the way the soft pot works it can also be used to make custom buttons. To do this you define a range of values corresponding to a discrete button. Use the code snippet below and the debug window to determine desired values. if(analogRead(0) > minValue && analogRead(0) < maxValue){ buttonAction() } Then cover the soft pot with a drawn/printed button pattern
http://sparkfun.com/
35
NOTE
notes
36
NOTE
notes
37
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License To view a copy of this license visit http://creativecommons.org/licenses/by-sa/3.0/ Or send a letter to: Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.