Recently, my friend asked me to build him a circuit to flash his brake lights twice quickly, then stay on, each time he hits the brake pedal. Originally, he said the flashes should be on and off for about half a second, but he was modeling his desires off the brake lights on a fire truck and his measurement of time is terrible. In actuality, he wants them to flash around 20-50ms each. I threw together a circuit on a breadboard, using a switch to emulate the brake pedal and an LED to emulate his brake lights. Originally, I also tried to design it under the presumption that the lights should flash at about 200ms or so, expecting that his original estimate was a little bit slow. I only have a hand drawn schematic of my circuit, and no way to scan it, so I will try to explain it as best as possible. His brakes are active low, so I have the switch grounded, with the other side connected to the trigger of a 555 configured as a monostable pulse with a duration of about 50ms. The trigger is usually held high by a 10k resistor. The output of the 555 is connected to a voltage divider that puts out about 6V, which is fed to the gate of a 2n7000 NMOS. The drain is at 5V, and the source is grounded through a 1k resistor. The output is taken off the source, and connected to the arduino pins 2 and 3 for interrupts. (I know I could have used only 1 interrupt that triggered on change, but I am not experienced enough with programming these and felt more comfortable using two seperate interrupts). I checked the voltage on the input when the switch was open and closed, and the levels are .03V and 4.8V. The output from the arduino is taken from pin 12, through a 10k resistor, to the base of a 2n2222 BJT. The emitter is connected to ground, and the source is connected to pin 85 of a standard 30/40A automotive electromechanical relay. Pin 86 is connected to +12V, and a flyback diode is placed between the two. Pin 30 of the relay is connected to +12V and pin 87 is connected to the load, in this case my led with limiting resistor. This is my code:
int relay= 12; //Output to relay
int time= 30; //Time pulse is on or off
volatile boolean able = 0;
void pulse(){
digitalWrite(relay,HIGH);
delay(time);
digitalWrite(relay,LOW);
delay(time);
}
void rise(){
able=1;
}
void fall(){
able = 0;
}
void setup(){
attachInterrupt(0,rise,RISING);
attachInterrupt(1,fall,FALLING);
pinMode(relay,OUTPUT);
}
void loop(){
while(!able); //Do nothing while waiting for brake to be pressed
pulse();pulse(); //Two Pulses
digitalWrite(relay,HIGH); //Then turn on
while(able); //Wait while brake is still depressed
digitalWrite(relay,LOW); //Turn off relay once brake is released
}
When I tested it with time=200, it worked perfectly every time I tried it, probably upwards of 100 times. However, when I brought it down under 50ms, sometimes when i pressed the switch, it would flash twice at 50ms, then come on for probably a few microseconds, and shut off, even though the switch was still depressed. If this were installed in a car, this would amount to the brake lights being off even though the brakes are depressed. Needless to say, this is an unacceptable condition. I don't have a scope to check out the voltage levels on the interrupt inputs, but I am guessing that for some reason the level is dropping for just long enough to trigger the falling interrupt that results in the relay turning off. Does anyone know of any hardware or software modifications I can make to remedy this situation? Any help would be greatly appreciated
