ELEGOO MEGA · LESSON 24
Eight LED with 74HC595
Fill an eight-LED bar through a 74HC595, then clear and repeat.
Shift a byte into a latched parallel-output register.
Parts List
- ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
- A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
- An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
- 2 ×Green LEDA green indicator LED converts forward current into visible light; use it for status indication with a series resistor. Green two-lead dome. Lead length may have been trimmed; confirm polarity with diode test.
- 2 ×Red LEDA red indicator LED converts forward current into visible light; use it for status indication with a series resistor. Red two-lead dome; longer lead normally anode, flat edge normally cathode. Lead length may have been trimmed; confirm polarity with diode test.
- 2 ×Yellow LEDA yellow indicator LED converts forward current into visible light; use it for status indication with a series resistor. Yellow two-lead dome. Lead length may have been trimmed; confirm polarity with diode test.
- 2 ×Blue LEDA blue indicator LED converts forward current into visible light; use it for status indication with a series resistor. Blue two-lead dome. Lead length may have been trimmed; confirm polarity with diode test.
- 1 kΩ resistor provides a fixed opposition to current. Signal current limiting and transistor base drive is a common use when its unverified power and tolerance limits fit the circuit. Small axial body with one wire at each end. Find the labeled value compartment and measure an isolated loose part with a meter; the shared inventory image is a form reference.
- 74HC595 accepts eight bits serially and latches them onto eight parallel logic outputs, expanding output control with a few GPIO lines. 16-pin DIP marked 74HC595/74HC595N with notch or pin-one dot. HC and HCT variants have different input thresholds.
- 100 nF nonpolar ceramic capacitor stores electric-field energy. Local IC decoupling and short high-frequency supply disturbances are appropriate uses when voltage and circuit requirements are checked. Small non-polar disc, often marked 104; 104 means 100 nF, not 104 pF. Read the value and rating rather than estimating from body size.
- Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.
Assembly
- Disconnect USB and use the original LED layout, replacing the eight LED resistors with 1 kΩ and adding the IC bypass capacitor.
- Check the notch, MR→5 V, OE→GND and every LED polarity before reconnecting.

Reviewed connections
| From | To | Note |
|---|---|---|
| Mega D12,D11,D9 | 74HC595 14 DS,12 ST_CP,11 SH_CP | Data,latch,clock |
| 74HC595 16 and 10 → 5 V; 8 and 13 → GND | Power, clear and enable | Notch identifies pin 1; pin 9 Q7′ stays open |
| Q0..Q7 (15,1,2,3,4,5,6,7) | One 1 kΩ then one LED anode per output | Each LED cathode → GND; replace all eight pictured 220 Ω values |
| 100 nF across IC 16 / 8 | Supply bypass | Place close to the IC |
Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.
Code
PlatformIO configuration
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
#include <Arduino.h>
const uint8_t LATCH_PIN = 11; // ST_CP, IC pin 12, copies shifted bits to visible outputs.
const uint8_t CLOCK_PIN = 9; // SH_CP, IC pin 11, advances the serial shift register.
const uint8_t DATA_PIN = 12; // DS, IC pin 14, supplies one bit for each clock edge.
uint8_t leds = 0; // Eight bits remember which LEDs should be on.
void updateShiftRegister() {
digitalWrite(LATCH_PIN, LOW);
// LSBFIRST sends bit 0 first; after eight clocks it reaches Q7, not Q0.
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, leds);
digitalWrite(LATCH_PIN, HIGH); // All outputs change together after the complete byte.
}
void setup() {
pinMode(LATCH_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT);
}
void loop() {
leds = 0; updateShiftRegister(); delay(100); // The actual supplied sketch uses 100 ms, not PDF's 500.
for (uint8_t i = 0; i < 8; ++i) {
bitSet(leds, i); // Set one more bit without clearing the LEDs already on.
updateShiftRegister(); delay(100);
}
}
Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.
Expected behavior
The bar clears, then adds one LED every 100 ms until all eight are lit. The actual archive uses 100 ms, despite PDF prose showing 500 ms.
Experiments & Challenges
- Change the 100 ms pauses to compare the fill speed.
Troubleshooting
- Wrong sequence: check data/latch/clock order and LSBFIRST; missing LEDs usually indicate polarity or an open resistor path.