Interfacing LED to Arduino UNO and controlling it Using arduino code

Table of Contents
Abstract
In this article, a comprehensive step-by-step guide to interface an external LED with Arduino UNO board using arduino code. This articles lays the foundation for more advanced embedded system and IoT projects.
Pre-Request
- OS : Windows / Linux / Mac / Chrome
- Arduino IDE
Hardware Required
- Arduino UNO.
- LED.
- Resistors.
- BreadBoard.
- Mini USB Cable.
- Connecting wires.
- 5V DC power supply (Optional)
| Components | Purchase Link |
|---|---|
| Arduino UNO | link |
| LED | link |
| BreadBoard | large : small |
| Connecting Wires | link |
| Mini USB Cable | link |
| 5V DC Adaptor | link |
Don't own a hardware
No worries,
Still you can learn using simulation.
check out simulation part .
Connection Table
| Particular | GPIO | Remarks |
|---|---|---|
| LED 1 | 8 | LED-1 Anode to GPIO 8 : High Logic |
| LED 2 | 4 | LED-2 Cathode to GPIO 4 : Low Logic |
Info
- LED-1 : HIGH Logic LED : ON for GPIO set to 1 : OFF for GPIO set to 0
- LED-2 : Low Logic LED : ON for GPIO set to 0 : OFF for GPIO set to 1
- Best practice is to connect LED in low logic.

fig-Connection Diagram
Code
Code Explanation
Accessing LED's.
- Define LED_1 to GPIO 8 & LED_2 to GPIO 4.
- GPIO pin 8 is configured as
OUTPUTpin (Line number 6) - GPIO pin 4 is configured as
OUTPUTpin (Line number 7)
Controlling LED
- Continuous loop for blinking led is achieved using
loopmethod. digitalWrite(LED_1, HIGH)sets the value of GPIO 8 toHIGHor1, it turns ON the LED-1. (line number 13)digitalWrite(LED_2, LOW)sets the value of GPIO 4 toLOWor0, it turns ON the LED-2. (line number 14)- Delay is achieved through
delay(ms_value);method. (line number 15 & 20) digitalWrite(LED_1, LOW)sets the value of GPIO 8 toLOWor0, it turns OFF the LED-1. (line number 18)digitalWrite(LED_2, HIGH)sets the value of GPIO 4 toHIGHor1, it turns OFF the LED-2. (line number 19)
Try It
- Change the value in the
delaymethod and observe the change in the on and off time.delay(2000),delay(750), etc
Simulation
Not able to view the simulation
- Desktop or Laptop : Reload this page ( Ctrl+R )
- Mobile : Use Landscape Mode and reload the page
Extras
Components details
- Arduino UNO Data Sheet
Modules / Libraries Used
NIL