Simple LED light chaser

> 2 min read

In this tutorial, you will learn how to make a simple light chaser, which will consist of only 3 LEDs. What is a lightchaser? A light chaser consists of a few LEDs that can be used to create “light” animation sequences, etc.

Overview

Basically, to make the light chaser, you will have to turn on one LED at a time while the rest of the LED is off. The process/program should be like this:

  • 1st LED is ON, 2nd & 3rd LED off
  • 2nd LED is ON, 1st & 3rd LED off
  • 3rd LED is ON, 1st & 2nd LED off
  • Go back to line 1

But, how do we do this? Well, the solution will be to use a for() loop function!

A for() loop function will be used to repeat the block of code which will turn ON & OFF the LED. The variable, i, will be used in this loop to determined & keep track which LED will be turned on. At every end in the for() loop, variable i will be incremented by one, which will caused the next LED to be turned ON. As there is only 3 LEDs used in this tutorial, I will only need to repeat the loop 3 times, and hence the condition of the for() loop will be i < 3. Now you may ask, how do I actually tell the Arduino which LED to turn on and which to turn off? Well, we will use a array to store the LED pins, which will be called “ledPin[]”. We will be using the digital pins 9 ,10 , 11 for this tutorial, and this values will be stored in ledPin[].

The potentiometer will be used to determine the delay of each LED, which turning anti-clockwise will make the delay shorter. The values of the potentiometer will be mapped from a range of 0 – 1023 to a range of 10 – 500, as this will determine the delay between each LED.

 

Parts

  • Arduino Uno Board x 1
  • Green LEDs x 3
  • 330Ω Resistors x 3
  • Jumper Wires x 7
  • Potentiometer x 1
  • Breadboard

 

Demo

 

Code

The code below is slightly differrent from the one you see in the video. This code is much more optimised & shorter.

int potPin = 0; // Input pin for the potentiometer
int delayLED = 100; // default delay for led's (microseconds) 
int pValue = 0;		//To store raw value of potentiometer
int ledPin[] = {9, 10, 11}; 

void setup() { 
for(int i = 0; i<3;i++){
pinMode(ledPin[i], OUTPUT); 
}
 
Serial.begin(9600); //Monitor value of potentiometer
} 

void loop() { 
  pValue = analogRead(potPin);// read the value from potentiometer
  pValue = map(pValue, 0, 1023, 10, 500);   // Map pValue from 0-1023 to 10-500
  delayLED = pValue;             // pValue is used to pause between LEDs (in milliseconds) 
  Serial.println(pValue); 			//Print delay in Serial Monitor
  
  for(int i = 0; i<3;i++){
  digitalWrite(ledPin[i], HIGH);
  delay(delayLED);
  digitalWrite(ledPin[i], LOW);
  delay(delayLED);
  }
}

 

Going further

Want to challenge yourself? Here are some things you can try out:

  • Make a 12 LED light chaser
  • Make a fading LED light chaser (or “LED rain” light chaser)
  • Make a RGB LED light chaser

 

Reference

You may also like...