Blinking LED With Arduino: A Fun And Easy Electronics Project
So here’s the situation! You are a beginner in electronics and you got your hands on the Arduino board, and you just want to Get Started with Arduino. And like any other programming language you are thinking about doing a “Hello World”-program with it. Now the question is who will do that with a physical development board like Arduino.
If you have this exact question in mind then worry not, in this tutorial your Arduino will say “Hello World” by blinking an LED with a perfect 1 second delay. And you will be the one who is going to be manipulating the code to make different patterns with your LEDs.
What is a LED? How do you get LED lights to light up?
LEDs are the miracle fruit of extreme engineering that empowers our modern day world. Without LEDs the flexible displays and the foldable phone would be nothing but daydream. Not only LEDs are used for displays, it’s also used for everyday applications like lighting up your home or neighbourhood.
It’s a fact that a LED bulb is 95% more efficient when compared to an incandescent light bulb and it’s also 80% more efficient when compared to a fluorescent light. Because LED lights convert 95% of their energy into light and only 5% is wasted as heat.
The LED is a glorified diode and it lets current flow through a single direction, so like a diode it has two pins, an anode and a cathode. To light up an LED you need to connect the cathode to the negative terminal of the supply and you need to connect the anode to the positive terminal of the supply.
To light up an LED, you need a voltage source. The 5mm RED led that is shown in the above picture has a forward voltage of 2V to 2.5V and a current is 20mA. That means to light up an LED your supply voltage should not be lower than 2V and it should not exceed 2.5V. If the voltage exceeds 2.5V the LED will burn out or get permanently damaged.
As we are blinking an LED with Arduino. Arduino has a 5V output pin. So you need to limit the current through the LED, to do so we are using a 150R resistor to limit the current to 20mA in the circuit.
Note: Do you know that different coloured LEDs have different forward voltage and current specifications and need different values of current limiting resistors to operate properly?
Why do Different Colours of LEDs Have Different Forward Voltages?
To construct different colours of LEDs engineers need different materials so the chemistry of the material gets altered so the applied voltage increases or decreases. For example, red LEDs are typically made using aluminium gallium arsenide (AlGaAs) and have a lower forward voltage than blue LEDs, which are made using indium gallium nitride (InGaN).
Different Colour LEDs and there Forward Voltages
In the table below we have shown you how the forward voltage differs depending on the LED colour and additionally you can see the series resistor value you need for 5V and 3.3V applications.
LED colour Forward Voltage 5In the table below we have shown you how the forward voltage differs depending on the LED colour and you can also see the series resistor value you need to apply for 5V and 3.3V.
LED colour | Forward Voltage(V) | Wavelength (nm) | Resistor at 5V | Resistor at 3.3V |
RED | 1.8 – 2.2V | 610-76 | 220 – 330 Ohms | 150 – 220 Ohms |
Green | 2.8 – 3.3V | 500 – 570 | 330 – 470 Ohms | 220 – 330 Ohms |
Blue | 3.0 – 3.3V | 450 – 500 | 330 – 470 Ohms | 220 – 330 Ohms |
Yellow | 2.0 – 2.2V | 570 – 590 | 220 – 330 Ohms | 150 – 220 Ohms |
Orange | 1.8 – 2.2V | 590 – 610 | 220 – 330 Ohms | 150 – 220 Ohms |
Violet | 3.0 – 3.3V | 400 – 450 | 330 – 470 Ohms | 220 – 330 Ohms |
Ultraviolet | 3.0 – 3.6V | <400 | 330 – 470 Ohms | 220 – 330 Ohms |
Infrared | 1.2 – 1.8V | >760 | 220 – 330 Ohms | 150 – 220 Ohms |
Connecting an LED to Arduino
Connecting a LED to an Arduino is pretty straight forward. And you don’t even need an LED in the first place to write your first blink program because there is already an onboard LED on the Arduino board. But for the sake of this tutorial we will connect an LED to the PIN 13 of the Arduino.
The above image shows the connection diagram for the LED blink circuit, and to build the circuit you will be needing
- An Arduino UNO Board
- A breadboard.
- Resistor 150 Ohms.
- Red LED
- Breadboard Connecting Wires.
Once you have all the components Follow the circuit diagram and hook up the components on the breadboard. Now as the hardware part is done we can hop onto the most interesting part of the project that is writing your first code for the Arduino. But before you do that you need to install the Arduino IDE.
Installing the Arduino IDE
To install the Arduino IDE you need to get the latest version of the IDE from the Arduino Website. When the download is finished proceed with the installation with the help of the following steps.
During the installation process Arduino IDE installer will ask your permission to install the Drivers. You need to allow those to install to be successful. If you dont allow the Driver your PC will not be able to recognize the Arduino board. The above images are taken from Arduino.cc you can visit their website for more information.
How to open an Arduino blink?
Once the install is finished open the Arduino app and you will be presented with the welcome welcome screen. Now go to Files > Example > Basic > Blink and you will find the blink sketch. Click on the blink app to open it.
Once you do that you will be presented with the blink sketch.
How to make Arduino blink code?
The Full Arduino is shown below. Let’s discuss how this code works.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Note: The LED_BUILTIN is the pin no 13 of the Arduino.
In the code you will find two functions: the void setup() function and the void loop() function. For any code that is running on the Arduino platform these two codes are absolutely necessary.
In the first line of code you will find the void setup() function. This function is executed once when the Arduino is powered on and the void loop function runs continuously. ]
The pins you see in the Arduin board are called General Purpose Input Output (GPIO) pins, and they can be configured as input and output. For our blink sketch we need to set the GPIO pin as output, that is why in the setup function the LED_BUILTIN was set as output.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
Next we have our void loop() function, in the void loop function we have the LED pin High and we wait for one second. That means the LED is ON.
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
Next we Set the LED pin Low and wait for another second.
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
And this process is repeated infinite time until you power off the Arduino Board.
Note: The built-in delay function of the Arduino takes the time in milliseconds. That is why we need to put in 1000 for 1 Second delay.
Commonly Asked Question about LEDs!
What is LED blinking?
It is a simple basic project created using Arduino. LED (Light Emitting Diode) is an electronic device, which emits light when the current passes through its terminals. LED’s are used in various applications. It is also used as an ON/OFF indicator in different electronic devices.
What are the applications of LED blinking?
LED blinking circuits can be used for signalling purpose (It can be used as signal for help, if you are in danger) LED blinking circuit can be used as flashing beacon. LED blinking circuit can be used as vehicle indicator when it is broke down in the middle of the road.
Do all LED lights blink?
Even though you don’t always see it, all mains-powered light sources flicker – whether incandescent, halogen, fluorescent or LED.
What is the code for LED blink in Arduino?
The Arduino Nano program code for led blinking is below.
const int ledPin = 9; void setup() { // put your setup code here, to run once: pinMode(ledPin, OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000);