Introduction
In the world of electronics, the Arduino platform has become immensely popular due to its ease of use and versatility. One of the most basic projects that you can do with an Arduino is blinking an LED. It may sound simple, but this project is a great way to learn about coding, circuitry, and using Arduino.
In this article, we will guide you through the process of blinking an LED using Arduino, step by step.
Hardware Components
To blink an LED with Arduino, you’ll need the following hardware components to get started:
Components | Value | Qty |
---|---|---|
Arduino UNO | – | 1 |
USB Cable Type A to B | – | 1 |
DC Power for Arduino | – | 1 |
LED | 5V | 1 |
Jumper Wires | – | 1 |
Blinking LED Circuit
Make connections according to the circuit diagram given below.
Wiring / Connections
Arduino | LED |
---|---|
D9 | +ve with Resistor |
GND | -ve leg of the LED |
Installing Arduino IDE
First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.
Code
Now copy the following code and upload it to Arduino IDE Software.
Project 1 – Blink the LED using digitalWrite()
In this Project, you will toggle the LED every second.
int ledPin = 9; // You can change the pin number according to your circuit
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW);
delay(1000); // Wait for 1 second
}
Project 2 – Blink the LED using millis()
Here is another method to toggle the LED. Instead of using the delay() function, you can use the millis() function to track the time.
int ledPin = 9; //You can change the pin number according to your circuit
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, (millis() / 1000) % 2);
}
Project 3 – Blink the LED using Timer Interrupts
Here is an advanced method to toggle the LED. Instead of using the functions, you will use built-in hardware timers to toggle the LED.
int ledPin = 9; //You can change the pin number according to your circuit
void setup() {
TCCR1A = 0;
TCCR1B = 0;
bitSet(TCCR1B, CS12); // 256 prescaler
bitSet(TIMSK1, TOIE1); // timer overflow interrupt
pinMode(ledPin, OUTPUT);
}
ISR(TIMER1_OVF_vect) {
digitalWrite(ledPin, !digitalRead(ledPin));
}
void loop() {
}
Project 4 – Blink the LED using Timers and Counters
int ledPin = 9; //You can change the pin number according to your circuit
void setup() {
TCCR1A = 0;
TCCR1B = 0;
bitSet(TCCR1B, CS12); // 256 prescaler
OCR1A = 62500;
bitSet(TCCR1A, COM1A0); // Toggle pin OC1A (9)
pinMode(ledPin, OUTPUT);
}
void loop() {
}
Applications
Here are some applications for blinking an LED:
- Indicate the status of a device, such as a power-on indicator
- Use as a visual alarm to alert the user of an event or situation
- Use as a warning signal to indicate a dangerous condition or situation
- Test the functionality of a circuit or component
- Use in educational settings to demonstrate basic circuit concepts
Conclusion.
Blinking an LED using Arduino may seem like a small project, but it can be the gateway to many more complex projects. By following the steps outlined in this article, you have learned how to write code, set up a circuit, and control an LED using an Arduino.