Car fog light turn assistant

My first project should be relatively simple:

L Indicator on - L fog light on (2 seconds delay after indicator off) R indicator on - R fog light on (2 seconds delay after indicator off)

Obviously there is no way Arduino could power car fog lights :-), so system will run on two relays (for L and R fog lamp) capable to handle 12V electric instalation.

Indicator circuits (L and R) would be equipped with a step down V regulator, to produce stable 5V to send signal to Arduino. This system must be reliable, as I intend to fit it ito my car!


I wrote my first advanced sketch 8):

int ledA = 8; int ledB = 7; int switchLeft = A0; int SwitchRight = A5;

void setup() { pinMode(ledA, OUTPUT); pinMode(ledB, OUTPUT); pinMode(switchLeft, INPUT); pinMode(SwitchRight, INPUT); }

void loop() { if (digitalRead(switchLeft) == HIGH) { digitalWrite(ledA, HIGH); } else { digitalWrite(ledA,LOW); }

if (digitalRead(SwitchRight) == HIGH) { digitalWrite(ledB, HIGH); } else { digitalWrite(ledB,LOW); } }

It is working! But not exactly as desired.

First of all - LEDs are staying on after removing 5V from: A0 - for 4 seconds - and for 2 seconds, after disconnecting A5 Second problem - even a simple finger tap at analog bank will start a diode (or both diodes) to switch ON.

Any ideas?

This is my second day of playing with Arduino - dont shout me if I've made some stupid mistakes....

All the best! Hants

You might be able to just use a voltage divider to bring the nominal 12V indicator signal down to the range the Arduino can handle. The only concern would be electrical noise on the car's 12V circuit, and you might find you need to use an optoisolator to keep that out.

Your code doesn't include any logic to time the LED signal outputs so it ought to just act like a couple of switches. Apparently it isn't, so I suggest you find out whether you're getting a correct reading from your switches before you go any further. You haven't enabled the internal pull up reistors and don't mention external pull up / pull down resistors so maybe your switches aren't wired correctly. The simplest circuit would be to connect one leg of the switch to the digital input pin and the other leg to ground, and enable the internal pull up resistor by a digitalWrite(switchLeft, HIGH) and similarly for the other switch input. This would give you a HIGH input value normally, and it would go LOW when the switch was closed. Your code to switch the LEDs on and off would need to reflect that logic.