Serial to Parallel Shifting-Out with a 74HC595

Share on facebook
Share on twitter
Share on linkedin

Using the 74HC595 to control 8 leds (outputs) without giving up 8 ports on the arduino uno. Three outputs from the arduino are used to shift the data out in serial to the 74HC595 were it is then parceled out to each of its individual pins. You can link multiple registers together to extend your output even more, without giving up any more pins on the arduino.

Note: The shift register is not what gives the appearance of the led going back and foth…ie shifting. All the shifting happens prior to the output states changing. The led appears to be shifting because it is in a loop writing the numbers 1, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, and 2.

If you are interested in seeing how fast data is shifted out by a 16MHz Arduino check out the post Syncing Oscilloscope To Interrupt Activity  post where we use an oscilloscope to observe the shiftout command in action.

Pin out for the 74HC595 along with a short tutorial by Simon Monk can be found here.

[javascript]
/*
Using the 74HC595 to control 8 leds (outputs) without giving up 8 ports on the arduino uno.
Three outputs from the arduino are used to shift the data out in serial to the 74HC595 were it
is then parceled out to each of its individual pins.

*/

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

byte leds = 0;
int pattern[] = {1, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2};

void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop()
{

for (int i = 0; i < 14; i++)
{
leds = pattern[i];
updateShiftRegister();
delay(1000);
}
}

void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
[/javascript]

David Riewe

David Riewe

Electronics Tech with over 20 years of experience in the computer industry. I enjoy building micro-controlled projects, programming and web development

Leave a Replay

Follow Me

My Latest Posts

Sign up for our Newsletter

Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit