Playing night rider with three 74HC595s

Playing night rider with three 74HC595s © CC0

Who isn't fascinated with shift registers and blinking LEDs? Using the 74HC595 I'll show you how to control 24 LEDs with three pins.

  • 1,868 views
  • 2 comments
  • 10 respects

Components and supplies

About this project

Back when I was going to electronics school in the 80's I built and installed a Night Rider lighting system in a friends camero using a bi-directional shift register to control the lighting effects. When I started experimenting with the Arduino and learned about how to control shift registers with the Arduino I wanted to simulate the Night Rider.

Pinout and Mode of Operation

In this project I use three shift registers to control 24 LEDs. The registers are connected together by taking serial out pin (pin 9) of the first shift register to the serial data input (pin 14) of the second register. Next you take the serial out pin (pin 9) of the second shift register to the serial data input (pin 14) of the third shift register.

The clock pin (pin 11) on all three shift registers are connected and driven by one output from the Arduino.

In this manner when you send the clock signal from the Arduino you will be causing the data to shift simultaneously in all three shift registers. Because a single call to the shiftOut() library function only shifts out one byte you will be calling it three times to update all three registers.

In my code I have a function "updateShiftRegister()" which takes care of setting the latchPin low, shifting out all 24 bits of my current led pattern, then setting the latchPin back high to update the LEDs.

This is the datasheet for the 74HC/HCT595:

Code

Night Rider CodeC/C++
/*
Using three 74HC595s to control 24 leds (outputs) on the arduino uno. 
This is an improved version by John Rogers
*/

int latchPin = 5;   // to pin 12
int clockPin = 6;	// to pin 11
int dataPin = 4;	// to pin 14

int numLights=24;
unsigned long light = 0;  // Bit pattern for entire display
byte b1 = 0;				// byte place holders for each shift register
byte b2 = 0;				// extracted from "light"
byte b3 = 0;

	

void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
 // Serial.begin(9600);
}

void loop() 
{
	for (int i = 0; i < numLights*2; i++)
	{
		int shift = i;
		if( i >= numLights )	//if i is above numlights then wee need to start
		{						// moving back to the left.
			shift = numLights*2 - i - 1;
		}
		// Extract the bytes of the light patter to be sent out
		light = (long)(1)<<shift;
		b1 = (byte)((light>>16)&0xFF);
		b2 = (byte)((light>>8)&0xFF);
		b3 = (byte)((light)&0xFF);
		updateShiftRegister();	// shift out b1, b2 and b3
		delay(30);
	}
}

void updateShiftRegister()
{
   	digitalWrite(latchPin, LOW);
   	shiftOut(dataPin, clockPin, MSBFIRST, b1);
   	shiftOut(dataPin, clockPin, MSBFIRST, b2);
   	shiftOut(dataPin, clockPin, MSBFIRST, b3);
   	digitalWrite(latchPin, HIGH);
   	
}

Comments

Similar projects you might like

Multicolor Knight Rider with RGB PL9823 LED + Arduino UNO

Project tutorial by Giovanni Gentile

  • 3,936 views
  • 0 comments
  • 10 respects

Night Light Assistant

Project showcase by Gabriele Fugazzi

  • 3,834 views
  • 9 comments
  • 21 respects

Motion Activated Night Light

Project tutorial by Haziq Afandi

  • 3,118 views
  • 0 comments
  • 4 respects

Arduino Burglar

Project showcase by paolo_cravero

  • 2,380 views
  • 2 comments
  • 6 respects

Knight Rider - KITT Scanner Featuring NeoPixels

Project in progress by Peter Gullberg

  • 6,663 views
  • 5 comments
  • 23 respects

Playing Smartphone Games with a Relay Touch Board

Project showcase by HomeMadeGarbage

  • 6,353 views
  • 6 comments
  • 11 respects
Add projectSign up / Login