Motivation
After getting a new bicycle I have started thinking about making my own LED lights for it. I have been playing with electronics many years ago in my teen-age years, but I have been doing only software since then. So I have got this as an opportunity to find out what progress the world of DYI electronics has made, and to learn programming of microcontrollers. This page describes work in progress, don't expect a final solution yet.
Features
- LED drivers for high-power LEDs:
- Atmel AVR Tiny CPU, programmable in-system (various blinking modes, etc.).
- Power: 7 to 12 V battery pack (either lithium or NiMH).
- Ambient light sensor (for automatically setting the mode depending on the conditions).
- Battery voltage monitoring.
- Cycle computer illumination LED.
- Two status LEDs.
- Two buttons for adjusting modes, switching on/off, etc.
- Brake lever sensor (switches the rear lights to brake mode)
- Software on/off.
- High-power software switched output driven by a MOSFET transistor. I will plan to use it for line lasers.
Todo
This is a work in progress. Here is the list of things I want to do and may indeed do some time in the future :-)
- Document the mechanical part (head light, rear LEDs, etc.). I am still playing with this, so I don't want to spend time on documenting the partial solution.
- Make the rear LED string - still not decided whether to use bare LEDs or encapsulate them in epoxy resin.
- Decide how to fix the photoresistor under the seat.
- Make the blinking pattern synchronous in order to not use the outputs in parallel, if possible. Also, this will allow to overcome the front LED instability when other outputs are blinking (using two modes for the front LED for each current value - i.e. 700 mA with other LEDs off, and 700 mA with other LEDs on).
- Make some use of ATTiny861a internal thermometer?
- Document the high-level view of the firmware.
News
- 2013-03-04
- Brake lever sensor added, increasing the complexity of the system even further :-)
- 2013-03-01
- I have soldered the components to the second board (the PCB service allows 10 boards minimum, so I still have 8 more to play with :-). Now I have one board for testing and development, and another one to be permanently mounted on my bike. The second board has stronger voltage regulator (MCP1703 instead of MCP1701) in order to be powered with a three-cell battery. I have also omitted the reversible fuse altogether - during my previous experiments I have discovered that the fuse is not the weakest link in case of problems :-).
- 2013-02-20
- I have decided on the purpose of the MOSFET-switched output: I plan to use it for line lasers (see the video).
- 2013-01-14
- I have replaced the photodiode with a 75K-5M photoresistor, which apparently has better characteristics for my needs. No changes to the PCB required.
- 2012-10-10
- I have solved the problem with unstable A/D converter readings when more than one output was on by adding low-pass filters from 220 nF capacitor and 1K5 resistor to each ADC input. Fortunately, this was possible without replacing the PCB (image on the right).
- 2012-10-29
- After thorough manual verification :-), I have sent the PCB gerber files to the fab. I have used iteadstudio 5x5 cm 2-layer service. Hopefully I did not miss anything important.
Source code repository
The project is licensed under GNU General Public License, version 2 (only). Here is the Git repository with schematics, datasheets, and firmware. You can browse the firmware source code (for Atmel AVR and GNU compiler toolchain), and schematics (designed using gEDA project). Feel free to send me comments, notes, or improvements. You can even clone the design and use it for your purposes, as long as the licensing conditions are met.
git clone https://www.fi.muni.cz/~kas/git/bike-lights.git
Schematics
The schematics has been designed using gschem from the gEDA suite, and is available here in the git repository.
PCB
These images have been generated by pcb program from the gEDA suite using this file.
You can also download the Gerber files with the PCB layout. These files are generated from the 2012-10-29 version of the source tree.
Design notes
- CPU
- Atmel Tiny861a AVR, 1.8-5 V power input, DIL-20 package, three PWM channels, 8 KB program memory, 512 B RAM, many ADC channels and general-purpose I/O pins.
- Step-down converters
- Driven by Microchip MCP14628 synchronous buck driver (one PWM input, drives two MOSFETs). MOSFETs are International Rectifier IRL6372PBF (two "digital" transistors in a single SO-8 package). Current regulation is done by measuring voltage on a 0.033 Ω resistor serially connected to the LED. For the 2500 mA converter, a large 220 μH/2.5 A coil is used together with 47 μF electrolytic capacitor; the ADC for regulation works in single-ended mode. For the smaller converter, a smaller 470 uH/450 mA coil and a 10 μF ceramic capacitor is used, and the ADC works in differential mode.
- Step-up converter
- The MOSFET (one half of IRL6372PBF) is driven directly from the ATTiny pin. The converter contains a generic Schottky diode, a 470 uH/450 mA coil, and a 10 μF ceramic capacitor. Current regulation is also done by measuring voltage on a 0.033 Ω resistor by ATTiny ADC in differential mode.
- Power regulator
- The power source for the CPU is made from Microchip MCP1710AT +5V 250 mA low drop out, low idle current regulator. The power source can be disconnected using a jumper in order to avoid power leakage to the high-current parts during the in-system programming, which has its own power source.
- Ambient light sensor
- 75K-5M photoresistor is used as an ambient light sensor. In order to remain under the 1.1 V (the maximum value of ATTiny A/D converter in single-ended mode), it is accompanied by two resistors, so the voltage range is between about 0.25 and 1 V.
- Battery voltage sensor
- Made from 1M5 and 100K resistors, read by a single-ended ATTiny ADC pin.
Handlebar switches
I wanted to add a brake lever sensor to the system. I have decided to use a Hall effect sensor and a magnet instead of a microswitch, because of its size. The problem was that Hall effect sensor needs constant current in range of miliamperes, which goes against my "software power-off" design. So the power to the sensor has to be provided by an ATtiny pin. However, I have only three wires for the handlebar connector on my board (GND, PA3, and PA4). Since the PA4 pin can also be used as A/D converter, I have decided to read the two buttons and the brake lever sensor using this ADC port, and use different voltages to distinguish between the switches. This way I can on-demand power the Hall probe using the PA3 pin, and even use one of the switches for waking the system from the sleep. The schematics is as follows:
I use Honeywell SS341RT unipolar Hall probe, and a small (1x2 mm) neodymium magnet, which is the fragment of the magnet from the broken hard drive. The switches handle the following states:
- When the system is off, PA3 is in third state, and PA4 has an internal pull-up resistor enabled, and S1 can wake the system up using PCINT4.
- When the system is on and I want to read the state of the switches and
the Hall probe, I can configure PA3 as output and set its state to logical 1.
- When PA4 in the digital input mode reads as one, all switches are off.
- When it reads as zero, I can switch PA4 to the ADC mode and read the voltage, which gives us the state of switches and the Hall probe.
Links, resources
- Mark Haun's LED bike light - a similar project to this one; for one LED, with a different step-down converter chip, creative-commons
- Buck converter page at Wikipedia
- Boost converter page at Wikipedia
- MCP 14628 synchronous buck driver datasheet
- ATTiny861a datasheet
- AVR libc homepage
- Kamil Řezáč's AVR Bike Light project has its pages on SourceForge and on Google Code.