An all-in-one tutorial to getting started with the Arduino open-source electronics prototyping platform. This guide is meant for the beginner but should be also be useful to you if you already tinker with electronics but want to get started with the Arduino. Iāll cover:
ā breadboarding LED outputs from the Arduino
ā creating and reading digital inputs to the Arduino
ā how to program the Arduino to take the input and act on it to modify the outputs
Our demonstration project will consist of a set of three blinking LEDās that blink in sequence. Youāll control the speed of the blinks via a pushbutton controller. Iāve designed this project to be modular in nature: we can create a fairly complex effect, but Iāve wired and coded everything in a modular fashion to make it easier to follow. Of course, that means that neither the circuits nor the code are necessarily the most efficient way of doing things ā but the emphasis here is on making it clear and understandable.
Acknowledgement: Iād like to thank Lady Ada for her excellent set of tutorials on the Arduino which is where I first learned Arduino basics. I cover a lot of the same ground, but her work has a very different flavor and emphasis including a different set of circuits and programs. I recommend that you pay her tutorials a visit. You can also buy Arduino boards and an wide variety of shields and accessories for the Arduino from her company, Adafruit Industries.
Hereās how the finished project behaves:
Step 1 Testing Your Board / Getting Started
If you have already connected an Arduino to your computer and run the basic āblinkā example you can skip this step. However, if all youāve done is unbox it, hereās how to start:
1) Download the software youāll need from the makers: Software Download.
2) Install the software and connect your Arduino to your computer via a USB cable. It draws power directly from the USB port, so you donāt need to connect a power supply to it at this point.
3) If you have a newer board youāll see a resistor next to pin 13 and an LED next to that. That LED works just as if it were connected between pin 13 and the ground (GND) pin next to it. If the LED is NOT on your board, just connect an LED between 13 and GND. You donāt need to do anything else since a resistor is already built in and limits the current through the LED so you donāt put your board at risk of a short circuit. NOTE: This resistor may not be present on really old boards (I just donāt know), but I doubt you have one of those.
4) Set your board type and serial port under āToolsā in the software kit. The current version (at the time of writing) does not have an option for the newest Duemilanove boards, but choosing Diecimila works just fine.
5) Open the blink example from the software kit: Itās under File | Sketchbook | Examples | Digital. The onboard LED (or the one you added) should blink on and off after you upload the Blink āsketchā (as Arduino projects are called) to the board (File | Upload).
When you write programs for your Arduino, you will normally do much of your debugging in the software development kit by doing a Verify/Compile before uploading, but since we just uploading a pre-built test sketch I skipped that here.
Step 2 Wiring the Blinky Lights
Iāve broken the circuit down in such a way that we will be wiring up our output (the blinky lights) completely separately from our input (the pushbutton switch). Makes it easier to understand if youāre just starting out.
First, a note and word of caution. Newer Arduino boards have an LED right on the board itself or at least a resistor connected to pin 13 so that you can stick an LED right between pin 13 and ground (GND).
This is NOT true for the other pins! If you connect LEDās or other circuits on other pins you must be certain to protect your board from excessive currents or full-out short circuits. You can fry your Arduino!
Personally, I recommend that you always use a resistor when experimenting. You donāt want to accidentally short to ground, so at least connect a low value resistor to the ground pin. Better safe than sorry.
In this circuit we are using pins 11,12 and 13 as digital outputs (5V) to power the LEDās. The negative post of each LED connects across a single shared resistor and then to ground. In my circuit Iām using a 150 ohm resistor (it was just a convenient grab from my parts bin). You can use other values here ā just donāt go too extreme so that you donāt either (a) keep the LED from lighting or (b) push too much current through your Arduino.
If you run the Arduino āblinkā sketch from step one you should now notice that one of your LEDās is blinking. If not, you should check back over your wiring and components. A diagram for this very simple circuit is below.
To keep things modular, the pushbutton switch also connects to your Arduino, but itās a very separate circuit.
Note that the little pushbutton switches commonly available have four legs. The pins on each side are permanently connected to one another, so the button actually makes a single connection between the two sides. If youāre in doubt as to which posts are which, just check it with your multimeter.
In the circuit diagram youāre going to notice that we are using two resistors. Again, the exact values arenāt really important, but the relative values are. If you arenāt familiar with the concept of pull-up/pull-down resistors, please take a minute to really understand this circuit. If you donāt, you will likely get flaky results in future projects or ā worse yet ā burn out your Arduino.
When the switch is OPEN, the circuit is simply a connection from the digital input (pin 2 in our case) to ground through a couple of resistors. Since we are connected to ground the value at pin 2 is LOW (approximately zero volts). If we were connected only to the switch the value would be whatever noise the wires were picking up. Maybe it would be close enough to zero to work, but maybe not. We need that ground connection to make sure our reading is right.
When the switch is CLOSED, the 5V source is connected to ground across our 15k resistor. The 150 ohm resistor is negligible by comparison, so it has a minimal effect on the voltage our input pin is reading (5V) and the digital input is HIGH (~5V). The 150 ohm resistor keeps us from creating a short between the power source and the pin so that we donāt damage the Arduino.
Again, the exact values of these resistors are not important. Just make sure R1 is MUCH bigger than R2 and that R2 is big enough to limit the current back to the board. My values were simply plucked from my parts bin.
Clarification: The resistor is a pull-DOWN resistor because it connects the digital input to ground. A pull-UP resistor would pull the normal (no button pressed) state of the input to 5V.
For more Detail: Arduino All-in-One Getting Started Guide