Protecting Arduino inputs from external inputs

I have some projects, usually automotive, where I'm monitoring a 0-5 volt input from a car. Like say the TPS (throttle position sensor) or the MAF (mass air flow sensor) etc. It works great and puts no load on the car's sensors so as to not alter the signal the car's ECU is getting.
However I'm wanting to build in some protection in case of an accidental miss-wiring under the hood such as accidentally connecting to a 12 volt source. My thought was to use a 5.1 volt zener diode on the input at the arduino. If my understanding is correct it'll have no current draw and place no load on the various 0-5 sources under the hood that I monitor. However if I make a mistake and hook it to a 12 source the zener diode will then shunt the extra voltage and save the arduino from frying at that moment. While that is happening I don't care that there is now a load on the circuit as it's incorrectly wired at that moment.

Does that sound right to you guys? Or should I be going about this a different way?

Thanks
Malcolm

What you need to be looking at, is resistors in series with the inputs. If the resistors are large enough (say, 47k,) the internal input diodes in the Arduino will look after it just fine.

On the other hand, you are talking about analog inputs, and I am not sure what their internal impedance is in that mode (it is of course, tens or hundreds of megohms as digital inputs) - perhaps you should research that? I believe however that this is only of importance during the A-D conversion, so putting a capacitor on the input after the resistor would stabilise the voltage during that conversion - and in addition, filter noise.

The obvious alternative is to use something like an LM324 (quad) op- amp as both an impedance buffer and a scaling amplifier, operating from the Vcc of the Arduino.

(I am getting déjà vu here - I seem to recall giving the same answer - on another board - many years ago!)

Hi!

Could you please explain how you monitor these sensors without altering the signal the car's ECU is getting?

Regards
Tobias

MalcolmV8:
[...] I'm monitoring a 0-5 volt input from a car. Like say the TPS (throttle position sensor) or the MAF (mass air flow sensor) etc. It works great and puts no load on the car's sensors so as to not alter the signal the car's ECU is getting.[...]
Thanks
Malcolm

Paul__B:
What you need to be looking at, is resistors in series with the inputs. If the resistors are large enough (say, 47k,) the internal input diodes in the Arduino will look after it just fine.

I'm not sure how that would help me? The current flow is so tiny it's neglagent and I don't see there been a voltage drop across the resister to protect me against the 12 volts? Or am I misunderstanding? If there is indeed a voltage drop then isn't that going to affect my 0-5 monitoring in normal circumstances?

Paul__B:
On the other hand, you are talking about analog inputs, and I am not sure what their internal impedance is in that mode (it is of course, tens or hundreds of megohms as digital inputs) - perhaps you should research that? I believe however that this is only of importance during the A-D conversion, so putting a capacitor on the input after the resistor would stabilise the voltage during that conversion - and in addition, filter noise.

I haven't had much problems with noise. A small amount in certain circumstances but I addressed that in the coding logic of how I work with those inputs so it hasn't been an issue.

Paul__B:
The obvious alternative is to use something like an LM324 (quad) op- amp as both an impedance buffer and a scaling amplifier, operating from the Vcc of the Arduino.

I know of LM324 but not really how to use it. Impedance buffer sounds useful but not sure I'd need a scaling amplifier? The 0-5 volt output from the car is perfect for what I need. How does this address my over voltage situation at the input of the arduino?

So was there anything wrong with my 5.1 volt zener diode solution? It sounds like it would work perfectly to me.

Paul__B:
(I am getting déjà vu here - I seem to recall giving the same answer - on another board - many years ago!)

Probably another car guy out there. I'm new to Arduino so still figuring this stuff out. Thanks for your help.

the zener is fine,you will need a resistor before the zener to protect it,like 47kiloohm

MalcolmV8:
I'm not sure how that would help me? The current flow is so tiny it's neglagent and I don't see there been a voltage drop across the resister to protect me against the 12 volts? Or am I misunderstanding? If there is indeed a voltage drop then isn't that going to affect my 0-5 monitoring in normal circumstances?

The point is that the microcontroller in the Arduino microcontroller already has 2 diodes connected to each pin, one to protect it against negative voltages, the other to protect it against voltages greater than Vcc (i.e. greater than +5V). The limitation is that these diodes are only good for about 2mA at most. By connecting a 47K resistor between your sensor and the input, you ensure that the sensor output would have to reach nearly 100V before that 2mA is exceeded.

MalcolmV8:
I'm not sure how that would help me? The current flow is so tiny it's neglagent and I don't see there been a voltage drop across the resister to protect me against the 12 volts?

And that is the point. Under normal circumstances, the impedance of the Arduino input is so high that there will be negligible current flow in the 47k resistor and negligible voltage drop. There are however, internal diodes in the Arduino that prevent the voltage from exceeding Vcc or going below ground by conducting current to Vcc or ground respectively. When your input voltage goes outside these limits, there will be a voltage across the 47k resistor, but at for example, 12 volts, there will then be 5V on the input and 7V across the resistor. That current will be limited by the resistor to 150 microamps and this should not be a problem for the Arduino. It is very doubtful that there is any advantage to adding a 5.1V Zener.

MalcolmV8:
I know of LM324 but not really how to use it. Impedance buffer sounds useful but not sure I'd need a scaling amplifier? The 0-5 volt output from the car is perfect for what I need. How does this address my over voltage situation at the input of the Arduino?

If you do not need scaling, then you just connect your input voltage through a 47k resistor to the "+" or non-inverting input of one op-amp and the output - which of course goes to the Arduino - through another 47k resistor to the "-" or inverting input. As the LM324 is running from the same 5V as the Arduino, its output cannot exceed that. There is a problem however - the LM324 cannot drive its output to the full supply voltage anyway, so you probably need something like a LMC6482 or LMC6484.

dc42:
The point is that the microcontroller in the Arduino microcontroller already has 2 diodes connected to each pin, one to protect it against negative voltages, the other to protect it against voltages greater than Vcc (i.e. greater than +5V). The limitation is that these diodes are only good for about 2mA at most. By connecting a 47K resistor between your sensor and the input, you ensure that the sensor output would have to reach nearly 100V before that 2mA is exceeded.

OK so I drew out what I think we're talking about here. The diagram on the left is all you're saying I need to do? Simply place a 47K resistor in line of the input like that and I'm protected? And this does not affect the 0 - 5 volts I'm reading? The Arduino is still going to see the same voltage as before?

Now if I was to add the zener (which it sounds like you guys are saying is not required at all) it would be added like the diagram on top right or bottom right? I'm thinking top right.

MalcolmV8:
OK so I drew out what I think we're talking about here. The diagram on the left is all you're saying I need to do? Simply place a 47K resistor in line of the input like that and I'm protected? And this does not affect the 0 - 5 volts I'm reading? The Arduino is still going to see the same voltage as before?

Pretty much. Each input.

MalcolmV8:
Now if I was to add the Zener (which it sounds like you guys are saying is not required at all) it would be added like the diagram on top right or bottom right? I'm thinking top right.

Indeed. The resistor prevents too much current getting through to the Arduino either way, whereas your "bottom right" wiring would provide no protection whatsoever. The Zener is merely supplementing - by paralleling - the two diodes already in the Arduino.

Thanks. I'll do some bench testing tonight. I won't test much over 13.5 ~ 14 volts but as long as that doesn't fry my arduino I'll be happy :slight_smile:

Well I did some testing. I put the 47K resistor in line of my input A0. The measured counts were very minimally affected. About 1 ~ 2 counts so that's good.

Now for testing the over voltage condition. I know you guys said it would protect up to 100 volts but I wasn't going to chance that. My lead acid battery was measuring around 13.2 volts so I used that. I used my DVM to measure the actual voltage at the Arduino pin and it was 5.9 volts. The Arduino still works and does not appear to have received any damage but isn't 5.9 volts a bit high? Although when I measured the voltage on the 5+ volt pin of the arduino I see 5.25 volts there.

It makes me wonder if I do indeed need that 5.1 zener diode there as well to protect the input? Or am I just been over paranoid?

5.9 volts is 0.65V over 5.25V, 0.65V being the voltage drop of a silicon diode - which is what is, internal to the chip, limiting the voltage. That is precisely what you would expect.

The point is that the current which is feeding that diode is negligible, It is not going to heat any part inside the chip, and 5.9 volts is not going to break down any insulation.

Given the cost of replacing an engine controller, shouldn't you be more concerned about protecting the other side from a wiring mistake?

Paul__B:
5.9 volts is 0.65V over 5.25V, 0.65V being the voltage drop of a silicon diode - which is what is, internal to the chip, limiting the voltage. That is precisely what you would expect.

The point is that the current which is feeding that diode is negligible, It is not going to heat any part inside the chip, and 5.9 volts is not going to break down any insulation.

That's great news. Thanks. So I'm all good.

I'm not sure I follow. I'm not applying voltage to the car's ECU. I'm only monitoring some outputs.

MalcolmV8:
I'm not sure I follow. I'm not applying voltage to the car's ECU. I'm only monitoring some outputs.

You are connecting a hand-built foreign device running code that has undergone limited testing. For example, what would be damaged if your program accidentally set one of the inputs to be an output?

I see your concern. While you say limited testing I say thorough testing. I designed this particular device over a year ago and have spent hundreds of hours testing it on the work bench with simulation. By simulation I mean I duplicate the car's particular functions I'm monitoring on bread boards. I've spent countless hours going through the various conditions, changing code, changing hardware and been as thorough as I can. I can tell you there is no chance my code will ever change the device's input to an output and even if it did it would not be able to output anymore than 5 volts which is in the acceptable limits of the particular sensors I'm monitoring.

And of course, given just a modicum of competence in wiring and construction, the isolation techniques we have been discussing provide excellent protection in the opposite direction.

I agree. The techniques should protect the hardware. But, given the cost of a fault, it is worth a few moments of time to discuss.

Like say the TPS (throttle position sensor)

The techniques do not provide protection against an accidental "full throttle" indication. The result of unexpectedly applying +5V to that sensor would be? Other than validating the software, is there anything else that could be done?

Yes definitely worth a moment in time to discuss. I never shy away from safety or learning something new.

As for the TPS sensor. On my particular car it's a cable operated throttle body moved by the motion of the gas pedal. The TPS is purely for telling the ECU where the throttle is at. It does not actually control the throttle. If it did receive 5 volts unexpectedly from an outside source it would command the ECU to go into open loop (instead of the current closed loop) which means instead of fueling the car according to feed back from the narrow band O2 sensors in the exhaust it would switch to a predefined fuel table in the tune and fuel the car from it. It would also change spark source to 2 (borderline knock) which means it would look up spark advance from a different table because it thinks the car is under a WOT (wide open throttle) condition.
Both conditions on my car are relatively harmless. Now if my car was a DBW (drive by wire) that would be a whole different story. On those cars (referring to the GT500s I'm familiar with here) they have a potentiometer under the gas pedal. As you depress the pedal they vary from 0 to 2 volts. That voltage goes to the ECU and it uses that to determine how far it should move the electric motor that opens the throttle body. In that case if someone erroneously gave it 2+ volts the car will go WOT unexpectedly. I have personally tested this when diagnosing a faulty nitrous WOT controller box and it does indeed do that. Even more scary when the external voltage was removed the car did not return from the WOT condition and we had to turn the key off to break the cycle.

Now if I was working on a DBW car I'd want hardware in place to make sure a software coding error could never cause the above scenario to occur. In that case I'd use the op-amp impedance buffer as Paul has suggested. In fact I will probably start using that anyways so I can learn more about it while experimenting. It should prevent the monitoring input from ever going high even if the Arduino's pin goes high as the op-amp would not be bi directional. Unless I'm missing something?