Intelligent Tail Light

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:

  1. Switch the LED on or off when the push button is pressed.
  2. Keep the LED on while the bike is moving and switch the LED off after 10 minutes if the bike is no longer moving.
  3. 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.

Arduino Contest 2019

Participated in the
Arduino Contest 2019

Be the First to Share


    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest



    3 years ago

    Well done! The thinkering of yours goes kind'f what I have made with them automatised lighting of a bicycle.
    Please visit my homepage at to see my solution to the agenda, or contact me by my e-mail:
    My "Light My Bike" is way more intelligent, (no affends here), but might inspirate you to go some steps futher with your own developement.
    I haven't made a instr. of the "Light My Bike", but I would gladly share a "total" concept of my work here, the schemas, layouts, program etc.
    P.S. The program is written for a microcontroller ST62xx and in Assambler,
    so the program itself propably does no good for anyone.
    Guess I'm gonna translate it to the ATtiny-84, (ATMEGA- family), written in C++ some day, when I'll run out of other projects be'ing actual for me right now).
    P.P.S Please comment on my "Light My Bike"


    Reply 3 years ago

    Hi Keslin,
    I did not see your comments (got no e-mail from Instructables). To answer your question. The light has to be put on (or off) by the push-button and it stays on when there is movement. I use only one motion switch for detection of motion. When there is no motion for 10 minutes it switches off. I was thinking of adding an LDR to measure the ambient light as for the device that it switches on automatically (so when there is motion and it is dark it turns on so I do not need an on-switch anymore) but I did not create that. Maybe something for later.


    Question 3 years ago

    Hi! I did read & re-read your instr. Ewerything was clear straight forward. Except for: In the picture you have 2 tilt-switches, (and only one lead coming to each of them?), and where do you attach them? And how do they function, (not the electrical, that I'm familiar with), but in use, e.g. do they be activated when you put your bice in a vertical pos.?


    3 years ago

    Way to keep this light in use! Thankls for sharing your circuit too.


    Reply 3 years ago

    You're welcome.