Multiple Blinking LED Arduino UNO Read it later

5/5 - (1 vote)

If you’re new to the world of electronics and programming, the Arduino UNO is an excellent place to start. The Arduino is an open-source platform that is widely used by hobbyists, makers, and professionals alike. With the Arduino UNO, you can create a wide range of projects, from simple LED blinkers to complex robots. In this article, we’ll focus on creating a multiple blinking LED project using an Arduino UNO. We’ll discuss the hardware and software components you’ll need, as well as step-by-step instructions on how to get started.

Hardware Requirements

Here is a list of the hardware components you’ll need to create a multiple blinking LED project using an Arduino UNO:

  • Arduino UNO board
  • Breadboard
  • Multiple LEDs (preferably of different colors)
  • Jumper wires
  • 220-ohm resistors
  • USB cable – To connect the Arduino UNO to your computer.

Software Requirements

You’ll also need some software to program your Arduino UNO. Here are the software components you’ll need:

Getting Started

Before we dive into the code, let’s first connect our hardware components to the Arduino UNO board. Here are the steps you need to follow:

  1. Connect the Arduino UNO board to your computer using a USB cable.
  2. Connect the breadboard to the Arduino UNO board – Place the breadboard on top of the Arduino UNO board, ensuring that the pins on the breadboard align with the pins on the Arduino UNO board.
  3. Connect the LEDs to the breadboard – Insert the LEDs into the breadboard, making sure to connect the longer leg of each LED to the positive (+) rail on the breadboard and the shorter leg to the negative (-) rail on the breadboard.
  4. Connect the resistors to the breadboard – Insert one end of each resistor into the same row as the LED’s positive leg on the breadboard, and the other end into a different row.
  5. Connect the jumper wires to the breadboard – To connect the jumper wires to the breadboard, you should connect one end of each jumper wire to the row where the LED’s negative leg is connected and connect the other end to a ground pin on the Arduino UNO board.

Multiples Blinking LEDs Algorithm

A step-by-step method, known as an algorithm, specifies a series of instructions that someone executes in a certain order to obtain the desired output.

An algorithm may be implemented in more than one programming language, independent of the underlying languages.

So, start writing the algorithm of our first project subpartBefore 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.

Multiple Blinking LED: Arduino Code

Now that we have our hardware components connected, it’s time to write the code. Open the Arduino IDE and follow these steps:

Step 1: Define the pins

To do this, add the following code to the beginning of your sketch:

int ledPin1 = 13;
int ledPin2 = 12;
int ledPin4 = 11;
int ledPin5 = 8;
int ledPin6 = 6;

Step 2: Setup Output Pins

Add the following code to the setup() function:

void setup()
{

   // RED LED
   pinMode(ledPin1,OUTPUT);
 
   // WHITE LED
   pinMode(ledPin2,OUTPUT);
 
   // BLUE LED
   pinMode(ledPin3,OUTPUT);
 
   // YELLOW LED
   pinMode(ledPin4,OUTPUT);
  
   // GREEN LED
   pinMode(ledPin5,OUTPUT);
  
}

Step 3: Create LED on/off loop in Arduino Code

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 assigns the pin number and clarifies whether to set a specific pin number as OUTPUT or INPUT for sensors or components.

Step 4: Upload the sketch to the Arduino UNO board

Click the “Upload” button in the Arduino IDE.

Once the upload is complete, you’ll see the LEDs blinking on and off in a sequence. We use the delay function to determine the duration for which the LED should remain on or off. In this case, the LED is on for 1000 milliseconds, or a second, and then off for 1000 milliseconds.

Multiple Blinking LED Arduino Code using Scheduler

In the previous section, we discussed how to create a multiple blinking LED Arduino Uno project using the simple digitalWrite() function. However, this approach can become complicated when we want to add more LEDs to the project or perform other tasks simultaneously. In such cases, using the Arduino Scheduler library can make our code more efficient and organized.

The Arduino Scheduler library allows us to create multiple tasks that can run simultaneously on the Arduino Uno board. Each task can be assigned a priority level, and the library will ensure that the tasks are executed in the correct order.

Here is an example code for the multiple blinking LED Arduino Uno project using the Scheduler library:

#include <Scheduler.h>

int ledPin1 = 2;
int ledPin2 = 3;

void led1_on() {
  digitalWrite(ledPin1, HIGH);
}

void led2_on() {
  digitalWrite(ledPin2, HIGH);
}

void led1_off() {
  digitalWrite(ledPin1, LOW);
}

void led2_off() {
  digitalWrite(ledPin2, LOW);
}

void setup() {
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  Scheduler.startLoop(loop);
  Scheduler.addTask(led1_on, 0, 500);
  Scheduler.addTask(led2_on, 1, 500);
  Scheduler.addTask(led1_off, 2, 1000);
  Scheduler.addTask(led2_off, 3, 1000);
}

void loop() {
  Scheduler.execute();
}

In this example code, we have included the Scheduler library using the #include directive. We have defined four functions: led1_on(), led2_on(), led1_off(), and led2_off(). Each function corresponds to a specific LED and turns it on or off.

In the setup() function, we have used the pinMode() function to set the pins connected to the LEDs as outputs. We have also started the loop using the Scheduler.startLoop() function and added four tasks using the Scheduler.addTask() function.

The first parameter of the Scheduler.addTask() function is the name of the function to be executed. Second parameter is the priority level of the task, with lower numbers indicating higher priority. The third parameter specifies the interval at which to execute the task, in milliseconds.

In the loop() function, we have used the Scheduler.execute() function to execute the tasks in the correct order and at the specified intervals.

Using the Scheduler library can make our multiple blinking LED Arduino Uno project more efficient and flexible. It allows us to add more LEDs or perform other tasks simultaneously without cluttering our code.

Customize Your Arduino UNO Project

You can customize your multiple blinking LED project in a number of ways. Here are a few ideas:

  1. Change the delay time – Experiment with different delay times to see how it affects the LED blink rate.
  2. Change the LED colors – Use LEDs of different colors to create a more visually interesting project.
  3. Add more LEDs – Increase the number of LEDs to create a more complex pattern.
  4. Use a potentiometer to control the blink rate – Add a potentiometer to your circuit to allow you to adjust the blink rate in real-time.
  5. Use a photoresistor to control the blink rate – Add a photoresistor to the circuit and use it to control the blink rate based on the ambient light level.

Was This Article Helpful?

2 Comments

Leave a Reply

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