About The Project

In this project, we’re exploring how to link four LEDs to an Arduino Uno board for creating a chaser effect.

Circuit Wiring

This project involves connecting the anode pins of the four LEDs to pins 7, 8, 9, and 10 of the Arduino Uno board. Setting the voltage at these pins to HIGH illuminates the LEDs, while setting it to LOW turns them off. The program code is crafted to ensure that only one LED glows at a given time, sequentially moving to the next LED  as in a chaser operation. The speed of this chasing operation  is regulated using the delay() function.

Program Code

Copy
/*
www.matthewtechub.com
 
This code is used to built a chaser.
Speed 1000 milli seconds.
*/
// variable declaration
int ledPin1=7;
int ledPin2=8;
int ledPin3=9;
int ledPin4=10;
// the setup function runs once.
void setup() {
// initialize ledPin as an output pin.
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
}
// the loop function runs repeatedly.
void loop() {
digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin3, LOW); // turn the LED off by making the voltage LOW
digitalWrite(ledPin4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin4, LOW); // turn the LED off by making the voltage LOW
}

Code Explanation

int ledPin1=7;
int ledPin2=8;
int ledPin3=9;
int ledPin4=10;

These lines of code declare and initialize four integer variables (ledPin1, ledPin2, ledPin3, and ledPin4) to represent the pin numbers (7, 8, 9, and 10) on a microcontroller to which LEDs are connected. This setup allows the program to control these LEDs by referencing their corresponding pin numbers.

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

pinMode(ledPin4, OUTPUT);

These lines of code configure the pins (ledPin1, ledPin2, ledPin3, and ledPin4) as output pins using the pinMode function. This setup allows the microcontroller to send signals to these pins, enabling it to control the LEDs connected to them.

void loop() {

  digitalWrite(ledPin1, HIGH);  // turn the LED on (HIGH is the voltage level)

  delay(1000);                      // wait for a second

  digitalWrite(ledPin1, LOW);   // turn the LED off by making the voltage LOW

  digitalWrite(ledPin2, HIGH);  // turn the LED on (HIGH is the voltage level)

  delay(1000);                      // wait for a second

  digitalWrite(ledPin2, LOW);   // turn the LED off by making the voltage LOW

  digitalWrite(ledPin3, HIGH);  // turn the LED on (HIGH is the voltage level)

  delay(1000);                      // wait for a second

  digitalWrite(ledPin3, LOW);   // turn the LED off by making the voltage LOW

  digitalWrite(ledPin4, HIGH);  // turn the LED on (HIGH is the voltage level)

  delay(1000);                      // wait for a second

  digitalWrite(ledPin4, LOW);   // turn the LED off by making the voltage LOW

}

These lines of code is used to perform chasing operation.

Modify Yourself

  1. Change delay(1000) to delay(500) and observe the result. Do you notice that the speed of the chasing action has increased?
  2. Revise the program code to turn off all LEDs after each chasing operation is completed.
  3. Modify the code to execute the operation shown in the figure.

Leave a Reply

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

error: Content is protected !!