Voltage divider with overvoltage protection

I'm wanting to measure 12 volts DC with an analogue pin When the car is running it will be 14 to 15 volts

I was planning on using a voltage divider

Only problem is this is in a car and I know the voltage can be unpredictable sometimes

What is the best way to protect my arduino mega just incase it goes above 15 volts

Maybe with some diodes???

One way is to use a 1:2 voltage divider to drop the battery voltage to 5volt.
e.g. with a 10k and 22k resistor (22k to battery, 10k to ground).
You are then protected to 32/10 * 5volt = 16volt.

Theoretically you are protected to ~40volt with a 10k/22k divider, calculating <=1mA fault current through the chip’s input protection diodes. That could drop to ~23volt when the Arduino is off.

Another way is to size the divider for 1.1volt, and use internal 1.1volt Aref on your code.
https://www.arduino.cc/en/Reference/AnalogReference
Divider can be 1:15, e.g. with a 100k resistor to battery and a 6k8 resistor to ground, or 150k to battery and 10k to ground.
Now you are protected to 106.8/6.8 * 5 = 78.5volt without even using the protection diodes.

A Mega has an additional 2.56volt Aref that can be used.
I leave the calculation over to you.

Always add a 100n cap from pin to ground to kill spikes.

Don’t forget that Arduino’s supply is equally important.
Leo…

Well I would use diodes to the rail. Do not use Zeners.

Never use zener diode for an analog input. They leak current. For an analog input, use clamping diodes.

The attached schematic shows how to use clamping diodes, an extra 1k resistor is used to protect the Arduino internal clamping diodes.

R1 : the value sets the range of the voltage to measure
R2 : for example 4k7 or 10k, determines the impedance of the circuit
R3 : 1k to protect the internal clamping diodes.
D1,D2 : The 1N4148 are fast and good for this.
C1,C2 : optional capacitor for example 10nF or 100nF, use none, one or two of them, according to your preferences.

I use a circuit like that for my Geiger counter to protect against voltage of 400V.
For a car, I think that I read once that a circuit must be able to withstand a spike of 120V.

Don’t forget the GND. If the GND can have voltage spikes as well, then it can’t be connected to the Arduino just like that.

input-protection.png

All automobiles are not the same, or if they did not produce large noise spikes last year, they may this year.

Acquire your signal (and power if so desired), from the battery, not from some wires, or chassis.

If your measurements are within expected values, then great. If not, there are several things that can be done to improve your accuracy.

Of course you need a voltage divider. Keep your highest resister below 60k, to help match the impedance of the arduino. Use an RC (or LC) circuit to help clip spikes. Of course put caps on the analog input (.1uf). What is your source of power for the arduino? If it is the car, then add extra filtering/caps on the power rails.

I still think the best way is a 1:15 divider (=1/16) and a 100n cap. Simple, effective, it takes advantage of the stable 1.1Aref, and the same code also works on 3.3volt Arduinos. As said in post#1, if you use 100k as the biggest value, the pin does not reach 5volt untill you put almost 80volt on the divider. If that would ever happen, everything else in the car would be toast.

Dividers with protection diodes are great if e.g. you want to take a fast pulse from the ignition coil. Other than that, they are tits on a bull. Leo..

" if you use 100k as the biggest value, "

That is a bit high resister value to match the impedance of an analog input pin. The analog input is designed for an input impedance of about 10k, but I usually get good results with about 40k, but 100k seems to be pushing it a bit far.

To repeat, IF there is any spiking problem, try using an RC or LC circuit to clean it up.

Just my opinion.

The A/D mux only connects to the input during sampling. And sees during that short time the very low impedance of the 100n cap.

If you talk about the resistive impedance. The 100k resistor has a 6k8 resistor in parallel. Leo..

"The 100k resistor has a 6k8 resistor in parallel." I don't know what a 100k and a 6k8 in parallel will provide. Maybe something like 6.1k ohms? I Don't think they will be in parallel. I think you mean they will be in series, and the voltage value will be taken from between the two serial resistors. I may be thinking this wrong tho.

(100*6.8 ) / (100+6.8 ) = 6k367

For DC, they are in series (between +in and ground). For AC, they are in parallel (both other sides are connected to a fixed point). Leo..

Wawa:
One way is to use a 1:2 voltage divider to drop the battery voltage to 5volt.
e.g. with a 10k and 22k resistor (22k to battery, 10k to ground).
You are then protected to 32/10 * 5volt = 16volt.

Theoretically you are protected to ~40volt with a 10k/22k divider, calculating <=1mA fault current through the chip’s input protection diodes. That could drop to ~23volt when the Arduino is off.

Another way is to size the divider for 1.1volt, and use internal 1.1volt Aref on your code.
https://www.arduino.cc/en/Reference/AnalogReference
Divider can be 1:15, e.g. with a 100k resistor to battery and a 6k8 resistor to ground, or 150k to battery and 10k to ground.
Now you are protected to 106.8/6.8 * 5 = 78.5volt without even using the protection diodes.

A Mega has an additional 2.56volt Aref that can be used.
I leave the calculation over to you.

Always add a 100n cap from pin to ground to kill spikes.

Don’t forget that Arduino’s supply is equally important.
Leo…

I will try with a 100k resistor to battery and a 6k8 resistor to ground

Does it have to be a 100n cap or can it be any size ?

I use ceramic caps the size of a match head.
Cap value is not critical.
Any cap more than 100nF will do.
Even a 10 - 100uF electrolytic.

This sample code will work on a Mega.
The “0.18823” depends on your Aref and your divider.
Change the number in small increments to get the right voltage on the serial monitor.
Leo…

unsigned int total;
float voltage;

void setup() {
  analogReference(INTERNAL1V1); // use the internal ~1.1volt reference | (INTERNAL) or (INTERNAL1V1) for a Mega
  Serial.begin(9600); // ---set serial monitor to this value---
}

void loop() {
  analogRead(A0); // one unused reading to clear ghost charge
  for (int x = 0; x < 25; x++) { // 25 analogue readings
    total = total + analogRead(A0); // add each value
  }
  voltage = total * 0.18823 / 1024; // adjust 0.xxxxx to display the right voltage
  // print to serial monitor
  Serial.print("The battery is ");
  Serial.print(voltage);
  Serial.println(" volt");
  total = 0; // reset value
  delay(1000); // readout delay
}

Thanks for that

I found some 1000nF caps that I will use

Just a word of CAUTION: Make sure the resistor to ground is never disconnected, or the arduino may suffer.

Turning off the power is almost the same situation.
The pin is then almost at ground potential, and any voltage divider will try to phantom-power the Arduino through the pin.
So we should stop recommending voltage dividers?

Luckilly it isn’t that bad.
100k@20volt is 200uA.
That shouldn’t be a problem.

Maybe you should always design the “hot” resistor of a voltage divider for <1mA between measuring voltage and ground.
Just in case.
Leo…

http://www.atmel.com/Images/doc8161.pdf (23.6.1) Page 257 states: "The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or less. If such a source is used, the sampling time will be negligible. "

I have used 40k with consistent success, but I have never tried to use 100k before. Do you get consistent success using 100k ? Do you vary the sampling rate?

The A/D has an input selector mux with sample/hold capacitors that have to be charged or discharged during a read.
Although they are very small, it takes some time to do so.

A voltage source with <10k impedance can deliver the current to charge/discharge the s/h cap fast.
It takes longer for a higher impedance voltage source to fully charge/discharge that sample cap.
If the sample cap had a different charge from a previously read pin (ghost charge), the sample cap might not fully reach the same voltage during the very short sample time.

A 100n capacitor from pin to ground makes the impedance almost zero ohms (= <10K).
During the short sampling time, the A/D samples from that “solid” source.
Call it a decoupling capacitor if you want.

Now the impedance of the voltage source can be as high as you want.
Here’s someone who used 10megohm resistors.
http://jeelabs.org/2013/05/16/measuring-the-battery-without-draining-it/
Leo…

i have tested it with my arduino and it works have a 100k, 6k8 and a 1000nF

i had to adjust the code a tiny bit

 voltage = total * 0.68023 / 1024; //

Thanks for reporting back. Leo..