7

I'm rather new to logic circuits and I'm trying to figure out which component I need to complete my project.

I'm attempting to make a backup/reverse camera. When I shift into reverse, 12V is sent to the reverse lights. I'd like the Pi to display it's camera feed onscreen when that reverse light is turned on.

I understand that automotive circuits are very noisy, but tests so far show that in my car, the voltage sent on this particular circuit is very clean, never going +/- more than 0.15 volts.

I need my Pi to be able to detect when that circuit is hot, and a Python script I've written will display the camera feed when it detects a 'HIGH' signal, and close it when on 'LOW'. However, I'm aware that the GPIO pins can only handle up to 3.3V, so I can't just hook the Pi up in series.

What components would I need to add so the Pi can detect the closed 12-volt circuit safely, without lowering the voltage to the light? Specific product recommendations aren't necessary.

  • 1
    If ground can be shared, a simple resistor voltage divider (4:1) in parallel with the light bulb will work fine for detecting 12V signals . But this question has probably been asked and answered here and on electronics.se before, if you search . There are many other approaches with varying degrees of isolation, safety, and complexity. The next step up is an open collector buffer like the trusty 7407 or an opto-isolator. – crasic Mar 15 '18 at 14:49
  • A Zener diode would help to protect the circuit. – MatsK Mar 15 '18 at 15:07
  • 1
    Please note that a 12V source may be quite a lot more than 12V if it is not regulated. You need to take this into account if you choose the resistor divider option. – joan Mar 15 '18 at 15:56
  • 1
    @joan Yes, thank you for mentioning that. The 12V source is regulated on this particular circuit, along with fuse protection. – Moses Mar 15 '18 at 15:58
  • It is a bad idea to implement either of these solution in an automotive circuit. This question is beyond the scope of rpi.se – crasic Mar 15 '18 at 17:24
16

A very secure solution uses an optocouple. A 1kΩ resistor is good for an input voltage range of 5 to 20 volts. You may connect the two grounds, but it's not required.

The output is inverted, that means, the Pi senses low on its GPIO if there is 5–20V on the input, and high if not.

schematic

simulate this circuit – Schematic created using CircuitLab

  • 5
    As the OP is monitoring a light bulb circuit it might even be possible just to use a photo-transistor. Then the Pi would know if the bulb died. – Chris H Mar 15 '18 at 16:53
  • 2
    That's also a good idea. Maybe do both to tell the two cases apart. – Janka Mar 15 '18 at 16:55
  • If it helps, my project is essentially activating the Pi's camera display when my car's reverse lights are turned on. Backup camera. – Moses Mar 15 '18 at 17:10
  • 6
    @Moses Wow, uh, big difference in information. Automotive voltage is not 12V because its particularly noisy. Auto-grade components usually need to be tolerant to 45-60V due to spikes from alternator/starting/inductive components. – crasic Mar 15 '18 at 17:23
  • 1
    Also, in cars often enough not the positive but the negative terminal is switched. – Janka Mar 15 '18 at 17:32
5

Use a voltage divider to monitor the 12V at the light bulb. Make the resistors large enough that they do not significantly affect the bulb. A 3K resistor for R1 and a 1K resistor for R2 divide the voltage by 4, giving you 3V at Vout when powered, and a 1K pulldown to GND when the switch to the light is open.

enter image description here

EDIT:

Note that the question was changed from "how to detect 12V turning on a light bulb" to the current question about doing so for a backup bulb in a car. Other solutions are better for an automotive environment.

  • Thanks! If I'm understanding this correctly, V-in in this diagram would be the 12-volt circuit being monitored? Does the Pi need to share ground with the 12-volt circuit? – Moses Mar 15 '18 at 15:14
  • Yes and Yes. Currents need loops to flow and the common ground completes the loop. – crj11 Mar 15 '18 at 15:17
  • 1
    Personally I'd increase the values by a factor of 10. Moreover consider that Vin can range from 16 to 8 in the worst conditions, and that there are spikes much higher during high noise phases (e.g. crank). So... Put at least a schottky diode towards the 3.3V rail or a zener diode to clamp at 3.3V, or be prepared to change the rPI soon... – frarugi87 Mar 16 '18 at 8:11
  • 2
    This will not work as intended. The battery voltage in a car is far from well behaved. Automotive parts need to withstand spikes of several tens of Volts. This circuit will just burn the RPi – Vladimir Cravero Mar 16 '18 at 13:32
2

I'd suggest just a simple transistor and 2 resistors. Wire the transistor as open collector, with the collector pullling the Pi input to Gnd when 12V is applied to the base. One resistor pulls the collector to 3.3V. The other resistor limits current flow into the base from the 12V source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.