Learn / Digital logic / Counters

Shift Registers: More Pins from Three

ReviewedIntermediate MakerAbout 6 min
ABY
In short

Shift Registers: More Pins from Three: the short answer

A shift register moves bits along a chain of flip-flops, one position per clock pulse. The 74HC595 is a serial-in, parallel-out register: you send it eight bits one at a time on a data pin, pulsing a clock pin for each bit, and then pulse a latch pin to copy all eight to its output pins at once.

Level
Intermediate
Time
About 6 min
Topic
Digital logic
You will learn to

Drive many outputs with a 74HC595 and read many inputs with a 74HC165, using only three microcontroller pins each.

Before this: Counters and Seven-Segment Displays, Digital Inputs and Outputs

A shift register moves bits along a chain of flip-flops, one position per clock pulse. The 74HC595 is a serial-in, parallel-out register: you send it eight bits one at a time on a data pin, pulsing a clock pin for each bit, and then pulse a latch pin to copy all eight to its output pins at once. The latch stops the outputs flickering while bits are shifting in. Three pins (data, clock, latch) give you eight outputs, and chaining the Q7' output of one chip into the data input of the next gives 16, 24 or more outputs on the same three pins.

The 74HC165 is the reverse: parallel-in, serial-out. Pulling its load pin low captures eight inputs (such as buttons with pull-up resistors) at once, then each clock pulse shifts one bit out to the microcontroller. In Arduino, shiftOut() and shiftIn() do the bit-banging; the SPI hardware can do it much faster.

Mind the current limits. A 74HC595 output can supply a few milliamps per pin for LEDs, but the whole chip is limited to about 70 mA through its supply pins, so eight LEDs at 20 mA each is too much. Run LEDs at 5 to 8 mA, or use the TPIC6B595 or a transistor array for heavier loads. Tie the output-enable (OE) pin low, or drive it with PWM to dim all outputs, and add a 100 nF decoupling capacitor at each chip.

Three pins can drive eight outputs

A 74HC595 takes data in serially, one bit at a time, on a data pin with a clock pin to say when to read each bit. After eight bits, a pulse on the latch pin moves all eight to the outputs at the same moment. That is why the outputs do not flicker while shifting.

Chain registers by connecting the serial output of the first to the data input of the next. The same three microcontroller pins now control 16, 24 or more outputs.

Current and output enable

The 74HC595 can drive about 6 mA per pin reliably and has a total limit for the chip, so eight LEDs at 20 mA each is too much. Use resistors that set a few milliamps, or a driver chip such as the ULN2803 for larger loads. The output-enable pin turns all outputs off at once, which is useful for dimming with PWM or for keeping outputs off during start-up.

At power-up the outputs are undefined until you clock in data. Hold the output enable high, then load a known value and enable the outputs.

Reading inputs with the 74HC165

The 74HC165 works the other way, reading eight inputs into one serial stream. Together, the two let a small board handle a keypad or a bank of switches and LEDs with only a few pins.

Common mistakes
  • Driving eight bright LEDs directly and exceeding the chip's total current.
  • Forgetting to pulse the latch, so the outputs never change.
  • Not holding outputs off at start-up, so connected loads flash.
Intermediate lesson · Maker plan

Practise this lesson with Maker

The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.

With Maker you also get: a worked example, a hands-on task, a 3-question check.

Common questions

What will I learn in "Shift Registers: More Pins from Three"?

Drive many outputs with a 74HC595 and read many inputs with a 74HC165, using only three microcontroller pins each.