Blinking LED on Arduino – The Arduino IDE

Digital media magic happens when we use hardware to create data from things that happen in the real world, use a computer to manipulate that data, and then use that data to make something else happen in the real world. For that we need an input device that turns a movement into data/numbers that we can use. And an output device that turns that data into some change in the world.

It might be argued that all art, expression and creativity are the result of a similar process. An artist perceives the world, interprets what they see and feel, then recomposes that data in anther form.

The first part of this path is called the input, the second is called the output. In this tutorial we are going to start on the output – We are going to use data to make something happen in the real world.

Put even more simply; we are going to use software to tell  hardware do something.

1) We will start by writing some software, some code, a small program on the computer.
2) We will plug our hardware Arduino into the computer using the USB cable.
3) We will compile the program into a language the Arduino can understand.
4) We will copy the compiled program to the Arduino.
5) The Arduino will run your program.

Lets start by build our hardware. In this example we are going to make a light blink on and off.

We will need:

a 220 Ohm resistor (resistor spark)
a red or green led
an Arduino
a Computer
a USB Cable.
a battery.

This Spark is an extension of a series that begins by building and LED circuit:LED Lights and Electricity and then looks at using Arduino Power: Lighting a LED with Arduino Power and requires information about Breadboards and Prototype Shields:Understanding Breadboards and Protoshields.

Arduino Control

Lets build our first software controlled machine.

For that we need to write some software and for that we need a computer with the Arduino IDE installed.

IDE stands for Integrated Development Environment – Its a piece of software in which we write code/instructions for the arduino and which then turns that readable code into machine code/instructions for the arduino to understand.

Download the IDE from here

When the software is downloaded double click on the file to install it or copy it to your applications folder.

Open the IDE and it should look like this;

Screen Shot 2016-01-07 at 4.17.49 PM

Start buy saving your file and calling it something sensible – like ‘polyBlink’ – sensible file names are file names that you’ll remember tomorrow so think about it a little. At Polygon Door you’ll probably be creating many different files and you will want to remember where you can find bits of code later.

now add the missing bits of code into your IDE;

Screen Shot 2016-01-07 at 5.46.39 PM

Once you’ve finished you can sleet the big Tick button – this checks that you haven’t made any mistakes and  creates a version of your code that can be uploaded to your arduino.

Lets have a look at what this code means. I’ve added comments to the code. A comment in coding is anything that follow two forward slashes. Anything I add to a line that after two forward slashes (//) will be ignored by the computer – its just for us humans. This allows us to use normal human speak to explain what we are doing and why.

We use them to teach you what is happening in the code we right – but you should right them so you can remember what a particular pieces of code is meant to do and why you wrote it. This will make it much easier to fix later.

Screen Shot 2016-01-07 at 5.46.06 PM

Configuring your IDE

With our Arduino plugged into the USB port we can now upload this little program. But first we need to tell the IDE where and how to send the program to the Arduino.

Select the >Tools menu and select >Board and find the >Arduino Mega option.

Screen Shot 2016-01-07 at 4.32.42 PM

Select the >Tools menu again and select > ‘Port’ and look for a port that has ‘tty’ and ‘usb’ in the name – if you are lucky it will also say ‘Arduino Mega’.

Screen Shot 2016-01-07 at 4.34.07 PM

You should only need to do this the first time you plugin in each new board – If you are having problems however check these settings.

Uploading your Code.

Now you are ready to send the code to your Arduino.
To do so select the sideways arrow button next to the tick button you used to compile your code earlier. This button compiles and copies your code to the Arduino.

If all goes well you should see a message on your IDE that says ‘done uploading’  with some information below it about your sketch.
Screen Shot 2016-01-07 at 5.29.54 PM

If something has gone wrong there will be some orange text and you’ll need help from your tutor.

Your code is now running on the Arduino but we can’t see anything happening because we haven’t connected an LED to pin 9 – the pin we used in our code.. lets do that now.

As in the image below stick the short leg  of your LED into the ground with the long leg sticking away form the Arduino.

Then place one end of the resistor in the pwm pin 9 hole. Touch the other leg of the resistor to the long leg of the LED.

You should now see a blinking light



Well done – you’ve written your first program and used it to control your own electrical circuit.

What is happening here? What is the software actually doing? What is the difference between the battery version the ‘Arduino power’ version and the final version?

Now try changing the values of the delays – see is you can find the point at which the flashing is so fast we can’t see it anymore.