Built-in project · Arduino Uno R3

One-digit countdown on a 74HC595 (pins 2, 4 and 3), on an Arduino Uno

A 74HC595 with data on pin 2, clock on 4 and latch on 3 drives a common-cathode seven-segment digit, counting down from 9 to 0. The whole build, an Arduino Uno and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

One-digit countdown on a 74HC595 (pins 2, 4 and 3) · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// A seven-segment digit counting down from 9, through a 74HC595.
//
//   74HC595 DS -> pin 2    SHCP -> pin 4    STCP -> pin 3
//   74HC595 VCC and MR -> 5V      GND and OE -> GND
//   Q0 to Q6 -> segments a to g, Q7 -> the decimal point
//   the display's common cathode -> 220 ohm -> GND
//
// A seven-segment display is eight LEDs in one package: segments a to g and
// the dot. Each digit is a pattern of lit segments, one bit per segment, so
// the whole digit fits in one byte and goes out through the shift register
// with a single shiftOut().
//
// The patterns below are written with segment a in the lowest bit.

const int DATA_PIN = 2;
const int LATCH_PIN = 3;
const int CLOCK_PIN = 4;

//                   gfedcba
const byte DIGITS[10] = {
    0b00111111,  // 0
    0b00000110,  // 1
    0b01011011,  // 2
    0b01001111,  // 3
    0b01100110,  // 4
    0b01101101,  // 5
    0b01111101,  // 6
    0b00000111,  // 7
    0b01111111,  // 8
    0b01101111,  // 9
};

void show(byte pattern) {
  digitalWrite(LATCH_PIN, LOW);
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, pattern);
  digitalWrite(LATCH_PIN, HIGH);
}

void setup() {
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: one digit on a 74HC595 (pins 2, 4 and 3)");
}

void loop() {
  for (int n = 9; n >= 0; n--) {
    show(DIGITS[n]);
    Serial.println(n);
    delay(1000);
  }
  delay(1000);
}

Parts list

5 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

13 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Arduino Uno R3 pin GND; 74HC595 shift register pin GND; 74HC595 shift register pin OE; Resistor, 220 Ω pin 2
  • Arduino Uno R3 pin 4; 74HC595 shift register pin SHCP
  • Arduino Uno R3 pin 3; 74HC595 shift register pin STCP
  • Arduino Uno R3 pin 2; 74HC595 shift register pin DS
  • Arduino Uno R3 pin 5V; 74HC595 shift register pin MR; 74HC595 shift register pin VCC
  • 74HC595 shift register pin Q1; Seven segment display pin B
  • 74HC595 shift register pin Q2; Seven segment display pin C
  • 74HC595 shift register pin Q3; Seven segment display pin D
  • 74HC595 shift register pin Q4; Seven segment display pin E
  • 74HC595 shift register pin Q5; Seven segment display pin F
  • 74HC595 shift register pin Q6; Seven segment display pin G
  • 74HC595 shift register pin Q0; Seven segment display pin A
  • Seven segment display pin COM1; Resistor, 220 Ω pin 1

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.