Built-in project · Arduino Uno R3
LED bar chaser on an Arduino Uno
An Arduino Uno runs a bar and a bouncing dot along eight LEDs through a 74HC595. The whole build, an Arduino Uno and 17 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.
IntermediateRuns in your browser. Free, and no account needed.
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
// Chaser: eight LEDs, three pins, one 74HC595.
//
// Wiring, shift register to board:
// DS (pin 14, serial data) -> pin 4
// SHCP (pin 11, shift clock) -> pin 5
// STCP (pin 12, latch clock) -> pin 6
// MR (pin 10) to 5 V, OE (pin 13) to GND
// Q0..Q7 through 220 ohm resistors to eight LEDs to GND
//
// shiftOut with MSBFIRST sends bit 7 first, and the bit sent first ends up
// furthest along the register, so bit n lands on Qn. Q0 is the left-hand LED
// here, which is why a growing bar is (1 << n) - 1 and a running dot is 1 << n.
//
// The latch clock is pulsed only after all eight bits are in, which is the
// whole point of the chip: the outputs sit still while the byte is being
// clocked in and all change together at the end, so nothing flickers through
// the intermediate patterns.
const int DATA_PIN = 4; // DS
const int SHIFT_PIN = 5; // SHCP
const int LATCH_PIN = 6; // STCP
const int BAR_MS = 80;
const int DOT_MS = 70;
static void show(uint8_t bits) {
shiftOut(DATA_PIN, SHIFT_PIN, MSBFIRST, bits);
digitalWrite(LATCH_PIN, HIGH);
digitalWrite(LATCH_PIN, LOW);
}
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(SHIFT_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
digitalWrite(SHIFT_PIN, LOW);
digitalWrite(LATCH_PIN, LOW);
Serial.begin(115200);
Serial.println("Mokxi Arduino Uno: eight LEDs on three pins");
}
void loop() {
// the bar fills from the left, then empties
for (int n = 1; n <= 8; n++) {
show((uint8_t)((1u << n) - 1u));
delay(BAR_MS);
}
for (int n = 7; n >= 0; n--) {
show((uint8_t)((1u << n) - 1u));
delay(BAR_MS);
}
// then a single dot runs to the right and back
for (int n = 0; n < 8; n++) {
show((uint8_t)(1u << n));
delay(DOT_MS);
}
for (int n = 6; n >= 1; n--) {
show((uint8_t)(1u << n));
delay(DOT_MS);
}
}
Parts list
19 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
21 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; LED, yellow (1) pin C; LED, yellow (2) pin C; LED, yellow (3) pin C; LED, yellow (4) pin C; LED, yellow (5) pin C; LED, yellow (6) pin C; LED, yellow (7) pin C; LED, yellow (8) pin C
- Arduino Uno R3 pin 6; 74HC595 shift register pin STCP
- Arduino Uno R3 pin 5; 74HC595 shift register pin SHCP
- Arduino Uno R3 pin 4; 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; Resistor, 220 Ω (2) pin 1
- 74HC595 shift register pin Q2; Resistor, 220 Ω (3) pin 1
- 74HC595 shift register pin Q3; Resistor, 220 Ω (4) pin 1
- 74HC595 shift register pin Q4; Resistor, 220 Ω (5) pin 1
- 74HC595 shift register pin Q5; Resistor, 220 Ω (6) pin 1
- 74HC595 shift register pin Q6; Resistor, 220 Ω (7) pin 1
- 74HC595 shift register pin Q7; Resistor, 220 Ω (8) pin 1
- 74HC595 shift register pin Q0; Resistor, 220 Ω (1) pin 1
- Resistor, 220 Ω (1) pin 2; LED, yellow (1) pin A
- Resistor, 220 Ω (2) pin 2; LED, yellow (2) pin A
- Resistor, 220 Ω (3) pin 2; LED, yellow (3) pin A
- Resistor, 220 Ω (4) pin 2; LED, yellow (4) pin A
- Resistor, 220 Ω (5) pin 2; LED, yellow (5) pin A
- Resistor, 220 Ω (6) pin 2; LED, yellow (6) pin A
- Resistor, 220 Ω (7) pin 2; LED, yellow (7) pin A
- Resistor, 220 Ω (8) pin 2; LED, yellow (8) pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.