Shift Register Multiplexing – Motorcycle Stop Light
This week I set out to build this LED stop light that I can fix at the back on my bike. The goals were simple.
This Stop light has Atmega328 IC as the brain. This chip uses 5V and all automotive electronics run off 12v so I have used BC547 transistors to level out. There are also three switches configured which simulate the stop and turn signals.
If you wanna see how I made this then stick around.
All the files have been included at the end of this Instructable.
First making the LED strips and animating it. When I sat to think how to make them, multiplexing was the best option. But what is multiplexing? In a layman’s term – it is a way to control lot of leds with just a very few wires. Let me explain with an example. I want to control 16LEDs and this can be done using one shift register. How? By turning these 16LEDs into a 4×4 matrix.
All these intersection are 1 led and so a total of 16LED. In fact I came up with the number 16 because of this matrix. In each row the anode are connected and in each column the cathode is connected. So when I supply 1 to the first row and 0 to the second column the first led lights up. This can be changed into a 8bit BYTE value like this B10000111. And if I want the second led from second row to light up then my byte value will be B01001011.
Let’s again put this in a row and see how the connection will be made. Each four leds are grouped and placed one after the other. So according to the connection in the matrix all the anodes of each group are connected together. At the end there is a 220ohm resistor to prevent excess voltage to the LEDs. Because at any one point just one led will be ON, just four 200ohm resistors are enough. Then the cathode of the first led from the first group is connected to the first led from each group. The same goes for the second, third and fourth.
A shift register output can be set to 1 and 0 using a micro-controller. So lets start wiring this up on a breadboard.
Here is a simple program. Its attached above. The Byte defines the animation that i want. The first four numbers refer to the Anode and the last four numbers refer to the cathode. Then in the loop I increment the index and use the shiftOut program of Arduino to send the data to the shift register. Btw here I have used LSB which means it will start from the LEFT first. If you want to use MSB then you may have to put the cathode first and then the anode values in the BYTE animation. In the BYTE animation I have simply set each LED to high by setting their respective anode and cathode high and low. This program will help check if all LEDs work.
For the bike stop light I have simply expanded on the same program with different animations. Then in the loop using if and else statement I check which switch is pressed and show the respective animation.
Speaking of switches, as I mentioned before we have to level out the 12v input to 5v, that we can feed to the Arduino. We can use voltage divider but automotive power is never constant 12v it may increase and decrease depending on the charge level of the battery. Luckily there is a voltage level diagram given. Here they use BC547 transistor. I just followed this schematics and wired it up. I also used a voltage divider instead of constant 5v to give better circuit protection. Finally connected all the switch to each pin of the Analog input.
Here then I do a analogread to check if the switch is HIGH or LOW.
Normally once the power is on the led keeps blinking from left to right. But when the stop switch is set to high and different animation is done. The same for left and right turn signals.
Using eagle cad I designed the board. I tried to make the design as small as possible so created one with SMD.
For the controller board I have designed this ATMEGA328 chip board. I call it the Bike Brain because it has space to add more switches and outputs. There are 3 more switch terminals provided and they are levelled out and connected to the rest of the Analog pins. So all the analog pins are connected to switches and the all the digital pins are outputs.
Then I etched them using toner transfer method. Please click here if you want to see how I etch PCBs.
Then drilled some holes using my home made mini drill press. And then started soldering.
I designed a case for the LED lights. It will be sealed with hot glue to prevent water entering the case. For the controller board I decided to tuck it inside the tool box to see if that will work against the water. If not I will make an enclosure for that too.
I did not want to complicate things with long wires and sourcing power from the controller board. So kept this simple with each board having its own 5v voltage regulator.
Please follow me on instagram @mrjcrp to see how this goes on my bike. Please tag me on social media as #mediamilan if you make this. If you have any question please leave them in the comments.
Until next time! Happy Learning.