Introduction: Arduino Workshop-Interactive LED Chase Effect

Arduino Workshop-LED Chase Effect We are going to add a potentiometer to this circuit which will allow you to change the speed of the lights while the code is running

Required Component


2. 5mm LED

3. 4.7KΩ Rotary Potentiometer

This book will help you to gain more knowledge about Arduino

Beginning Arduino

Circuit diagram Arduino Interactive LED Chase Effect

First, make sure your Arduino is powered off by unplugging it from the USB cable. Now add a potentiometer to the circuit so it is connected as in Figure Interactive LED Chase Effect with the left leg going to the 5V on the Arduino, the middle leg going to Analog Pin 2, and the right leg going to ground.

How Work potentiometer:

The potentiometer is simply a fixed resistor with an adjustable wiper that can be used to divide the total resistance into two parts that add up to the total (fixed) value.

[caption id="attachment_414" align="alignnone" width="200"] potentiometer[/caption]

The potentiometer has three legs. By connecting up just two legs, the potentiometer becomes a variable resistor. By connecting all three legs and applying a voltage across it, the potentiometer becomes a voltage divider. This is how we have used it in our circuit. One side is connected to the ground, the other to 5V, and the center pin to our analog pin. By adjusting the knob, a voltage between 0 and 5V will be available from the center pin; we can read the value of that voltage on Analog Pin 2 and use its value to change the delay rate of the light effect. The potentiometer can be very useful in providing a means of adjusting a value from 0 to a set the amount, e.g., the volume of a radio or the brightness of a lamp.

Code Arduino Interactive LED Chase Effect

byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Create
array for LED pins
int ledDelay; // delay
between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
int potPin = 2; // select
the input pin for the potentiometer
void setup() {
for (int x=0; x<10; x++) { // set all
pins to output
pinMode(ledPin[x], OUTPUT);
changeTime = millis();
void loop() {
ledDelay = analogRead(potPin); // read the
value from the pot
if ((millis() - changeTime) > ledDelay) { // if it has
been ledDelay ms since last change
changeTime = millis();
void changeLED() {
for (int x=0; x<10; x++) { // turn off
all LED's
digitalWrite(ledPin[x], LOW);
digitalWrite(ledPin[currentLED], HIGH); // turn on the
current LED
currentLED += direction; // increment
by the direction value
// change direction
if we reach the end
if (currentLED == 9) {direction = -1;}
if (currentLED == 0) {direction = 1;}

This time when you verify and upload your code, you should now see the lit LED appear to bounce back and forth between each end of the string of lights as before. But, by turning the knob of the potentiometer, you will change the value of delay and speed up or slow down the effect. Let’s take a look at how this works and find out what a potentiometer is.