Multiple Blinking LED Arduino UNO
Advertisement
In the previous blog, we learned how to connect a single LED to Arduino UNO and make it blink using the code. This time, we are going a step further and will try to make Multiple Blinking LEDs in Arduino UNO.
Let’s start and put some LEDs and Resistors to work.
Multiples Blinking LEDs Algorithm
Before starting to write the algorithm of our project first know what is an algorithm. The algorithm is a step-by-step method, which specifies a series of instructions to be executed to get the desired output in a certain order.
Algorithms are usually generated independently of the underlying languages, i.e. in more than one programming language, an algorithm may be implemented.
So, start writing the algorithm of our first project subpart. Before going onto the algorithm part you should have a clear understanding of what is an Arduino UNO and the basic parts.
- Turn on LED 1
- Wait a second.
- Switch off LED 1.
- Turn on LED 2.
- Wait a second.
- Switch off LED 2.
- Continue until LED 5 is turned on, at which point the process reverses from LED 5 to 1.
- Repeat indefinitely.
Required Components
- 5 LEDs
- 5 Resistors
- One Bread Board
- Wires
- Arduino
- USB Cables
Blinking LED Arduino Code
This is about Multiple LEDs Blinking with different delays.
void setup()
{
pinMode(13,OUTPUT);
// RED LED
pinMode(12,OUTPUT);
// WHITE LED
pinMode(11,OUTPUT);
// BLUE LED
pinMode(8,OUTPUT);
// YELLOW LED
pinMode(6,OUTPUT);
// GREEN LED
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(1000);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(6, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
In this program we have discussed many functions like delay(), digitalWrite(), pinMode(). It’s time to learn what are these functions and how they work.
delay()
is a blocking function. It is the syntax of writing for giving hold between ON and OFF or 0 and 1 signal to the Arduino.
In the above code, we have provided 1000ms to the delay() function that is equal to 1 second.
digitalWrite()
– This function helps in to write the command on the microcontroller i.e which should give LOW output or which pin should give HIGH output. digitalWrite(6, LOW); this line means pin number 6 will LOW or OFF and digitalWrite(8, HIGH); pin number 8 will HIGH or ON
pinMode() – This function helps to assign the pin number and clarify that a specific pin number is given OUTPUT or take INPUT from the sensors or the components.
Use Variables
Variables play an important role in programming. In a computer program, data is stored using variables.
You can take a look at the Single LED blinking project in Arduino UNO, where we used the delay(1000) feature to hold the LED to Turns on for 1000 milliseconds.
Multiple Blinking LED Arduino Circuit
Now let’s build the circuit. A circuit layout can be described in several ways. For this project (MULTIPLE LED BLINKING USING ARDUINO UNO), we are using a physical layout diagram similar to the one shown in below figure 1.
By comparing the wiring diagram with the sketched functions, the circuit will start making sense to you.
When we use for example DigitalWrite(13, HIGH), a 5 V high-voltage will flow from the digital pin 13 through the current-limiting resistor, the anode through the LED, and then the anode-cathode, and finally back to the GND socket in Arduino to complete the circuit.
Then by using DigitalWrite(13, LOW) the current stops and the LED turns off.
Multiple LEDs Blinking Working Explanation
Attach your Arduino now, and upload your sketch from the Arduino IDE. After a second the LEDs should start blinking.
However, if nothing happens then remove the USB cable immediately from Arduino and verify that the sketch has been typed correctly.
Fix the mistake, and upload the sketch again. If your sketch matches exactly and the LEDs still don’t blink, check your wiring on the breadboard.
If you wanted to modify this sketch to make the LEDs cycle more quickly, you would need to blink after each delay(500)
.
There is a better way if you want to see the stimulation of the project. Visit Tinker Cad for the stimulation of Multiple Blinking LEDs Using Arduino UNO.
delay()
is a blocking function. It is the syntax of writing for giving hold between ON and OFF or 0 and 1 signal to the Arduino.
In the above code, we have provided 1000ms to the delay() function that is equal to 1 second.
It’s a very simple technique, you have to change the value which presents in the delay() function.
For example delay(1000), delay(500).
lED BLINKING//initialize variables (for pin)
int ledPin = 11;
void setup()
{
pinMode(ledPin, OUTPUT);
//set the pin mode to output}
void loop()
{
digitalWrite(ledPin, HIGH);
// send a HIGH(ON) signal to led Pin which is pin 11delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
https://hackthedeveloper.com/led-blinking-arduino-uno/
Hi There
Nice tutorials for beginners. Explained nicely
Here is a simulation, you can use if you feel it is okay, in the article. Your readers will get live experience to paly with your Arduino Project
https://wokwi.com/arduino/projects/321298093502890580