Hello all! In this walkthrough, I'm going to show you the basics of the Arduino and how to blink an LED. I know this has been done many times, but since I'm hoping to create a series of tutorials, this is where I'm going to start.
Step One: Purchase your Arduino.
There are many outlets where you can buy an Arduino. Some include Sparkfun, Solarbotics, Maker's Shed, and many others. If you are a total beginner to electronics and microcontrollers, I highly recommend the basic version (as of this writing, the Deumilanove). It comes at a pretty reasonable price (actually very cheap, if you remember things like the BASIC Stamp). The Deumilanove is a very flexible chip, and comes with plenty of pins for the beginner to be satisfied with. You could buy just the Arduino, but I highly recommend the project pack from Make because you get goodies like jumper wires, potentiometers, and switches.
Step Two: Set it up
What you will need to use your Arduino are a USB cable (the type you would use to plug into a printer, it has a big head) and the software.
Download the software from http://arduino.cc/ and set it up. It should come with drivers too.
Restart for the drivers to take effect, then plug your Arduino in to the computer. You should see a little green light turn on.
Launch the software. You will be presented with a simple IDE. Read on to step 3...
Step 3: Get going!
Alright, so we're getting there. Now we're going to blink an LED! First, we're going to blink the Arduino's built in LED.
Simply paste in this code, then hit the Upload button. If it doesnt upload, check around in the board and port menus and make sure that Deumilanove and the correct serial port is checked. If you don't know which port is your Arduino (and the software doesn't automatically find it), just try all of them. Also, note that the little LED has a resistor wired to it, something you should have on all your LEDs so they aren't damaged.
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(250);
digitalWrite(13, LOW);
delay(250);
}
That's it! Now lets break it down so you understand it better.
void setup(){ }
Each segment of code between from the "void" to the last } is called a "function". The setup() function runs once when the Arduino starts up. We don't have anything that we need here, so the function is empty.
void loop(){ }
The loop() function runs over and over again, which is fairly self-explanatory.
digitalWrite(13, HIGH);
Now lets look more closely at the code. The digitalWrite() command basically tells the Arduino to turn something on or off. The first number in the command, in this case 13 (the LED on the board is wired to pin 13), is the number of the pin that the target component is connected to. The second part of the command, in our case either "HIGH" or "LOW" tells the Arduino to either turn that pin on (HIGH) or off (LOW). It's pretty simple.
delay(250);
And finally, lets look at delay(). This command tells the Arduino to halt the entire program for a given amount of time, which is specified in milliseconds in the parentheses. If you wanted the code to stop for a quarter of a second, you'd write "delay(250)", which we did. By delaying the code, we keep the LED on or off for a certain amount of time.
;
Another thing you might notice is the semicolons at the end of each line. This will be especially unusual if you came from a language such as BASIC. All they do is tell the controller that the end of the line is reached, and to move on to the next one. Notice that you'd only put these semicolons at the end of a line that is not the start or end of a function, so you'd never have something like "void setup() { ; "
Alright, so that's it! If you have everything perfect, the little yellow LED (labelled L, I beleive) should blink on and off. Congratulations, your Arduino just said "Hello World"!
"But wait", you say. "How do I connect an external component like an LED to the Arduino?"
Here's how you do it. Take any ordinary LED and stick the shorter (negative) pin into GND (Ground, negative, its all the same here) and take the longer (positive) pin, connect it to a resistor, then stick the resistor in pin 13. Upload, and there you have it!
Thanks for reading and trying this out. Feedback would be greatly appreciated! I realize there may be mistakes, please don't be afraid to point them out so I can fix them.