Measuring high DC supply voltage with an Arduino
For my home-monitoring setup I would like an Arduino to measure the supply voltage it is getting from a DC battery UPS (Uninteruptible Power Supply). Unfortunately (actually by design, but that’s another story), the power supply is 24V, which means it will put out anywhere from 21.3V-29.8V (according to the manufacturer), which is far too much to measure with the Arduino’s 0-5V input range. For simplicity’s sake, lets assume we want to measure a 20-30V voltage.
The immediate answer is to use a voltage divider, which will bring a voltage in the 0-30V range into the 0-5V range. The general formula for the resistor divider is:
Plot it into a spreadsheet, create a graph and add a linear regression gives:
Now, this formula is a bit different compared to the theoretical one, mainly in the Zener diode drop. However, the datasheet for the BZX79 actually has the 18V C-type () as between 16.8-19.1V, so this is well within spec. Since this is just a one-off, I’m happy to just use the measured formula, as this will be more accurate.
The final precision should be . The current should be around , which again is ok.
We want to give , so
Now, just as a sanity check we should calculate the current of the resistor divider, to make sure we’re not converting too much electricity into heat. Ohm’s law gives us
which in this cases gives
No problems there. This works okay, but we lose a lot of precision, as only ~1/3 of the Arduino’s range is actually used: the Arduino’s ADC has 1024 different readings between 0-5V, so when reading the 0-30V range the precision is just about over the range. If only we could move the lower bound, so that 20V would map to 0V on the Arduino. A wild Zener Diode appears! One use of a Zener diode is as a voltage shifter. The closest Zener diode I could find was an 18V of the BZX79 series. This resulted in the following circuit: which I hacked into my Arduino box. Now, theoretically the formula for translating an voltage at the Arduino to the supply voltage should be:
I then did some quick measurements of various input voltages and the resulting voltage at the Arduino pin:
Input voltage | Arduino pin |
18V | 0.32V |
20V | 1.16V |
26V | 3.60V |
28V | 4.41V |
29V | 4.81V |
31 aug
0 Comments