150 LEDs, One Bike – Pimping my Commuter
When daylight savings finished this year, I found myself getting stuck at Uni without any lights for my ride home. The easy solution would be to keep my lights in my backpack, however I instead decided to attach 150 LEDs to my bike, because it seemed like the more interesting option. I’ll let the below video do the explaining. Apologies in advance for the shoddy video, we all have to start somewhere.
As you might have noticed in the video, I glossed over some technical detail and also made a few mistakes with some of the numbers. So hopefully the below explanation clears some of those up. Whist I have not included a full schematic for the project, with a bit of Googling you should be able to join any missing dots (or wires!). However, if you want some help, feel free to contact me with any questions.
The power supply consists of a 12 V lithium ion battery back, which is run into the input of a boost converter to keep the output at 12.6 V for the duration of the battery. As without it will drain down to 10.8V or below, which will dim the LEDs. Yes, the LED strip is rated at 12 V, so I should have used a buck-boost converter to pin the output at 12 V, however I had a buck converter laying around and 0.6 V over their rated max shouldn’t hurt.
As the Arduino Nano is rated at a max input voltage of 12 V, and many people (myself included) have let the magic smoke out at this voltage, the 12.6 V from the buck converter is regulated down to 8.3 V using a LM317T in the configuration shown below. This is then fed to the Nano through the VIN pin, where the voltage regulator on the board can safely step it down to whatever voltages it requires. I added a heat sink on the regulator to play it safe, however it does not get very hot so it could be done without.
I used an Arduino Nano as the controller for the lights, as I had one laying around, and it also has just enough PWM pins (6) to control the RGB channels for the front and rear independently. Whilst it would have been nice to be able to PWM the white channel, I’m not sure if I would ever use that functionality so it’s neither here or there. With a push button connected to Pin 13, the Arduino is used to check it’s state, and then cycle through the different light patterns which are set in the code.
I used eight IRLB8721PbF N-Channel Power MOSFETs to drive the LEDs, as they can withstand the power requirements, and also have sufficiently small switching time delays, which allows us to PWM the LEDs. They were connected as shown in the below schematic.
When it comes to the Code, I must give credit to Tom Igoe and Josh David for their edge detection and smooth RGB fading examples respectively, as if it wasn’t for their work which I have used extensively into my project, it would not work anywhere near as well. (Trust me, my attempt was buggy at best, and unusable at worst!).
The code I have loaded onto my Arduino can be found here, and I’ll quickly outline what it does. The first part checks for a change in the state of the pushbutton, and increments a variable every time it is pressed. This value is printed to serial, and then switch statements are called depending on its value. Case 0 pulls all pins low, and thus acts like a ‘soft’ off state. The following n-1 statements simply turn pins high and low to change the LEDs on and off, with one of them using Josh’s code for the smooth RGB fading. Case n is a special case, in that it resets the count to 0, and allows for the lighting options to form a loop.
If you have gotten this far and are wondering how to wire everything up, I have purposely omitted this as there are plenty of good examples on the internet, such as this Adafruit example. All you will need to do to make my code work is to change the pins the LEDs and button are connected to, ensuring that you are using the PWM pins on your Arduino of choice to drive the Red, Green, and Blue LEDs.
Whilst this was an interesting project to undertake, I would be reluctant to do it again. The technical challenge of writing the code, and building the control board was challenging, but easy enough that that it was enjoyable. The actual wiring of the LEDs to the bike on the other hand was long, tedious and boring. The end result was nowhere as neat as I hoped, and due to my lack of experience with crimping the wires into the connectors, they take some finessing when being connected. At the end of the day, I’m happy that I completed the project, and the result looks good at night, from a meter away, without my glasses. But would I do it again? or recommend it to someone else? Probably not.
If you have any comments on how the lights look, have an idea for a different light combination, or want a hand with a technical part of the project, feel free to leave a comment below. Also if you have gotten this far and are wondering about the reference that the second part of the title and my shirt are alluding to, your answer is here.