Skip to main content

7.5 Shift Register Binary Counter

placeholder
Shift Register Binary Counter project demonstration

The goal of this project is to demonstrate how to expand digital outputs using a 74HC595 shift register.
With just three pins from the NULA MINI, we can control multiple LEDs — an essential concept when working with limited I/O pins.

This example creates a 4-bit binary counter, displaying values from 0 to 15 across four LEDs connected to the shift register.
It teaches how to send serial data to the register, latch it, and visualize binary counting in real time.

In this documentation you will learn:

  • How a 74HC595 shift register works and connects to the NULA MINI
  • How to use the shiftOut() function to send serial data
  • How to control multiple LEDs using only three output pins
  • How to visualize binary numbers using LEDs

Hardware required

  • 1× Soldered NULA MINI board
  • 1× 74HC595 shift register
  • 4× LEDs
  • 4× 330 ohm resistors
  • Breadboard
  • Jumper wires
  • USB-C cable
placeholder
All components required for Shift Register Binary Counter project

How it works

The 74HC595 is an 8-bit serial-in, parallel-out shift register.
It allows you to send 8 bits of data one at a time through a single data pin.
When all bits are loaded, you latch the output — updating all LEDs at once.

In this project, the NULA MINI sends 4-bit values (0–15) representing a binary counter.
Each LED corresponds to one bit of that number:

DecimalBinaryLED pattern (Q3 Q2 Q1 Q0)
00000All OFF
10001Rightmost LED ON
70111Three right LEDs ON
151111All ON
placeholder
Concept: sending binary data to LEDs through 74HC595 shift register

Wiring and connections

74HC595 PinFunctionNULA MINI PinDescription
DS (Pin 14)Serial Data InputIO2Data sent from NULA MINI
SH_CP (Pin 11)ClockIO4Shifts each bit into the register
ST_CP (Pin 12)LatchIO3Updates LED outputs
Q0–Q3 (Pins 15,1,2,3)Outputs4 LEDs (via 220 Ω resistors)Display binary value
MR (Pin 10)Master Reset5VKeeps register active
OE (Pin 13)Output EnableGNDEnables outputs
VCC (Pin 16)Power5VPower supply
GND (Pin 8)GroundGNDCommon ground
placeholder
Pinout for 74HC595 IC
placeholder
Wiring diagram for 74HC595 shift register and 4 LEDs

Full code

Below is the full example code for this project:

int latchPin = 3;  // ST_CP pin (Latch)
int clockPin = 4; // SH_CP pin (Clock)
int dataPin = 2; // DS pin (Data)

int counter = 0; // 4-bit counter (0–15)

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

void loop() {
// Limit counter to 4 bits (0–15)
byte value = counter & 0x0F;

digitalWrite(latchPin, LOW); // Prepare shift register for data
shiftOut(dataPin, clockPin, MSBFIRST, value); // Send data bits
digitalWrite(latchPin, HIGH); // Latch outputs to LEDs

counter++; // Increment counter
if (counter > 15){
counter = 0; // Wrap around to 0 after 15
}

delay(500); // Wait half a second
}

Full example

placeholder
Full Shift Register Binary Counter demonstration video

Check out the full example code on the link below:

7.5_Shift_Register_Binary_Counter.ino

Project demonstrating how to use a 74HC595 shift register to control four LEDs as a 4-bit binary counter using only three NULA MINI pins.