RGB LEDs consist of a red, a green and a blue LED conveniently encapsulated in one package. Theoretically one such should be able to produce any colour of the rainbow, but I have restricted my project – for reasons explained later – to just red, green, blue, cyan magenta, yellow and white.
The project uses my 5 in 16 out Raspberry Pi interface. The output GPIO lines are 2, 3, 4, 17,27,22,10,9,11,7,8,25,24,23,18 and 15. Any interface providing these lines should be a suitable substitute for my little effort.
The circuit
I only managed to buy a packet of 50 common cathode LEDs. As the output logic of my interface board is of the current sinking type, I had to use a little trick to switch 16 LEDs. The circuit diagram of four of them is below, to demonstrate the principle.
The diagram shows four LEDs each one containing a red, green and blue semi conductor in one row of the arrangement. The final circuit uses four rows like the one above. Notice that the LEDs are switched in parallel – which is usually not a very good idea but it worked out very well indeed in this case. The anodes of the LEDs are connected to current limiting resistor. The anodes are also connected to three of the GPIO ports. To turn an LEDs ON, Ports 1 to n3 have to go high. This allows current to flow through the LEDs. To turn them OFF, Port 1 to 3 go low. Current will now flow from the supply through the current limiting resistors into the ports and because the LEDs need a turn-on voltage of more than a volt, they will be OFF.
This means of course that the circuit will use power in both the ON and the OFF state. To prevent this, the cathodes of each of the four rows of LEDs are connected to another GPIO port. When Port 2 is low, its row of LEDs in ON, when it goes high, no current will be consumed and all four LEDs are OFF.
This roundabout procedure was forced on me by the fact that I couldn’t buy common anode LEDs.
he pcb on the left might make things a bit clearer. I did not feel like drawing a complete circuit diagram with all those LEDs (48 all told!). The LEDs of the top row are connected thus: four red LEDs to GPIO port 15, four green LEDs to GPIO port 18, four blue LEDs to GPIO port 23. The cathodes are connected to GPIO port 2. It is clear that one row uses four GPIO ports hence all four rows use up all the ports available.
If you find this confusing let me assure you that it confused me too, at first.
Notice also that the connections to the LEDs are very close together. In fact they are on a 0.1 inch grid and you need to have a steady hand with a soldering iron to solder those tightly packed joints. One of the reasons why I switched the LEDs in parallel – it cut out a great many resistor connections!