LED Blinking with Arduino Uno
Interfacing LEDs with Arduino UNO for Controlling Multiple LEDs
Interfacing LEDs with Arduino UNO for Controlling Multiple LEDs demonstrates how multiple Light Emitting Diodes (LEDs) can be connected to an Arduino UNO board and controlled using digital output pins.
An LED (Light Emitting Diode) is an electronic component that emits light when electric current flows through it in the forward direction.
The Arduino UNO can control multiple LEDs by providing HIGH and LOW signals through its digital GPIO pins.
In this experiment, four LEDs are connected to digital pins 3, 4, 12 and 13 of the Arduino UNO.
All four LEDs are turned ON simultaneously for 1 second and turned OFF for 500 milliseconds. This process is repeated continuously.
Arduino UNO → Digital GPIO Pins → LEDs → Light
Theory
A Light Emitting Diode (LED) is a semiconductor device that converts electrical energy into light energy.
LEDs work on the principle of electroluminescence. When a suitable forward voltage is applied across the LED, electrons and holes recombine at the semiconductor junction, releasing energy in the form of light.
An LED has two terminals:
- Anode (+): Positive terminal of the LED.
- Cathode (−): Negative terminal of the LED.
The LED glows when it is connected with the correct polarity and sufficient current flows through it.
The Arduino UNO controls LEDs using digital output signals.
- HIGH (5V): Turns the LED ON.
- LOW (0V): Turns the LED OFF.
A current-limiting resistor is connected in series with each LED to protect it from excessive current.
Digital HIGH → LED ON → Light Emission
Digital LOW → LED OFF
LED Pins
An LED has two terminals:
| Pin | Connection | Function |
|---|---|---|
| Anode (+) | Arduino digital output through a current-limiting resistor | Positive terminal |
| Cathode (−) | GND | Ground terminal |
The longer leg of the LED is generally the Anode (+), while the shorter leg is the Cathode (−).
A suitable current-limiting resistor, typically 220 ohms or 330 ohms, should be connected in series with each LED.
LED Control Using Arduino UNO
The Arduino UNO provides multiple digital GPIO pins that can be configured as OUTPUT to control external LEDs.
The pinMode() function is used to configure a GPIO pin as an output.
The digitalWrite() function is used to control the output state of the pin.
The syntax is:
pinMode(pin, OUTPUT); digitalWrite(pin, HIGH); digitalWrite(pin, LOW);
Where:
| Function / Parameter | Description |
|---|---|
| pinMode() | Configures the selected GPIO pin |
| OUTPUT | Configures the pin as a digital output |
| digitalWrite(pin, HIGH) | Sets the selected pin HIGH and turns the connected LED ON |
| digitalWrite(pin, LOW) | Sets the selected pin LOW and turns the connected LED OFF |
Applications
LEDs are commonly used in:
- Status indication systems
- Traffic signal systems
- Electronic control panels
- Decorative lighting
- Alarm and warning systems
- Digital display systems
- Home automation systems
Connections
In this experiment, four LEDs are connected to the Arduino UNO digital pins 3, 4, 12 and 13.
| LED | Anode (+) | Cathode (−) | Function |
|---|---|---|---|
| LED 1 | Digital Pin 3 through 220 ohm resistor | GND | LED control 1 |
| LED 2 | Digital Pin 4 through 220 ohm resistor | GND | LED control 2 |
| LED 3 | Digital Pin 12 through 220 ohm resistor | GND | LED control 3 |
| LED 4 | Digital Pin 13 through 220 ohm resistor | GND | LED control 4 |
Note: Each LED must have its own current-limiting resistor connected in series.
Algorithm
The following algorithm is used to control four LEDs simultaneously:
- Start the Arduino IDE.
- Connect the Arduino UNO board to the computer using a USB cable.
- Declare four variables to assign digital pin numbers 3, 4, 12 and 13.
- In the void setup() function, configure all four GPIO pins as OUTPUT.
- In the void loop() function, set all four GPIO pins to HIGH.
- All four LEDs turn ON simultaneously.
- Provide a delay of 1000 milliseconds.
- Set all four GPIO pins to LOW.
- All four LEDs turn OFF simultaneously.
- Provide a delay of 500 milliseconds.
- Repeat the process continuously.
The overall operation is:
All LEDs ON → Delay 1000 ms → All LEDs OFF → Delay 500 ms → Repeat
Working
The Arduino UNO controls four LEDs through its digital output pins.
The working sequence is:
- The Arduino UNO initializes digital pins 3, 4, 12 and 13 as OUTPUT.
- All four digital pins are set to HIGH.
- All four LEDs glow simultaneously.
- The LEDs remain ON for 1000 milliseconds (1 second).
- All four digital pins are set to LOW.
- All four LEDs turn OFF simultaneously.
- The LEDs remain OFF for 500 milliseconds.
- The process repeats continuously.
Arduino UNO → Digital Output HIGH → Four LEDs ON
Arduino UNO → Digital Output LOW → Four LEDs OFF
Observation
Arduino UNO LED Control Program
The following program is used to control four LEDs connected to digital pins 3, 4, 12 and 13 of the Arduino UNO.
#define LED_PIN 3
#define LED_PIN1 4
#define LED_PIN2 12
#define LED_PIN3 13
void setup()
{
pinMode(LED_PIN, OUTPUT);
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
}
void loop()
{
digitalWrite(LED_PIN, HIGH);
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
delay(500);
}
Program Explanation
- Four LED pins are defined using the #define preprocessor directive.
- LED_PIN is assigned to digital pin 3.
- LED_PIN1 is assigned to digital pin 4.
- LED_PIN2 is assigned to digital pin 12.
- LED_PIN3 is assigned to digital pin 13.
- The pinMode() function configures all four pins as OUTPUT.
- The digitalWrite() function sets all four pins HIGH, turning ON all LEDs simultaneously.
- The delay(1000) function keeps all LEDs ON for 1000 milliseconds.
- The digitalWrite() function then sets all four pins LOW, turning OFF all LEDs.
- The delay(500) function keeps all LEDs OFF for 500 milliseconds.
- The loop() function repeats this operation continuously.
Observation Table
| Step | Arduino Output | LED 1 (D3) | LED 2 (D4) | LED 3 (D12) | LED 4 (D13) | Duration |
|---|---|---|---|---|---|---|
| 1 | HIGH | ON | ON | ON | ON | 1000 ms |
| 2 | LOW | OFF | OFF | OFF | OFF | 500 ms |
Result
The Arduino UNO successfully interfaces with and controls four LEDs connected to digital pins 3, 4, 12 and 13.
All four LEDs turn ON simultaneously for 1000 milliseconds and turn OFF for 500 milliseconds.
Thus, multiple LEDs are successfully controlled using the digital GPIO output pins of the Arduino UNO.