Build it step by step
0 of 7 doneTest one LED
Check polarity with a resistor and the 5 V pin before soldering.
Make a jig
Drill a 3×3 grid in card, 2.5 cm apart, and hold the LEDs in it.
Solder a layer
Bend the cathode legs flat and join the nine cathodes into one square.
Make three layers
Test each layer's LEDs again before stacking.
Join the columns
Stack the layers and join each column's anodes with the vertical legs.
Wire the base
Fit nine resistors on the columns and one transistor per layer.
Upload the sketch
Watch the three animations.
How do you build a 3×3×3 LED cube?
Twenty-seven LEDs soldered into a cube light up in 3D animations, multiplexed by layer. You need Arduino Uno R3, LED 5 mm blue × 27, Resistor 220 Ω × 9, BC547 NPN transistor × 3, Resistor 1 kΩ × 3 and Perfboard (dot PCB) 7 × 9 cm. It takes 7 steps and about 180 minutes.
- Level
- Beginner
- Time
- About 180 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- OptoelectronicsBuyLED 5 mm blue × 27
- PassivesBuyResistor 220 Ω × 9
- SemiconductorsBuy
- PassivesBuyResistor 1 kΩ × 3
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Column 1 to 9 (anodes of the three LEDs stacked in each column) | Arduino D2 to D10 through a 220 Ω resistor each | Nine column drives |
| Layer 1 common cathode | BC547 collector, emitter to GND | Bottom layer switch |
| Layer 2 common cathode | BC547 collector, emitter to GND | Middle layer switch |
| Layer 3 common cathode | BC547 collector, emitter to GND | Top layer switch |
| BC547 bases | A0, A1, A2 through a 1 kΩ resistor each | Layer select |
| Arduino GND | All BC547 emitters | Common ground |
| USB | Arduino | Power |
Code
Columns are wired in a 3×3 grid, so column 1 is a corner and column 5 is the centre. Each LED is on for one third of the time, so with a 220 Ω resistor the pulses look bright enough while the current stays small: a layer has up to nine LEDs lit at about 8 mA each, which the BC547 handles. Never switch two layers on together. If the cube looks dim, shorten nothing: lower the delay only a little, as flicker appears below about 1 ms per layer. Arduino IDE, board "Arduino Uno".
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// 3x3x3 LED cube: nine column pins, three layer transistors. Board: Arduino Uno.
const byte COL[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
const byte LAY[3] = {A0, A1, A2};
byte cube[3][9]; // cube[layer][column] is 1 when the LED is on
void clearCube() { for (byte l = 0; l < 3; l++) for (byte c = 0; c < 9; c++) cube[l][c] = 0; }
// Show the current frame for the given time by scanning one layer at a time.
void show(unsigned long ms) {
unsigned long t = millis();
while (millis() - t < ms) {
for (byte l = 0; l < 3; l++) {
for (byte c = 0; c < 9; c++) digitalWrite(COL[c], cube[l][c]);
digitalWrite(LAY[l], HIGH); // transistor on, this layer's cathodes go to ground
delayMicroseconds(1500);
digitalWrite(LAY[l], LOW); // off before changing the columns, to avoid ghosting
}
}
}
void setup() {
for (byte c = 0; c < 9; c++) pinMode(COL[c], OUTPUT);
for (byte l = 0; l < 3; l++) pinMode(LAY[l], OUTPUT);
randomSeed(analogRead(A5));
}
void rain() { // random drops fall from the top layer to the bottom
for (byte n = 0; n < 12; n++) {
byte c = random(9);
for (int l = 2; l >= 0; l--) { clearCube(); cube[l][c] = 1; show(90); }
}
}
void layerSweep() {
for (byte r = 0; r < 3; r++) for (byte l = 0; l < 3; l++) {
clearCube(); for (byte c = 0; c < 9; c++) cube[l][c] = 1; show(180);
}
}
void spin() { // a bar turns around the middle column
const byte ring[8] = {0, 1, 2, 5, 8, 7, 6, 3};
for (byte r = 0; r < 3; r++) for (byte i = 0; i < 8; i++) {
clearCube();
for (byte l = 0; l < 3; l++) { cube[l][ring[i]] = 1; cube[l][4] = 1; cube[l][ring[(i + 4) % 8]] = 1; }
show(90);
}
}
void loop() { rain(); layerSweep(); spin(); }Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| One layer on | All nine LEDs of that layer light evenly |
| Rain | Single drops fall top to bottom |
| Sweep | A full layer moves up in turn |
| No LED stays on when the program stops | Remove power and check |
If it does not work
A whole layer stays dark
Check its transistor, base resistor and cathode joint.
A column never lights
Look for a cold joint on its anode legs.
Two layers show the same picture
Check no cathode square touches another layer.
Brightness varies
Check the LEDs are the same colour and batch.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the 3×3×3 LED cube?
Arduino Uno R3, LED 5 mm blue × 27, Resistor 220 Ω × 9, BC547 NPN transistor × 3, Resistor 1 kΩ × 3 and Perfboard (dot PCB) 7 × 9 cm.
How long does the 3×3×3 LED cube take to build?
About 180 minutes for a beginner maker, in 7 steps.
How do I know the 3×3×3 LED cube works?
One layer on: All nine LEDs of that layer light evenly. Rain: Single drops fall top to bottom. Sweep: A full layer moves up in turn.
A whole layer stays dark: what should I check?
Check its transistor, base resistor and cathode joint.
A column never lights: what should I check?
Look for a cold joint on its anode legs.
Two layers show the same picture: what should I check?
Check no cathode square touches another layer.
Brightness varies: what should I check?
Check the LEDs are the same colour and batch.
