0
\$\begingroup\$

There are certain lines in my car which I want to detect when hot. My initial thought was to hook a voltage divider to drop from 12v (or ~14 rather) to 3.3 and feed it to my pi but I soon realized that I'm probably going to have a bad time due to fluctuations and stuff.

Would it be enough of a safety precaution if instead I use an optocoupler such as 4n25 and feed the IRLED from the line I want to monitor via a 1.3k resistor to get about 10mA?

Additionally would changes in the voltage of the electric system (and therefore the line I'm feeding the LED from) cause changes in the voltage of the transistor side of the 4n25? Or in other words does the brightness of the IRLED(?) affect the state of the transistor or is it stable once it reaches a certain threshold?

\$\endgroup\$
4
  • \$\begingroup\$ What does feed the PI? If it is the same 12V battery the use of optocoupler makes no sense. \$\endgroup\$ – Huisman Apr 5 '20 at 20:31
  • \$\begingroup\$ @Huisman if you mean how I power it, with a buck converter from the car battery to 5v. \$\endgroup\$ – php_nub_qq Apr 5 '20 at 20:33
  • 1
    \$\begingroup\$ There are other means to protect your electronics. The same care you should take to protect the PI now applies to protect the optocoupler. So, I don't see a benefit in the use of an optocoupler. The real benefit a optocoupler gives is to provide galvanic isolation between 2 circuits. \$\endgroup\$ – Huisman Apr 5 '20 at 20:37
  • \$\begingroup\$ @Huisman so you mean there is no difference whether I'm going to use an optocoupler in my case or connect to the pi directly? \$\endgroup\$ – php_nub_qq Apr 5 '20 at 21:12
1
\$\begingroup\$

An optocoupler would provide quite a lot of protection from whackiness on the lines. Messiness on the input side of the opto could cause changes on the output side. But if this is a digital system it is probably not much of a concern because digital systems only care if you are above or below a threshold. If you are concerned, you could add a schmitt trigger on the output side for hysteresis. Note that the power on both sides of the opto has to be isolated too for the opto to provide any real protection.

\$\endgroup\$
12
  • \$\begingroup\$ I'm sorry but I didn't understand what is probably the main point in your answer - what do you mean the power has to be isolated? \$\endgroup\$ – php_nub_qq Apr 5 '20 at 17:33
  • 1
    \$\begingroup\$ It's also worth mentioning that the opto's LED is a somewhat sensitive device itself, so you'd need to design the interface to the opto to protect it from over voltage too. \$\endgroup\$ – The Photon Apr 5 '20 at 17:42
  • 1
    \$\begingroup\$ @php_nub_qq You can use a TVS diode anti-parallel to your opto to clamp voltage. Better if both are behind a resistor which you will probably have anyways to limit the LED current. \$\endgroup\$ – DKNguyen Apr 5 '20 at 17:48
  • 1
    \$\begingroup\$ If it's just to sens a voltage you can add a 22K resistor in serie with the pi input and a 3V zenner diode between the resistor and the input. The zenner is better than a voltage divider to prevent higher voltage. You can also add 14 or 15V varistor at the input (before the resistor) and at the buck converter. Also beware of reverse current. \$\endgroup\$ – Fredled Apr 6 '20 at 7:21
  • 1
    \$\begingroup\$ @php_nub_qq 1A diodes should be easy to find. There even 10A diodes. It doesn't have to be 15W. The voltage of the zener diode should be the same or just above the connected device, If the IRLED is taking 3V, take 3V zener. For the buck converter, a varistor is good, but a zener won't because it can't take enough current. The zenner must always be protected with at least 1K resistancem preferably 10K, it depends how much current hte led needs. And you can't do that for the supply input. The higher the resistance before the zener, the best. \$\endgroup\$ – Fredled Apr 7 '20 at 14:18
1
\$\begingroup\$

Here it illustrates my comment. For the buck converter, only a varistor is enough. For the LED see schematic below. If R1 resistance is too high for the LED reduce it to 4.7k but I think it should be plenty enough. You can put two zenner in parallel for higher safety. (or 3 or 4).

D4 protects from reverse voltage. The varistor protects only for surges above 20V. Between 15 and 20V it only mitigates the surge but it doesn't regulate the voltage with precision. If the voltage is above the "clamping voltage" (see parameters) it will short to ground and eliminate the current completely. The clamping voltage is much higher than the working voltage. You must chose the varistor according to the working voltage. Here 15V. The maximum voltage given by the battery.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
3
  • \$\begingroup\$ I was just in my local electronics store and the only varistors they had left were the s07k35 which would still be fine as my buck converter accepts voltages of up to 40v, right? \$\endgroup\$ – php_nub_qq Apr 7 '20 at 15:18
  • 1
    \$\begingroup\$ If the voltage is 35V it means it clamps maybe at 50V (I didn't read the datasheet). I'm not sure if it makes sens in your car? Do you expect surges of more than 35V? If yes then it can be useful, Anyway try to find a varistor with lower voltage. This local electronic store really doesn't have a lot in stock. 15V to 20V varistors are not something special. \$\endgroup\$ – Fredled Apr 8 '20 at 22:31
  • \$\begingroup\$ From the articles linked in other comments and answers I see that the spikes are in the range of 85 to 120 or more volts. I'll definitely search for a ~15V one today but where I live the stores are not packed all the time and I have to wait like 2 weeks if I order something on top of which I sometimes need to pay like 5 EUR for delivery, you understand how getting a varistor can be a problem :D \$\endgroup\$ – php_nub_qq Apr 9 '20 at 12:30
1
\$\begingroup\$

I going to take a somewhat contrarian view here.

If you don't understand your environment - a car power system in this case, anything you come up with is more of an ad-hoc solution. You can't properly engineer a solution to an ill-defined problem. In you're case, you need to define what it is you're trying to protect against.

Starting point would be to do a little research to find out details of a vehicle's 12 V power system. Things to look for are 1) steady state voltage ranges, 2) surges and sags, 3) spikes & transients (pretty large during a load dump), 4) noise, etc. SAE ( think) publishes documents that contain this information, that you have to pay for, but there's probably a good deal of information on-line.

Once you have that information, and knowing the damage thresholds for the device you're trying to use - some flavor is Raspberry PI I assume - you will be a position to properly design a solution for your problem.

\$\endgroup\$
2
  • \$\begingroup\$ I absolutely agree. I'm far from being able to fully understand all of the dangers simply because the people who do have spent many many hours in learning theory, same as I have in my craft. Being a foreigner to this craft I'm trying to learn by experience. Honestly speaking, for the simple thing I'm trying to do I'm going a huge deal out of my way to try and understand things that imho should be common sense. I'm not mad though, and I'm extremely thankful for anyone out here reaching out to me. \$\endgroup\$ – php_nub_qq Apr 7 '20 at 15:25
  • \$\begingroup\$ Most important, in two words, is to know the possible surges, sags (negative or reverse current),spikes & transients which can happens in a car. (I don't know them myself) And then, see if a 35V varistor for example is useful or not. Thought it will never hurt if it's not. \$\endgroup\$ – Fredled Apr 8 '20 at 22:37

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.