How to Program an Arduino

Arduino Software Development

One of the great strengths of the Arduino Development Environment is the programming. The Arduino IDE (Integrated Development Environment) is a great tool for writing software for the Arduino. The IDE is also used to upload the compiled software to the hardware via the USB port.

Another strength of the Arduino Environment is the great range of software libraries provided by the Arduino IDE as well as third party hardware and software developers. Of course you could also write your own software libraries but this is not recommended for beginners.

What do I need to program an Arduino

All you need is your favourite pc or laptop to run the Arduino IDE, a USB cable and of course your Arduino Uno board. We need no components for this demo as we are going to use the onboard LED in the program below. That's right the Internet needs another tutorial on how to flash an LED.

IDE Software Download

To write your program we need to download the IDE from Arduino. It is available in Windows, Mac and Linux. On the IDE website you just select the software version that suites your operating system of choice.

IDE Software Installation

The website has instructions on installing the IDE depending on the operating system you use. For Windows users you might have to install additional USB drivers to suite the Arduino board you are using. The latest authentic boards use an Atmel USB chip. The Sparkfun funboard uses the FTDI USB chip.

Hookup the Arduino Board

Just connect the Arduino board to the USB port on your PC platform of choice. As shown in the picture at the top of the page.

Start the Arduino IDE

Arduino Blank New Project

Create your first program

This program is so simple that it requires nothing the to connected to the board except the USB cable. This function of this simple bit of code is to flash the LED that is mounted on the board on and off.

Arduino Led13 Blink Project

Every Arduino Program has two functions. The first is called setup() which is where we configure the hardware on the board. In this case we are setting digital pin 13 as an output.

The next function is called loop() which is where all of the action happens. Of course with a name like loop it just runs and runs forever.

In the loop function we set the digital pin 13 high to turn on the led. We then use a delay(500) function to delay for 500ms or half a second. The digital pin is then set low which turns the led off. Once again we use a half second delay.

The whole process then loops again with half a second on and then half a second off. That's it, not much easier than that.

Verify, Compile and Upload

After we have entered the code we can click on the verify button which will check for coding errors. If you have any errors they will be displayed in the box below the edit box. If it verifies okay then it will display white text with number of byte used in the code.

The next step is to compile and upload the code to the Arduino board. This requires the board to be connected to the computer.

Arduino IDE Code Editor

Once the code is uploaded the led on the Arduino board should start flashing.

Arduino IDE Code Editor

What's next

If you want to get carried away with led excitement you can vary the delay values to flash the led at different rates. Just change the delay value, compile and upload.

We have a range of hookup guides and tutorials that include sample sketch's and libraries for a range of sensors and devices.