Rainbow LED Chaser
I was bored this past sunday, and needed something to ease my racing brain … so I picked an easy project with lots of flash.
The parts list:
Eight Tri-Color or RGB leds … each led package contains three LEDs
Three 74HC595 Shift Registers … serial load, latching. other varieties would probably work too.
One Microcontroller … doesn’t matter what it is, I used a pic18f252 since it was handy.
Twenty-Four Resistors … I used 150 ohm to set my led current at 20mA, but use anything from 56-220 ohms
The tri-color leds I used are wired as common anode LEDs … each led inside the package has its own cathode pin and shares a common anode pin. So, all my anode pins connect to the postive rail on the breadboard. There’s no reason a person couldn’t use twenty-four discrete LEDs, or eight common cathode leds. Since my leds are “active low”, outputting a 0 turns them on, outputting a 1 turns them off… if you used common cathode leds, they would be “active high”, a 1 would turn them on and a 0 off. If you used discrete leds, well, hook ‘em all up one way or the other.
Next comes the connections to the shift registers. Think of each register as a chip containing eight switches you can turn on or off remotely. Each of the 24 LEDs gets connected to an output on the register, and they need to be grouped by color and kept in order. So looking at the picture below, working left to right, I connected all the red leds to the first register, all the blue to the second, all the green to the third. This resulted in the rats nest of wires you see between the chips and the leds. Concerning the registers themselves, they have three connections of up-most importance. Pin seven is the ground connection, pin fourteen is the +5v connection, and pin thirteen is the enable or tri-state pin. The tri-state pin must be tied to ground in order for the outputs on the register to work. Next up is the data connections. The 595 offers a nifty feature of serial pass-through. Using this feature, you can chain a bunch of them together, and treat them as a large number (in the programming). This is done with the QH* and SER pins. QH* connects to SER on the next ic ‘down stream’. On the first IC (the rightmost in my picture), SER connects to the microcontroller. Now in order to ‘load’ the chips with serial data, the microcontroller has generate a ‘clock’ for all the chips to sync to. This clock signal is transmitted on the SCK (serial clock) line. All three SCK lines are wired in parallel to the microcontroller. Last, since we want the data to be retained by the registers, even if the pic stops transmitting, we need to latch the data. This is controlled by the last data line, RCK. When the microcontroller is finished transmitting data, it needs to pulse the latch clock RCK high briefly. Upon receiving this signal, the registers display the data which they just received, and continue to display it until told otherwise. I have some other lines connected, but don’t use them… they are the SCLR line, which clears the data from the buffers, and the enable line. The microcontroller keeps the enable line high (disabling the registers outputs) until it is read to start sending commands… this prevents the registers from powering up with weird random data being displayed.
That’s it for the hardware side … really simple. All the magic happens in software… which I will write about in part two (yes, I’ll post the code too). As a spoiler, all the software does is boolean math, shifting and inverting 8-bit words of 1′s and 0′s around.
The parts in the grayed out areas are just stuff left over on the breadboard from an earlier project, or support components for the microcontroller.
Here are some videos:
Initial Test Program:
Due to all the connections (24 of them between the registers and the LEDs), drawing a schematic can get messy. I chose to avoid this mess by using Eagle “BUS” feature, which allows a large number of signals to be combined into one wire. The schematic below is drawn using a much less expensive and smaller PIC than the one pictured in the breadboard … however the idea is still the same.
For more detail: Rainbow LED Chaser
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days
Current Project / Post can also be found using:
- project kit for rgb led chaser