Rechargeable Bike Light With Automatic Switch of Energy Source




Introduction: Rechargeable Bike Light With Automatic Switch of Energy Source

First of all, excuse my non-native English and my lack of professional electrical engineering skills. I see this as a hobby and have no claim to be perfect. However, if you have some ideas on how to improve the setting don’t hesitate to write a comment ;-)

I haven’t seen any similar Instructable yet, which is why I quickly created one =)

My former bikelight was a pretty standard halogen light which was directly connected to the dynamo (generator) of the bike. Major problems I had with it were:
- Insufficient brightness
- Characteristics of the light beam caused by the reflector
- Light was not available when standing or at very low speed (disadvantageous at traffic-lights, junctions etc.)

My goals for the new bike light were:
- Rechargability via dynamo
- No need to exchange batteries
- Higher brightness
- Better distribution of the light beam
- Availability of light at all times (standing vs cycling)
- Low-cost

- quite similar project : Rechargeable Bike light set with bottle battery
- all pictures shot in battery mode (on dynamo it's approx. 1/4 brighter)

Step 1: Parts and Prerequisites

- Bike
- Dynamo (mine is 6V / 3W)
- Mount from old bikelight
- Small metal-box (Altoids etc.)
- Arduino Uno / duemilanove (only to program Attiny85)
- Heatshrink tubing / Lighter
- Wires (I use wires from old IDE/P-ATA cables and mark their polarity with permanent marker)
- Hotglue-gun
- Glue
- Electrical tape
- Cable straps

Specific parts
(all prices approximated, some example links provided)
- 5V Linear Voltage regulator $0,51 / 0,37€
- 5W LED Driver 3-18V input $2,60 / 1,89€
- Li-ion charge controller input voltage 4.5-5.5V $1,87 / 1,36€
- 2x Small R/C helicopter battery 240mah $3,44 / 2,50€
- Cree XR-E Q5 (or any high-power LED) $5,60 / 4,07€
- Bridge Rectifier $0,38 / 0,27€
- Attiny85 Microcontroller $2,49 / 1,81€
- Socket for Attiny chip (called DIP8) $1,88 / 1,37 €
- Lens or Reflector for LED $ 0,52 / 0,38€
- Capacitor (I used a 10 µF one, higher capacity is better ) $0,27 / 0,20€
- Transistor (I used 2N2369A, better use one for high currents) $0,27 / 0,20€
- Switch $0,27 / 0,20€

Sum ~ $20 / 15€

Step 2: Design

The major idea is to have the rectifier converting the AC power from the dynamo into useable DC power for our driver, charger and microcontroller. The capacitor is supposed to flatten the energy output from the rectifier and dynamo into a more constant power source. The capacitor I used has 10 µF which is probably too small (lack of electrical engineering here), but for me it works fine at this point (the LED driver does some work too).
There are two power lines, one is going directly to the LED driver and is intended to transfer the electricity when cycling. Since the LED driver has a voltage range from 3-18 V a maximum of 6V coming from the dynamo should be no problem.

The other power line is connected to the 5V linear voltage regulator in order to protect the charge controller and attiny85 microcontroller from voltage spikes (attiny 2.7 V-5.5V, charge controller 4.5-5.5V). The charge controller is charging two li-ion batteries in parallel (do not charge a li-ion battery without a charge controller, they can otherwise ignite or even explode!) and will stop to do so if the battery is fully charged. A switch is connected to the positive pole of the Battery so that the light can be switched off completely. After that the Attiny chip is linked to control a transistor which connects the battery to the LED when the dynamo does not produce sufficient energy. Due to the Voltage drop and a relatively low maximum current through the transistor (at least my one) it is possible to directly connect the LED to the battery circuit without frying it (At first I did wire up the battery circuit with the LED driver too, but it did not work out due to a very low input voltage of about 3.2 V. There are better drivers with lower input voltage thresholds where this could be possible.).
The main issue of this setting is that we are able to define a threshold in the microcontroller at which the change from battery to dynamo and vice versa is triggered, so that an on-the-fly switching of the energy source is possible.

Here a quick video demonstrating the switch of energy source

switch to dynamo at 0:04 (not visible)
switch back to battery at 0:07
Light actually is a lot brighter than it seems on the video!

Step 3: Programming

int transistorLine =0;int voltageSens =3;
boolean dynamoOn= false;

byte testruns =15;int thres =680;void setup(){.
  pinMode(transistorLine, OUTPUT);  
  pinMode(voltageSens, INPUT);}void loop(){if(dynamoOn = IsDynamoRunning()) digitalWrite(transistorLine, LOW);else digitalWrite(transistorLine, HIGH);}

boolean IsDynamoRunning(){
  byte test=0;for(byte i =0; i < testruns; i++){if(analogRead(voltageSens)>= thres ) test++;
   delay(1);}if(test == testruns){return true;}elseif(test ==0){return false;}elsereturn dynamoOn;}

The programming is relatively simple, we just use one pin as analog-input to measure voltage coming from the generator. At a defined threshold (I chose 680 which should be about 3 V) we switch from battery to generator or generator to battery. We measure the voltage several times and only change the condition if all measurement samples were over or under the threshold voltage respectively. This is done to avoid any flickering and make the decision whether to switch to battery or dynamo more stable. The battery connection is switched on by setting the transistor control pin to HIGH and thus closing the “switch” from battery to LED. Naturally, the opposite effect can be achieved by switching to LOW.
For wiring of the Attiny85 and a manual on how to program it by using the Arduino board have a look at this link: or google "attiny85 arduino"


Step 4: Assembly

I decided to put all components into an old candy metal box which I insulated from the inside with electrical tape. At first I drilled two holes at the top of the box to serve as holes for the two cables pairs coming out of the box. The holes need to be big enough so that one heat-shrink-tube can fit through each hole. Through these tubes we put the two strings of cables and fix them with hotglue. One pair is the AC input from the generator, the other pair is + and – for the LED (see circuit diagram).
Another bigger hole at the bottom (I drilled two holes next to each other) is used to accommodate the switch and is later fixed to the box with hotglue as well.
The soldering of the components is quite straight forward, just make sure to insulate all contacts carefully (Don’t forget to put the heat-shrink-tubes onto the wires before you solder both ends of the wire).
After that the whole thing can be squeezed into the box with light force (be careful not to break anything). Alternatively it is also possible to solder everything onto a prototype PCB board, which may tidy it up a little bit ;-).

The Box itself is additionally held closed by a rubber band and is fixed to the bike next to the headset and the front part of the frame by using cable straps.
The LED is soldered to the designated cable pair coming out of the box. Furthermore, the reflector of the old bike light needs to be screwed off and the old blub needs to be removed so that the LED can fit into the mount. After that I hot-glued a LED-lens on top of the mount to focus the beam into a cone of approx. 60-90 degrees.
Lastly you need to connect the two wires coming from the dynamo to the two designated cables for the AC power input of our driver box. Sometimes there is only one wire, this often means that the other connection is made via the frame of the bike.
Optionally tidy up excess wiring by using cable-straps and you are done! =D

Step 5: Criticism / Improvements

- Possibly bad battery lifetime due to unusual charging/discharging behaviour (however these batteries are cheap)
- Doubtable if charger quickly recognizes after switching on that battery is fully charged (and stop charging) when it is full already
- Switching of transistor/attiny- method may not always be perfect, e.g. undesired leakage current in opposite direction through transistor towards battery. Perhaps better use a diode or a self-conducting transistor but then the threshold for the energy source- switching is more difficult to set.
- Possibly not fully waterproof.  My workaround is to wrap the whole box into a small, trimmed and transparent plastic bag. It is closed off at the bottom (where the two cable pairs exit the box) with another rubber band that is tightly fitted. This is then attached to the bike with cable straps as usual.
- Quite low battery capacity of 480 mah (but the battery needs to take over only for short periods of time usually)
- It would be possible to implement an engery-saving mode (Attiny PWM) after some time when running on battery or to even switch off the light (or both as certain steps of an energy-saving concept)
- Could use a reflector to collect more light
- Better pictures and a video may follow! ;-)
- Probably better use a high power transistor  (just used this one because I already had it)

- It is interesting to note that the analog voltage measurement of the attiny is only a comparison to the reference supply voltage of the chip. That means that 1024 at 5V supply means 5V and roughly 3.7V at battery supply. So I guess if you would like to calculate the voltage threshold via the analog input, better use the minimum 3.7V as a reference as there probably will be no supply by the charge controller anymore/yet.

- One could easily add a USB charger by using a cheap step-up USB module (1-5 V input converted to 5V for USB) connected after the 5V voltage regulator (in parallel to the charge controller, could imagine some trouble with the charge controller otherwise). Note that there could be some issues with apple hardware due to their special USB-charging requirements.

Be the First to Share


    • Exercise Speed Challenge

      Exercise Speed Challenge
    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Metalworking Contest

      Metalworking Contest

    5 Discussions


    6 years ago on Introduction

    HI Great work, but I feel that your un-loaded voltage from the hub will be too high at good speed and will cook your main voltage reg (LM7805) over time.... you need to use a voltage limiter somewhere, and would pay to use a bigger smoothing cap, 4700uf is fine....

    hope this helps....K


    6 years ago on Introduction

    Thanks a lot! I have a similar configuration on my bike


    6 years ago

    This is great stuff and your English skills rock.