DIY Programmable Bike Light – Arduino or ATTiny and RGB LED

by Oscar

Since I got my bike, I had always wanted to do something interesting bike related. Riding a bike at night is a bit dangerous, so I decided to build a DIY bike rear light to keep me safe.! Most bike lights on the market are some dummy red LED with just a switch, which might be running off some AA batteries. That is boring as hell and swapping out the battery once every few days seems to be a pain.

Some of the links on this page are affiliate links. I receive a commission (at no extra cost to you) if you make a purchase after clicking on one of these affiliate links. This helps support the free content for the community on this website. Please read our Affiliate Link Policy for more information.

In this project I will be using a microcontroller to allow for switching between the various functions I programmed. The entire system is built on the backbone of an ATtiny4313 chip with a few other parts totaling at about $35. It might seem a little expensive, but this build covers a lot of ground. You not only get safety-centric feature, you also get a handy USB charging facility and programmable LED display.

Here is a quick demo how it performs.


I had a lot of ideas about the features since I have the idea. Here is what I am going to do:

  • It should be light weight and small – aim to make it lighter than 30 grams and can be easily mounted on the bike or backpack.
  • It should be an easy and simple build, no complicated circuit or calculation.
  • It should use wide angle RGB LEDs, so it changes colour if I want to.
  • Multiple LED display patterns available, can be chosen by the user.
  • It uses rechargeable Lipo battery, so it’s lighter and more durable, and It can be charged by computer USB port.
  • It shows the battery power level.


So here are the list of components and materials I used:

  • ATTiny4313 micro processor – The brain ( I can use the Arduino too)
  • Powercell Lipo charger and booster
  • 300mA 1S Lipo Battery
  • WS2811 RGB LED strip
  • Some Resistors, Capacitors and wires

I will try to explain why I used these components in the article. I will also state what resistors and capacitors I used in this project. Let’s go through the steps I took to build this colourful yet simple bike rear light.

Getting the ATTiny4313 to work

Not many particular reasons why I used this chip, just because I had a few spare, and they are very light weight. Arduino can do the job too (probably a better job and making the circuit much simpler, and allows a larger sketch), but Arduino is more expensive and larger/heavier in size. The code written for this project is interchangeable for ATTiny and Arduino, the only difference is the pin numbers, so pick the one that works for you.


You can write the program in the Arduino IDE, and upload the code to the ATTiny via an Arduino. The arduino in this case act as a programmer, which is relatively easy to do, check out my tutorial on how to do this on ATTiny4313.

Getting the RGB LEDs to work with ATTiny4313/2313

I decided to use WS2811 because I happened to have some spare from my last Arduino Ambilight TV project, and they are actually very bright and durable. They have built-in IC to control the RGB LEDs, so only require one data connection from the micro controller (for multiple RGB LEDs), and the library for it is very simple to use too.

This is very straight forward, same as how you would use it on the Arduino, nothing needs to be changed in the code you use on the Arduino, but the data connection pin number.

Electronics wise, this LED runs on 5V (instead of 12V which is harder to work with) and draws a constant current of 20mA at its brightest state.

Power The Circuit with Lipo Battery And Lipo USB Charging Testing

As you know Lipo Batteries are used a lot in RC planes and models like that because of it’s advantages in weight and discharge rate. However the voltage of 1 cell Lipo battery is 3.7V, 2cell would be 7.4 V etc, and our LED and Attiny Chip require 5V power supply. That means we will need some sort of voltage booster.

Luckily there are available board that can boost 1S Lipo battery voltage to 5V, at the same time it can be used as a charger.

Battery Voltage Checking

If we are able to check the voltage level on the battery, we can be reminded to charge the bike light and manage the usage better. I described how this could be achieved using the ATTiny2313 and 4313 in this tutorial.

Here is the battery positive wire break out connection to connect to the AIN0 (comparator).


One problem though, is when the Lipo is connected directly to the ATtiny chip, it also powers up the chip! (I didn’t thought of that! ) That means when it’s connected there is no way you can power down the LEDs and the ATTiny chip unless you disconnect the Lipo connection.

This is a problem I need to think about, one quick fix would be adding a extra switch, or push button, which you only press when you want to check the voltage level, and the rest of the time it’s switched off. However this is not ideal, I will keep working on it for a better solution.

Eventually, I decided to solder a push button to the battery break out connection. So only when the push button is pressed, AIN0 can read the voltage of the battery, the rest of the time it’s an open circuit.

Schematics Circuit Design

This schematics probably isn’t up to standard, but I hope it should be clear enough for most people. This is the whole system.


Soldering Work And Assembling

Soldering is not easy. I recommend using more wires and avoid using the soldering on the vero board, once you make a mistake it’s very HARD to reverse. Because I am trying to minimize the cross section area, so I am stacking them by building the electrical components on three smaller separate vero boards.






After connected everything, I first tested the circuit making sure it’s working. Then I put hot glue all the solder joints and back of the vero boards. Finally stack them up and use cable tie to secure them. It turns out a bit taller than I thought.






Just be aware that the ATtiny4313 allow sketches that no larger than 4090 Bytes. That’s pretty limited and it doesn’t leave much room after including the RGB LED library. I had to really simplify my code and squeeze it.


I am thinking to create 5 patterns, from the most power saving mode to the most colour and brightest mode.

1. “Loading Red Dot” – only 1 LED is on at all time

2. “Switching 3 LEDs” – only 3 LEDs

3. “Breathing Red Light” – all 6 LEDs are on

4. “Dimming White and Blue Light” – all 6 LEDs are on

5. “Colourful Rainbow Mode”  – all 6 LEDs are on


I am very happy with the result. there are a few improvement I could think of right now, such as sun light detection, solar charging, etc. I could also make a case for the device, so no electronics is exposed. Even making it water proof so it can also work in the rain.


Leave a Comment

By using this form, you agree with the storage and handling of your data by this website. Note that all comments are held for moderation before appearing.