I built this pretty simple 2x2x2 led cube for my raspberry pi, and wanted to share what i learnt.
This is my first time using transistors so the circuit is probably not perfect, but it works as i intended it to.
Here is what you will need to make one:
– 1x raspberry pi
– 8x led’s that can run on 3.3v (mine were rated for 5v)
– 2x NPN transistors (i used two 2n3904, but many others will work too)
– 2x 560ohm resistors (green blue brown gold, this will probably work with more more resistive resistors too)
– 1x 61ohm resistor (blue brown black gold, this is so we don’t burn out the led’s, doesn’t hurt if this is even bigger)
– 1x breadboard
– a raspberry pi breakout board & ribbon-cable, or a hacked ribbon cable from an old cd/floppy drive (i recommend getting a cheap breakout board and cable from ebay. It’s alot easier to wire up)
– some breadboard wires
Step 1: Making the led cube
You can make the cube freehand. But if you want to make it straighter and nicer looking, you should make a jig out of some wood.
The idea behind the led cube is that the grounds are connected together in each layer/level of the cube.
This lets you control what layer gets lit up by grounding it by switching on the NPN transistors.
The positive leads of the led’s controls which column to light up.
To make the cube just:
– bend the short(negative) leads of all the led’s 90 degrees to the side
– solder the first four negative(short) leads of 4 led’s together so they make a square
– solder the last four negative(short) leads of 4 leds’ together so they make another square
– solder the positive leds of the second square to the positive leads of the first square
– solder a wire to the ground of each layer
– your 2x2x2 led cube is now complete!
Step 2: Wiring it up
WARNING! ALWAYS TEST YOUR CIRCUITS BEFORE YOU CONNECT THEM TO YOUR RASPI (burnt pi is bad)
And if you know better, you should also calculate the drain of the circuit on full load and make sure it does not exceed 50mA!!!(supposed limit of the raspberry pi’s GPIO pins)
The NPN-transistor has three pins (or legs if thats what you’re into).
These pins are called emitter, base and collector.
When looking at the flat side of the npn transistor, with the pins facing down,
the left pin is the emitter, the middle pin is the base and the right pin is the collector.
I will use the base pin to switch the ground of the two layers in the led-cube on/off!
Now that your cube is done, you will need to wire it up, so:
– stick the four positive leads of the led cube into the breadboard
– connect gpios from the raspi to each of the 4 positive leads of the led cube
– connect the current limiting resistor (61ohm) to the ground on the pi and to the rail
– connect the right pin (collector) on both npn transistors to the grounded rail
– connect a 560ohm resistor to the middle pin(base) of each npn transistor
– then connect a gpio from the raspi to each of the 560ohm resistors
– connect the emitter(the left pin) on each npn transistor to one of the negative leads of the led cube
– and you’re done!
Step 3: Write the code
To make everything as simple as possible, i will script in bash.
In the next step you can see my code, but first.
here is the basics.
Say you have a lead from the cube connected to GPIO8 and one of the NPN-transistors connected to GPIO-25.
– open a terminal on your pi
– create the script with: “touch ledcube.sh”
– edit the script with: “nano ledcube.sh”
– write this into the script:
#preparing gpio 8 and 25 for use
echo 8 > /sys/class/gpio/export;
echo out > /sys/class/gpio/gpio8/direction;
echo 25 > /sys/class/gpio/export;
echo out > /sys/class/gpio/gpio25/direction;
#turning on an led
echo 1 > /sys/class/gpio/gpio8/value;
#turning on the ground
echo 1 > /sys/class/gpio/gpio25/value;
#waiting a little
#turning off an led
echo 0 > /sys/class/gpio/gpio8/value;
#turning off ground
echo 0 > /sys/class/gpio/gpio25/value;
echo 8 > /sys/class/gpio/unexport;
echo 25 > /sys/class/gpio/unexport;
– run the script with “sudo sh ledcube.sh”
– modify it so you can control all your led’s and layers and ENJOY!
You can also build a 3x3x3 led cube this way, just expand the cube and add another npn-transistor. Any more than that and you will need some other parts.
Any and all feedback is appreciated. And please tell me if I’m spreading misinformation, so i can correct it.
For more detail: Raspberry pi – simple 2x2x2 led cube