NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Car brake lights circuit

May 07, 2011
by ToLazyToThink
ToLazyToThink's Avatar

My friend asked me if I could build a circuit for him that would have his car's brakes flash twice in rapid succession, then come on fully each time the brake pedal was pressed. The flashes should be somewhere in the range of 20-50ms each. I figured that such a task would be no problem for an ATMega, so I tried to think of a way to implement it. However, I am still very inexperienced with programming the chip, so my first implementation failed horribly. Using an LED as a test load, I tried it a few times and it worked as intended one out of every four or five times, so I scrapped that design and am back to the drawing board. Can anyone provide any insight into a hardware and software design to interface with a 12V(14.4V when running) car electrical system that will accomplish this task? I would like for this project to remain as inexpensive as possible, but if I do install this in his car, it will need to have an absolute 100% success rate, so any hardware to increase its reliability is acceptable. Any help would be greatly appreciated. Please let me know if I have not been clear enough about the intent or specifications of my circuit needs.

May 07, 2011
by Ralphxyz
Ralphxyz's Avatar

ToLazyToThink, one of the first lessons of life is "If you can not sue your friends, then what good are they?"

Your best intentions and friendship mean absolutely nothing to a insurance adjuster to say nothing about the lawyers <-- plural(s).

It's a bigger world than just you and your friend. Liability, even if what you do worked perfectly, if the car was in a accident ...

Lawyers Lawyers Lawyers Lawyers Lawyers Lawyers Lawyers


But we can certainly help you with your LED blinking code. So why don't you post what you have, even if it only sorta worked occasionally.

Ralph

May 07, 2011
by avr
avr's Avatar

Having the lights flash for every stop is non-sensical, and it could even break the law.

BMW and Mercedes have developed better systems, termed Adaptive Brake Lights.

eg: in the BMW 5 series "Available in the new 5 Series, Adaptive Brake Lights are designed to reduce the risk of bumper-to-bumper collisions by enlarging the brake light area when the driver forcefully applies the brakes.".

ie. more brake lights come on in an emergency stop.

eg: in the Merceds B class: "... the B-Class features adaptive brake lights as standard: in the event of an emergency stop from a speed of more than 50 km/h, the brake lamps start flashing several times a second so as to warn any vehicles behind, thus shortening their stopping distance decisively. If the B-Class is braked to a halt from a speed of 70 km/h or more, the hazard warning lights are activated automatically, giving you an extra level of protection."

May 07, 2011
by SpaceGhost
SpaceGhost's Avatar

I agree with these guys - This idea could be in violation of the law. I would check this with your state and local law enforcement agencies.

However if you want to program your MCU so that when you push a button an LED would blink twice then stay on until the button is released, that would be fairly easy to do. I have a process in mind that I know would do this...

Blinky lights are a lot of fun. Botched or illegal brakelights are not!!

Like Ralph said, post your code. You'll find here that you're more likely to get help if you post what you have, to show that you at least tried. But only please, if you are just interesting in figuring out then demonstrating on your breadboard how something like this might work.

I would post my solution to the problem only if you promised not to try to implement it into a vehicle brakelight system. I don't wanna get sued either!

May 08, 2011
by mongo
mongo's Avatar

I have seen the flashing brake lights on certain vehicles in my area. Usually school buses and emergency equipment. When they first hit the brake pedal, the lights flash a couple of times very brightly and then stay on solid after that. I think it is to get the attention of people behind them to let them know that the brakes are in operation. It seems that the flash might be more of a distraction that a help though. I also have seen the reactions to other cars in the vicinity do some things like sudden lane changes and panic braking as a result of the flashing.Some folks just have a funny way of handling flashing lights.

May 08, 2011
by Ralphxyz
Ralphxyz's Avatar

Darn I was thinking about something like what BMW is doing 5 years ago, before I got my Nerdkit so I didn't have any idea how to do it.

Now mmmm'm. I know there are add on third party light kits one can buy from the automotive parts stores.

So what if we came up with a supplement light kit?

I was thinking about a rotating led display that would speed up the harder you pressed on the brake.

Adding more brightness (more leds) would fit in nicely.

The interface to the braking system would be the hard part.

What about using the vehicles OBD-II signal? I'll bet there is a brake pressure module in there.

I just got some mcu's to look at the CAN (OBD-II) bus now I have more to look at.

Ralph

May 08, 2011
by ToLazyToThink
ToLazyToThink's Avatar

Thank you all for your quick replies. Most of the motivation for me to undertake this project was to see if I could actually design a finished product, not to install it in his car. He very clearly understands that it will not be installed until(if) he verifies that it is legal in regular vehicles. Likewise, it will not be installed until I have verified that it works under all operating conditions of the vehicle. Most importantly, it will not be installed until we have some type of legally binding agreement absolving me of all responsibility and liability for any damages. Those were the first considerations I thought of when he first proposed the idea, and I never intended to put it in a vehicle before they were dealt with.

That being said, the setup my friend wants to emulate is the brake lights on some of the fire trucks in our town. As mongo said, the idea is to get drivers attention by very quickly flashing the brakes before coming on fully. He already has a multitude of blue lights and strobes, but he can only use them while responding to an emergency, and would like to have these brakes for every day use.

The code I came up with was basically the sample code for blinking an LED with a lot more if statements. However, I deleted it, perhaps too hastily, when it didn't work. One of my friends told me I should be using interrupts to control it, but i have no idea how to implement an interrupt properly. I have a circuit schematic of what I did, but I do not know how to attach a picture on this forum.

SpaceGhost, what you propose sounds perfect. Could you post the code to get an LED to blink twice then stay on for the duration of the button press? Perhaps after seeing one way to make it work, I will be more prepared to come up with my own implementation.

May 08, 2011
by SpaceGhost
SpaceGhost's Avatar

Well, okay - to simply cause an LED to blink twice then stay on for the duration of a button press, I did it like this:

#define F_CPU 14745600

#include <stdio.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"

 int main() {
    // fire up the LCD
    lcd_init();
    FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
    lcd_home();

  DDRC |= (1<<PC0);   // Set PC0 (pin 23) as sourcing output for LED

  DDRC &= ~(1<<PC5); // set PC5 (pin 28) as pushbutton input (sink input)

  PORTC |= (1<<PC5); // turn on internal pull up resistor (pin 28)

// declare the variable to represent pushbutton input

  uint8_t on;
  uint8_t j;

  j = 0;

while(1) {

    on = (PINC & (1<<PC5)) >> PC5;

    if (on == 0) {

      j = j + 1;

      if (j > 3)

      j = 3;

      delay_ms(250); // delay

      lcd_line_one();
      fprintf_P(&lcd_stream, PSTR("%u "), j);

    if (j < 3)

      PORTC |= (1<<PC0); // LED on

      delay_ms(125);

      PORTC &= ~(1<<PC0); // LED off

    if (j > 2)

      PORTC |= (1<<PC0); // LED on

    }

    else {

      j = 0;

      PORTC &= ~(1<<PC0); // LED off

    }

  }

   return 0;

}

I'm sure there are a number of different ways to do this.

By playing around with the delay times you should be able to customize the blink rate to your liking. I added the LCD fprintf_P function to give a better visualization of what's happening, but of course it is not needed to actually control the LED.

Does anyone want to show another solution?

Dave

P.S. to Rick - I sure get a lot of mileage out of that counter program you taught me, don't I? lol

Post a Reply

Please log in to post a reply.

Did you know that NerdKits has been featured in the MIT Undergraduate Research Journal? Learn more...