I'm buiding a board that needs to "read" the rear lights of the car. So basicaly, I want to connect the Left and Right Flashers, Brake, Tail and Reverse light to the arduino to get their status (on or off) and from there, different actions will be done.
Is it as simple as using a 12v to 5v transistor and maybe put a Cap. on the + just to filter the output??
In a car, you should be very carefull with the voltages. I read once that the voltages can have peaks to 60V.
You better use optocouplers. That is in many ways much safer, especially in a car.
I am using this to detect a running bicycle generator. It should withstand voltages up to 60V.
The output is active low. The capacitor at the output leads to a delay of about 200ms, you may want to make it smaller maybe
Normally you can use relays in series with the lights to turn on the switches which arduino can detect through the digital pins. I recommend a 12v SPST relay but beware when the engine is running because while the alternator is spinning the voltages will increase from 12 to 14V. The reason: The alternator has to provide more voltage than the battery's nominal voltage to charge while running. You can wire the 3.3V line through the relay switch input and then into the digital inputs (not the ones marked with ~).
From what I am seeing you are trying to build a continuity status to display if the lights are working or blown. I would consult the owners manual to your car to find the appropriate wires to add the relay in series.
Also beware when the relays are on because it may blow the fuse supplying the signal to the lights.
An alternative is to add Optocouplers( as Peter_n stated).These are very similar but it uses a LED and a photo transistor in place of the coil and switch.
P.S: you must add a diode in parallel to the relays but backwards to prevent voltage spikes from the induction coil inside the relay(1N4007 diodes are sufficient) .
I don't think you can put relays IN SERIES with the bulbs. This would certainly "choke" the bulb because the resistance of a relay is too high.
If you want to detect wether the bulb is drawing current or is blown, you may put a resistor of 0.1 Ohm or 1 Ohm in series and detect the voltage drop thru an analog input
Either that or have a high voltage capable transistor( such as a IRFZ44E with a maximum voltage of 60V) to switch the relay from the battery supply. Adding an extra resistor will just dim the bulb more but I see your point.
If you just want to detect whether there is 12V connected to the bulb (not whether the bulb is actually working), and the Arduino has a common ground with the car, then you just connect each 12V signal through a resistor to a digital input. Use a resistor value of at least 100K. This will keep the current into the processor pin protection diode below the 1mA maximum advised even for input transients of 100V.
If you are not sure whether the Arduino has a good common ground with the car, then use opto isolators.
...you just connect each 12V signal through a resistor to a digital input. Use a resistor value of at least 100K...
This is a lot simpler than the opto-coupler or relay ideas.
I was thinking a voltage divider with something like a 5.3V Zener to protect against spikes. But if this resistor method is safe, I like it better.
This method exceeds the "Absolute Maximum Ratings" chart under "Voltage on any Pin except RESET with respect to Ground".
I knew about the protection diodes because I have overloaded them before, with not-so-good results to my project. I hadn't thought to look at the specs and actually use them as a feature instead of protection.
Where do I find this 1mA maximum advised? Could I simply provide my own external protection diode with a higher current rating?
The 1mA recommended pin protection diode current maximum is unfortunately not published on the datasheet, it is in an Atmel application note about detecting mains zero-crossing, see http://www.atmel.com/images/doc2508.pdf.
You can add external protection diodes if you like, however if you want them to conduct the current in preference to the built-in pin protection diodes, then your external diodes should be Schottky diodes, so as to conduct at a lower forward voltage than the internal diodes.
I don't care about the bulbs, I just need to know if the car is sending 12v to them or not...
The solution with just a simple resistor seems easy however i'm concerned about sending directly the electricity without relay or transistors... kinda scared of blowing up my arduino!
dc42:
If you just want to detect whether there is 12V connected to the bulb (not whether the bulb is actually working), and the Arduino has a common ground with the car, then you just connect each 12V signal through a resistor to a digital input. Use a resistor value of at least 100K. This will keep the current into the processor pin protection diode below the 1mA maximum advised even for input transients of 100V.
a) How will this let you know when the bulb is off? The output to the bulb won't necessarily go to ground when the bulb is switched off.
b) If the bulb blows, the input to the bulb will still go high when it switches on. You need to measure current flowing through the bulb, not the voltage being applied to it.
Raiden38:
The solution with just a simple resistor seems easy however i'm concerned about sending directly the electricity without relay or transistors... kinda scared of blowing up my arduino!
a) A resistor divider will work and if you use high resistance values (eg. 100k and 50k) the current will be so small the Arduino can't be hurt. Something would have to go very badly wrong with the car electronics to kill the Arduino. The entire car would be fried. PS: Add a tiny capacitor across the Arduni input to avoid radio noise with resistors that high.
b) If you use a Pro Mini they cost $2.50 each - that's "disposable" in most people's books.
c) The only way to be 100% safe is to put a phototransistor next to the bulb and detect it using photons.
I am working a similar effort on connecting to a cars tail and turn lights. First you need to check on your cars light control. Many newer cars are not 12v on 12v off for lights but use PWM control so you would need to adjust for that in your design.
I had intended to run a opto-coupled SSR but but am on hold until I get readings from the light circuit on my MINI.