Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation.
Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)
Target Amount: $2000
Amount Raised: $1960
Donations Received
Top Donor: C.C. $100
X
Created on: 31 July 2012
In this tutorial, you will first load a program to the Arduino Uno board that will flash the on-board LED on and off. You will then connect an external LED to the Arduino using a breadboard and load a new program to flash the external LED on and off.
You will learn:
This video shows what you will achieve:
Can't see the video? View on YouTube →
First complete tutorial 1 before attempting this tutorial. Although not essential, it is also recommended to complete tutorial 2.
Qty | Part | Designator | Notes | Type |
---|---|---|---|---|
1 | 470 ohm resistor (yellow - violet - brown) | R1 | 1/4W, 5% or better | Resistors |
1 | 5mm red LED | D1 | Other coloured and sized LEDs could also be used, e.g. 3mm green LED | Semiconductors |
You will also need:
Parts Needed for this Tutorial
You basically just need to download and install the Arduino IDE software as described below, but rather refer to the step-by-step installation instructions on the Getting Started with Arduino web page - click the Windows, Mac or Linux link on this page.
Windows: Download the latest version of the Arduino IDE from the Download the Arduino Software web page (click the Windows link). Unzip the downloaded file and extract the contents to a folder in a convenient location – e.g. to your desktop. Install the drivers as described on the Windows getting started page. To run the Arduino IDE, open the folder and double-click the arduino icon.
Ubuntu Linux: Install the Arduino IDE from the Ubuntu Software Center. For other Linux distributions and information on installing the latest version, see the Linux link on the Getting Started with Arduino web page. If you have installed an older version of the IDE from the Ubuntu Software Center, then all of the dependencies will be installed. To use the newest version of the IDE, download the Linux edition from the Download the Arduino Software web page. Unzip the downloaded file and extract the contents to a folder on your desktop or home folder. To run the IDE, open the folder and double-click the arduino icon. Click the "Run" button in the dialog box that pops up.
We will initially program the Arduino board with a program that is built into the Arduino IDE. This program will flash the on-board LED on and off.
Plug in the Arduino Uno board and open the program to load as follows:
Arduino IDE with the Blink Program Open
Load the program into the Arduino:
The Upload Button
Amazon.com
Amazon.co.uk
We will now interface an external LED to the Arduino board.
The circuit diagram below tells us to connect the anode of the LED to pin 2 of the Arduino board. Pin 2 is marked on the silk-screen of the board. The LED cathode connects to a resistor and the other lead of the resistor connects to one of the GND pins of the Arduino (the Arduino Uno has three pins marked as GND, use any one of them).
Connecting a Single LED to the Arduino
Bend the longer lead of the LED out and down and then plug the LED into the breadboard.
Plug the 470 ohm resistor into the breadboard so that one of its leads connects to the cathode (shorter lead) of the LED. Connect the other lead of the resistor to one of the GND pins of the Arduino board using a long wire link.
Connect the anode (longer lead) of the LED to pin 2 of the Arduino using a long wire link.
Your circuit should now look something like this:
LED Connected to the Arduino on Breadboard
The new program is an adaptation of the previous program. It has been modified to flash an LED on and off that is connected to pin 2 of the Arduino.
Start the Arduino IDE and either type the following program (from the screen-capture below) into the IDE and save it, or select the code below and then copy it and paste it into the IDE.
The LED2_blink Program
void setup() { // set pin 2 as an output pinMode(2, OUTPUT); } void loop() { digitalWrite(2, HIGH); // switch LED on delay(1000); // keep LED on for 1s digitalWrite(2, LOW); // switch LED off delay(1000); // keeep LED off for 1s }
The LED2_blink Program: Copy this Block of Code and Paste it into the Arduino IDE
In the Arduino IDE, save the program that you typed or copied and pasted.
Click the Verify button on the top toolbar of the IDE to make sure that the program has no errors in it (the verify button is the first icon on the toolbar - the tick mark).
If the program has any errors, then make sure that you typed the program in exactly as shown. Make corrections, save and verify again.
Click the Upload button to load the program to the Arduino board.
After the upload completes, the external LED interfaced to pin 2 of the Arduino board should start to flash on and off just like the on-board LED did after loading the first program.