Tenty LED Brake Lights





UPDATE:
     This project was so overwhelmingly well received that it has spawned a commercial interest.  The version available for purchase varies somewhat in it's flash patterns and also in the ability to record and play back your own flash patterns.  If you would like to check it out take a look at Betelgeuse - A Programmable LED Brake Lamp at my new company Lakeside Electronics, LLC.



I Purchased a motorcycle about two weeks ago.  Interestingly, whenever I tell someone this news, they immediately proceed to tell me the most gruesome injuries and stomach turning plights that they or someone they know, has fallen victim to while motorcycling.  In some cases, these raconteur's briefly pause to look over their shoulder, presumably scanning for small children or otherwise offendable ears, before delivering the goriest details.

One commonality in these stories, aside from the macabre and arguably poor timing involved in telling them to me is that many accidents come down to a lack of visibility of motorcycles and their riders.  Less than Argus-eyed motorists often pull out into the path of a motorcycle and with insufficient time for evasive action, that quickly an accident has occurred.  Other times, drivers may focus on the car ahead of the motorcycle and in the event of stopping at a red light or similar, fail to leave enough room for the motorcycle, unfortunately rear ending him or her.

In the photo below, you can see that I am in one piece and the bike is also.  Let's see what we can do to help keep things that way.




To partially combat the lack of visibility I decided to make a replacement brake light for my bike; one that would strobe briefly when I applied the brakes then stay solid on.  I got this idea when I noticed a similar strobing effect to the brake lights on an ambulance that I was following near to, but not immediately behind.  Those lights really got me to notice the ambulance which I had largely ignored up until that point.

I would also want a way to be able to disable the brief flash before the brake light stays solid on.  This could be useful if the flash was ever to cause a safety hazard to other drivers or if I am ever stopped by the police for having this system I can easily disable the strobe part and still have a functioning brake light; I do not want to be stranded.  I wrote the software so that if you turn the key on while you have the brakes applied, the flash is disabled.  You must turn the key off, then back on, without the brake applied to restore the flash functionality.

Here is a video of the prototype Tenty LED Brake Light installed and operating.  In the video, I demonstrate the flashing brake light 3 times and then key off.  Then I disable the strobing part by turning the key on while holding the brake on, demonstrate that several times and key off again.  Finally I re-enable the strobing functionality by key on with the brake off.  For the purposes of the video, I lengthened the duration of the flash on and off times.  This is so the camera can better capture the flashes.  




In order to keep this system reversible should I ever have the need to put it back to stock, here is how I mounted the circuit board inside the tail light lens.  I bought some replacement bulbs at a local auto parts store, broke out the glass and desoldered the filament.  I replaced the filament by soldering wires to the tail light power, brake light power and ground.  I ran a file over the solder blobs just enough to level them out so they would make good contact with the socket.  I then filled the bayonet base with epoxy and inserted an 8-32 stainless steel screw into the base being careful not to touch the screw to any metal,  accidentally making the screw a conductor.  Below are a few pictures of this process.


 



 After installing the modified bayonet screw mounts I threaded two nuts on each and jammed them together.  This is what the back of the circuit board will rest on.  You can see several pictures of the final assembly below.











Circuit:

The circuit is basically a large array of really bright red LED's ( Light Engine ) and an ATTiny85 microcontroller to tell the LED light engine how to behave.  There are also two high brightness LED's that shine downward onto the license plate.  They are solid on all the time as required by the Michigan vehicle code.  The red LED's, made by Optek have a 100 degree viewing angle and output 8000 mlm each - there are 16 of them.  The brake light switch delivers it's ~12 V signal translated thru an 2n3904 transistor to pull a microcontroller pin low.  I usually use 14.4 V when doing calculations for operating voltage on 12V systems like this.  Total current draw with all LED's at maximum brightness is less than 500 mA.  I ordered the logic level mosfet IRLU3410PBF from mouser.com also, which is used for the PWM control of the light engine.  Below you will find a screen cap pic of the schematic.





Software

There are two modes of operation to this brake light - flashing and non flashing.  The non flashing brake light is activated by turning the key on while holding the brake and behaves just like a stock brake light would.  Flashing mode is enabled by default so key on with brake off and you are good to go.  In this mode, the LED light engine strobes briefly upon initial application of the brake then is a steady on light.  I set the period of the flashes to be higher for the videos so the camera could pick them up, you can see in the code below that the flash period is twice as fast in the operational version of the software.  Feel free to use the code as you see fit.


/*
Program Description: 

This program controls an LED light engine used as a brake light on a motorcycle.
When the brakes are applied the tail light flashes several times off then on before
being a steady on brake light.

The program also has a feature to disable the flashing brake light and the brake light will
behave like a standard lamp ie no flashing.  This mode is enabled ( flash mode disabled )
by turning the motorcycles key on while holding the brake on.  The state is reset after a power 
cycle.

Legal Note:  I read the entire vehicle code for my state.  It does not address brake light flashers, but
does prohibit " rotating, oscillating or flashing red lights ".  I believe a brake light flasher
differs from " rotating, oscillating and flashing " lights in the implied duration of operation.  
My state did not respond to emails I sent requesting clarification.  
Basically, modify your vehicle at your own risk.

Change Log
2012.4.21 - added 1 mS debounce to brake switch in main loop - Pete


A circuit description and other details can be found at http://petemills.blogspot.com

Filename: led_brakelight_main.c
Author: Pete Mills
petemills.blogspot.com
2012.4.15

Int. RC Osc. 8 MHz; Start-up time PWRDWN/RESET: 6 CK/14 CK + 64 ms

*/



//********** Includes **********

#include <avr/io.h>     
#include <util/delay.h>   



//********** Definitions **********

// Output to LED Light Engine

#define LED   PB0  
#define LED_PORT PORTB
#define LED_DDR  DDRB


// Input for Brake Switch

#define BRAKE_SWITCH  PINB4  // bit is clear when brake switch is pressed
#define BRAKE_SWITCH_PORT PINB
#define BRAKE_SWITCH_DDR DDRB



// PWM Preset Values

#define TAIL_LIGHT_PWM  25
#define BRAKE_LIGHT_PWM  255



//********** Function Prototypes **********

void setup( void );
void brake_alert( uint8_t number_of_flashes );



//********** Global Variables **********

uint8_t disable_flash = 0; // if 1, the flashing part of the brake light will be disabled


int main(void)
{


setup();

_delay_ms( 5 );



// if the brake light is held on during boot up, disable the flashing
// flashing can only be disabled during boot up ( key on ) and is reset after power down ( key off )
// this could be useful if you suddenly learn your flashing light is causing a problem for other motorists 
// or citizens employed to monitor the adherence to legislation and cite violations for deviation from such 


if ( bit_is_clear( BRAKE_SWITCH_PORT, BRAKE_SWITCH ) )
{
 disable_flash = 1; 
}



 while(1)
 { 
  
  
  if ( bit_is_clear( BRAKE_SWITCH_PORT, BRAKE_SWITCH ) )  // if the brakes are applied
  {

   _delay_ms( 1 ); // filter time aka debounce

   if ( bit_is_clear( BRAKE_SWITCH_PORT, BRAKE_SWITCH ) )  // if the brakes are actually applied
   {  

   // if we are allowed to flash, do
   
   if( disable_flash == 0 ) 
   {
    brake_alert( 5 );
   }
  

   // if the brakes are still applied, hold the LED light engine to a brighter output
   // until you release the brakes
   
   while( bit_is_clear( BRAKE_SWITCH_PORT, BRAKE_SWITCH ) )
   {
    OCR0A = BRAKE_LIGHT_PWM;
   }
   
   _delay_ms( 100 ); // debounce the brake switch release ( break )
   
   }   

  }
  
  OCR0A = TAIL_LIGHT_PWM;  // restore the tail light on
  
  
  
  /*
  // demo mode
  for( ;; )
  {
  brake_alert(6);
  OCR0A = BRAKE_LIGHT_PWM;
  _delay_ms(2000);
  OCR0A = TAIL_LIGHT_PWM;
  _delay_ms(4000);
  }
  */
   
 }
}




//********** Functions **********

void setup(void)
{



 //********* Port Config *********

 LED_DDR |= ( 1 << LED);   // set PB0 to "1" for output 
 LED_PORT &= ~( 1 << LED );   // turn the led light engine off

 BRAKE_SWITCH_DDR &= ~( 1 << BRAKE_SWITCH );   // set BRAKE_SWITCH pin to 0 for input
 BRAKE_SWITCH_PORT |= ( 1 << BRAKE_SWITCH );   // write a 1 to BRAKE_SWITCH to enable the internal pullup



 //********** PWM Config *********
 
 TCCR0A |= ( ( 1 << COM0A1 ) | ( 1 << WGM01 ) | ( 1 << WGM00 ) ); // non inverting fast pwm
 TCCR0B |= ( 1 << CS00 ); // start the timer
 
 
}




void brake_alert( uint8_t number_of_flashes )
{
 // here we create a visual alert that the brakes have been applied
 // pass this function the number of flashes desired ( off then on = 1 )
 
 //uint8_t delay_between_flashes = 50; // for video demonstration purposes ( video aliasing issues ) 
 uint8_t delay_between_flashes = 25; // every day use
 uint8_t alert_pwm_min = 2;   // minimum and max values to flash between during the alert
 uint8_t alert_pwm_max = 255;
 
 
 for( int i = 0; i < number_of_flashes; i++ )
 {
  OCR0A = alert_pwm_min;
  _delay_ms( delay_between_flashes );
  OCR0A = alert_pwm_max;
  _delay_ms( delay_between_flashes );
 }

}


Legal Note:

I'm not too sure what to say about the legality of this project.  I read the entire vehicle code for my state.  There was no reference to brake light flashers for cars or motorcycles.  The vehicle code for Michigan does prohibit " rotating, oscillating or flashing lights " on non-emergency vehicles, however I believe my brake light does not qualify as the clear intent in the vehicle code was " rotating, oscillating or flashing " lights that continue to do so for an extended period of time as emergency or police vehicles do. Really, my device is no different than tapping your brake pedal several times before stopping your motorcycle.  In the end, I did send an email to the state of Michigan requesting clarification.  At the time of this writing there has been no response.  I think the bottom line is, don't modify your vehicle unless you are willing to accept full responsibility for any outcome.


Here are a couple pictures of the build process.  The abstract looking pictures are of the LED light engine shining thru my desk magnifier onto the ceiling.







Comments

Anonymous said…
Nice work. Increasing visibility is key for surviving on a motorcycle as well as wearing the right protective gear.

Consider a headlight modulator as well as good protective gear.
Anonymous said…
You usually won't have a problem at night. your bigggest concern should be at daytime.

but that break strobe made me put that mod in my to-do list! damn you
Derek Vance said…
This comment has been removed by the author.
Derek Vance said…
I live in michigan and I have flashing taillights. Technically you cannot have constantly modulating taillights, but you can flash them or fire the LED's in a certain order so that you can gain better attention from the person behind you. (IE flash for 3 seconds and then they stay solid)
Anonymous said…
I often pulse my brake while stopping & at the stop light (on a highway feeder stopped @ light and no cars are behind me)

While I REALLY want the modulator that does this for me (you can buy a harness thats practically PnP) My hand does a cheaper job ^_^
John said…
I'm in MI also. When I bought my used Goldwing it had an extra breaklight bar mounted below the trunk worked the same way. 3 flashes, then solid. Rode it for about a year with no police issues. The lens decided to fall off on the highway and got run over after about a year, so I had to remove it. Thinking about making one of these to replace it. The factory brake light is kind of buried on my wing.

Nice write up. Now you have me thinking about turn signals too. Maybe tri color Gr/Yl/Rd leds for yellow turn and red brake when the turn isn't activated. Have to do some thinking on that.
Andrei said…
Nice!
I think I'm going to copy your concept and adapt it for my bike.

If you have easy access to your tail lamp, I would take a Sharpie, either red or black and go over the board. That way it will show less while the lamp is off :)
Wood said…
This comment has been removed by the author.
Wood said…
Legal in VA - http://leg1.state.va.us/cgi-bin/legp504.exe?000+cod+46.2-1012
Winter said…
Hi - I am thinking of doing something similar but based on an Arduino / ATMega. I am only just getting started in the world of micro controllers and I havent ever done much with IC's / transistors. I understand all the basics but I am not sure how you come up with the resistor values etc. I was wondering if you get a chance would you explain the methodology you went through int he circuit design. The Arduino has PWM capabilities so I was wondering of I would need the logic level mosfet you have used. Any advice / help would be greatly appreciated as I want to build one for my Speed Triple and VFR800 !!
Pete said…
Hello Winter,

I think porting the brake light project to an arduino would be a great project! Provided that your bike is also a ~12 v system you could just replace the ATTiny85 I used with the ATMega running the arduino boot loader. You can probably sort out that you need to connect the ATMega pins appropriately, connecting the ATMEGA PWM output pin of your choice to the logic level mosfet in the original schematic.

One improvement for this circuit would be to replace T1 ( 2n3904 transistor ) with an optocoupler. I didn't have any at the time but have since purchased these and will install one when I have time. http://www.sparkfun.com/products/314

I have also added a 0.1uF electrolytic capacitor on the output of the 5 v regulator and this helps keep the power supply stable during transient responses.

When you write your code keep safety in mind. The same is true for making the hardware. A brake light is an important device that must be 100% reliable.

If you have any questions feel free to email.

Best of luck and let me know how it turns out!

-Pete
Unknown said…
Nice backlight.
Just did the build my self for my Ducati 900ss, and it all worked out great, thx to the pictures on your site, and the code.

Pictures can be found here:
http://juelsminde.org/?p=6&lang=en-us
Pete said…
Nice Work, Lars!
McNor said…
This comment has been removed by the author.
McNor said…
Hi Pete, Nice DIY...do u make and sell the kits,
im not very good in software programming, just a little bit knowledge of soldering component here and there..
But im not intend to install it on my bike but i want to install it on my car...not just the 3rd brake light but also the Left/Right brake light.
1 kit is enough but it may take to many wire..so prefer 2 kits for each L/R brake light..independantly.

Just my opinion.

Im from Malaysia BTW.
Pete said…
Hi McNor,
I do not sell kits for this brake light, but I did recently release a similar product for sale here.

http://lakesideelectronics.net/?wpsc-product=betelguese-a-programmable-led-brake-lamp

Good luck with your project. It sounds like it will look very cool!

-Pete
Greg M said…
Great project! Thanks for posting this.

I adapted it to fit my Yamaha VStar.

I also used my arduino uno to program the tiny85.
Pete said…
Awesome job Greg! I uploaded your pics here http://petemills.blogspot.com/2012/08/more-flashing-brake-lights.html
Unknown said…
Did you use any protection for voltage spikes?
Unknown said…
Did you use any voltage spike protection?
Pete said…
Hi Anthony,

The bikes existing electrical system does a pretty good job of smoothing out any voltage ripple or spikes so no additional protection was employed. Of course, as you saw in the schematic, there is a voltage regulator for the ATTiny85.
Anonymous said…
Hi Pete ~

I'm glad I came across this site. I made this my first real electronics project and built a version of this circuit for my Yamaha WR250X. I learned tons about programming for an Arduino and even loaded my code to an ATTiny 45. It works awesome!!!

Thanks for the inspiration.

MarkC
Anonymous said…
Hi Pete,

I very new for electronic.

Your project is great. I try to do it . It work OK on breadboard but not work on my small honda bike 125 cc.

I measure voltage from engine is around 4-5 V. Voltage signal from brake is 12 V.

Could you advise how should I do . Thank in advance.

:) Krit
Pete said…
Hi Krit,

Congratulations on getting your circuit working on the bench!

I am not sure where you are measuring the 4-5 V power from, but the circuit I designed will need at least 7 volts to run reliably.

I know some motorbikes don't have alternators and rely on other means of generating very noisy electrical power.

Perhaps if you find the source of the 12 V brake light signal you will find a suitable power supply.

Best of luck!

Pete
Anonymous said…
Thanks Pete.

Krit
Bill said…
Thanks for posting your build. I am a electronics noob. In your diagrams, what is IC1?
Pete said…
Hi Bill,

IC1 is a 7805 voltage regulator. Good luck with your project. Write in when you get it done!

-Pete
Bill said…
Ah that's what I thought from looking at your pictures. Does the 7805 generate much heat?
Pete said…
Hi Bill,

A 7805 is capable of generating enough heat to trip its internal thermal limit and shut itself down prior to damage.

This occurs when we are regulating high currents from high voltages.

To combat this you would put a heat sink on the 7805 to keep it cool.

Basically I try to keep most things below 50 deg C.

So, lets take a look at the LM7805 datasheet. It says it has a thermal resistance for junction to air of 65 deg C per Watt. This means that if ( (input voltage - output voltage) * output current * 65 C/W + ambient Temperature > 50 C we will use a heat sink.

For example ((9vin - 5vout) * .1A * 65c/w) + 21c = 47 deg c. So, we are ok if we don't go above 9v input with 100 mA output current.

-Pete
Bill said…
Looks like I will need a heatsink being the bike is 12v. Last time I used a 7805, it was hooked to a computer PSU 12v and it burnt my finger when I touched it. I was not sure if it would dissipate heat efficiently closed up in the light assembly.

What are your thoughts on using this to replace the 7805: http://www.adafruit.com/products/1065
Pete said…
Hi Bill,

The regulator you linked to would be good for higher current projects. This circuit uses very little current on the 5 V supply. All of the LED current is supplied directly from the vehicle battery.

Please forgive my prior example. I chose poor numbers to illustrate what is necessary, so let me try again.

Since your alternator runs at about 14.4V and the only current on our 5V rail is the AVR which we will say is (much) less than 1mA we can calculate: ((14.4 V - 5 V) * 0.001 A * 65 c/W ) = 0.61 C temperature rise.

You are fine to use a 7805 here on the nominal 12 V motorcycle battery. I suspect when you had a hot 7805 before, you were passing a lot more current thru it...
Bill said…
Ah.. thanks for the clarification. Yes I was passing a lot of current through it when it got hot.

I am also a new motorcycle rider, I will building for a 2004 ninja 250. The LEDs are on back order.. hopefully I'll get the items soon.
Anonymous said…
Hi. Did you use an arduino boot loader on the attiny85?

Thanks
Pete said…
Hi Anon,

I did not use an arduino bootloader.

-Pete
Pete said…
Hi Bill,

That is a nice bike you have. Be sure to send some pictures when you get your tail light done. I'll post them up here.

Ride safe!
-Pete
Anonymous said…
Hi Pete and thank you for the quick response. What type of programmer did you use?

Thank you, Fred
Pete said…
Hi Fred,

I use an ATMEL AVR ISP MK2 and avrdude.

-Pete
Anonymous said…
Thanks Pete. Do you think your sketch will work with the Arduino ISP as the programmer instead of the Amtel programmer or would I have to make changes?

Fred
Pete said…
Hi Fred,

I am not sure if you are asking if my program will work on an ATTiny85 with arduino bootloader or if you are asking if you can program a bare ATTiny85 with my code using an arduino as an ISP.

The answer to the former is simply, no. The slightly longer answer to the latter is: I think so, but I have never done it."

I suspect that if an arduino can be used as an ISP to burn a boot loader ( and I believe it can ) that it can probably be used to flash "tenty brakes" to a blank AVR as well.

If you dont find a definitive answer, email me and I can send you a programmed ATTiny85 if you like.

-Pete
Bill said…
I also will be attempting to program a bare ATTiny85 using an arduino as an ISP. I have never attempted this before. I have an arduino and there seems to be a lot of tutorials using it as isp through Linux.
Anonymous said…
Thank you Pete. That is a very generous offer. How can I take you up on receiving the pre-programmed sketch?

Fred
Anonymous said…
Hi Fred. Curious with another question: in your schematic on JP1 you show a different pin out then the MKII. Is there something your circuit requires different than the standard MKII pinout. Thanks agin for all your responses.

Fred