LED light chaser using 74HC595 Shift Register & Potentiometer

> 2 min read

This Arduino project is similar to the other light chaser project I done, but I’ll be using a shift register & will be controlling 8 LEDs instead.

Overview

In this project, a shift register is used to control the 8 LEDs attached to the breadboard, turning on all the LEDs one after another and turning off all of it after all the LEDs are turned on. The potentiometer is used to set the time delay between each LEDs, where I constrained the range from 0 – 1023 to 10 – 500.

Checkout my my simpler version of the light chaser too! Simple LED light chaser

 

Demo

 

Parts required

  • Arduino Uno x 1
  • Potentiometer x 1
  • 74HC595 Shift Register IC x 1
  • LED x 8
  • Jumper Wires
  • 330Ω Resistors x 8

 

Code

// Pin definitions:
// The 74HC595 uses a type of serial connection called SPI
// (Serial Peripheral Interface) that requires three pins:

int potentPin = 0; // select the input pin for the potentiometer
int datapin = 2; 
int clockpin = 3;
int latchpin = 4;

// We'll also declare a global variable for the data we're
// sending to the shift register:

byte data = 0;

void setup()
{
  // Set the three SPI pins to be outputs:
  pinMode(datapin, OUTPUT);
  pinMode(clockpin, OUTPUT);  
  pinMode(latchpin, OUTPUT);
  Serial.begin(9600);
}


void loop()
{
        int index;
        int pValue;                   //Value of potentiometer
        int delayTime;            // Time (milliseconds) to pause between LEDs
  // Turn all the LEDs on:
  for(index = 0; index <= 7; index++)
  {
    shiftWrite(index, HIGH);
        readSensor();
  }
  // Turn all the LEDs off:
  for(index = 7; index >= 0; index--)
  {
    shiftWrite(index, LOW);
    readSensor();
  }
}

void readSensor(){
  
  int pValue = analogRead(potentPin);// read the value from the sensor:
    pValue = map(pValue, 0, 1023, 10, 500);
         int delayTime = pValue;            // Time (milliseconds) to pause between LEDs
  Serial.println(pValue); 
   delay(delayTime);
}


void shiftWrite(int desiredPin, boolean desiredState)

{
  bitWrite(data,desiredPin,desiredState);
  shiftOut(datapin, clockpin, MSBFIRST, data);
  digitalWrite(latchpin, HIGH);
  digitalWrite(latchpin, LOW);
}

You may also like...