Arduino Projects

Arduino External LED Code Example

Arduino External LEDs, Example:

In this example, we are going to control 2.5V and 10mA Leds. Controlling an external LED is just like controlling the onboard LED. Now, you might be thinking then why am I explaining this? Well, I want to explain how to use other IO pins, how to define and use multiple pins at the same time, and how to calculate the current limiting resistor.

The Arduino Uno and Arduino Nano both are 5V compatible controller boards. Which means 5V are available on its IO pins when turned ON. So, if you will directly connect 2.5V LEDs with the Arduino; they will burnout in a second.

So, how to control a 2.5V LED with a pin that has 5V. Well, We will have to use a current limiting resistor and for this we will have to perform some calculations. So, let’s do it.

The LED Voltage is 2.5V and the LED Current is 10mA.

Voltage on the Arduino Pin is 5V.

So using the V = IR formula, we can find the Resistor value which is 250 ohms.

Don’t select a resistor with a value less than 250 ohms. Go for a slightly bigger value this will increase the LED life span. The LED won’t heat up. I always select 330 ohm resistor it works perfectly.

Amazon Links:

Arduino Nano USB-C Type (Recommended)

Other Tools and Components:

ESP32 WiFi + Bluetooth Module (Recommended)

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Led Interfacing with Arduino:

Arduino course

Connect the Cathode legs of the LEDs together and then connect it to the GND pin on the Arduino board. Connect the Anode legs of the LEDs to the digital Pins 2 and 3 on the Arduino through these 330ohms current limiting resistors. Now, let’s go ahead and take a look at the programming.

Arduino External Led Programming:

This program is quite similar to the program used in example number1. The only difference is that this time I am using two LEDs connected to digital pins 2 and 3. Since, I am using the same color LEDs so I named them led1 and led2. And if I was using different color LEDs; for example Red and Green, then I could also call these LEDs as R_led and G_led. Anyway, the pins are defined.

In the void setup() function, I have set both the Pins as output, and in the void loop() function I am simply turning ON and turn OFF these LEDs. Let’s verify the code to check for any errors… You can see there are no errors and now we can upload the program.

For this go to the Tools Menu…then to board and select the Arduino Uno. Again go to the Tools menu and this time select the port, and finally, click on the Upload button. The two Leds will start blinking. For the step by step explanation and practical demonstration watch the video tutorial given at the end of this article.

Arduino course

video tutorial


Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button