Introduction: Intelligent Tail Light
Some time ago the tail light of my bike stopped working. When I opened it, there was a small PCB with some electronics and a LED in it. The problem was the push button switch that did not function. I could have replaced the switch but something about this design disturbed me. The point is that the tail light is battery powered and once switched on, it stays on until you switch it off or when the batteries get drained.
Since I care about the environment I wanted a solution that did not drain my batteries if I forgot to switch the tail light off. So a new project was born.
This intelligent tail light has 3 main functions:
- Switch the LED on or off when the push button is pressed.
- Keep the LED on while the bike is moving and switch the LED off after 10 minutes if the bike is no longer moving.
- Switch off the LED when the battery voltage drops below 2.1 Volt.
For this project I reused a tilt switch from the Tea Light Clone project from which I also reused some of the software for this project.
As always I built this project around my favorite micro controller the PIC, using the JAL programming language.
Step 1: Required Components
You need to have the following components for this project:
- A piece of breadboard
- PIC microcontroller 12F615
- 8-pin IC socket
- Capacitor 100 nF
- Resistors: 2 * 10k, 1 * 100 Ohm
- High Brightness Amber LED or Red LED
- Push Button On/Off switch
- Tilt switch
See the schematic diagram on how to connect the components.
Step 2: Designing and Building the Electronics
The operating voltage range of the PIC is between 2 Volt and 5.5 Volt which makes it suitable using the 2 AAA batteries as power supply. The design had to be low power so the tilt switch is only active when the device is turned on by making pin 3 of the PIC low during operation.
In the original design, the current through the LED was 20 mA which is quite high for a high brightness LED and not needed. In order to save batteries, this design uses a current of 10 mA for the LED.
Since the PIC is put into sleep mode when inactive, the push button switch is connected to the interrupt PIN of the PIC to wake it up from sleep. In sleep mode the PIC uses almost no power.
The circuit was made on a breadboard which fitted nicely in the existing housing of the tail light. In the picture you can see how the board was set-up and how it fits in the housing.
Step 3: The Software
As already mentioned, the software is written for a PIC12F615 using the JAL programming language. The software performs a few tasks:
- Initialize the PIC and put it into sleep mode after power up.
- Wakeup from sleep when the push button is pressed and turn on the LED. Go back to sleep if the push button is pressed again. The wakeup is activated by the external interrupt of the PIC to which the push button is connected.
- When awake enable the tilt switch and monitor if the tilt switch is activated due to motion. If no motion is detected for 10 minutes, the LED is switched off, the tilt switch is disabled and the PIC is put back into sleep mode.
- When awake measure the voltage of the batteries and if it drops below 2.1 Volt the LED is switched off, the tilt switch is disabled and the PIC is put back into sleep mode.
Initially the software for the motion detection was designed using the Interrupt On Change (IOC) feature of the PIC but that did not work well. Instead, the switch is now polled every 100 us to determine if it was activated or not. The measurement of the supply voltage is done using the integrated Analog To Digital converter which samples the supply voltage every 20 ms.
The JAL source file and the Intel Hex file for programming the PIC are attached. If you are interested in using the PIC microcontroller with JAL – a Pascal like programming language – visit the JAL Website.
Have fun building your own project and looking forward to your reactions and alternative applications.
Participated in the
Arduino Contest 2019