BITX Voltage Monitor

With eight pins available for reading analog signals, the little Nano® has some enticing capabilities. More useful than an “S” meter reading, a measurement of the supply voltage is another display item that you can easily include. This will allow you to keep track of your battery status if you are portable. It could also be adapted to check on any other voltage (or voltages) that you might be concerned with. Like your PA supply if you are going to feed it with a separate higher voltage.

Looking at the wiring diagram you will notice a couple of resistors that are in series and placed between the +12 Volt input and ground. There is a 1.8 Kohm from ground and a 5.6 Kohm on the power feed side. Power rating is unimportant since they are going to dissipate only about 25 milliwatts. I chose these values so that it could measure up to 20 Volts without subjecting the Nano® to more than 5 volts. A safe Nano® is a happy Nano®.

Whenever measuring any voltage with the Nano®, endeavor to keep the maximum voltage to the analog pin below 5 Volts but compromise to retain the best dynamic range. The measurement involves converting the range into 1024 steps and then dividing the result by whatever number will display a reading that will be closest to what the measured voltage actually is. If you have too much range then those steps will be larger and more inaccurate.

Software implementation is wonderfully simple. Here's how to read the voltage on pin A1:

//Read supply voltage

int supply = analogRead(A1);

The first line is just a comment, reminding you what the next code is about. This line is optional. The second line establishes a local variable (that I named “supply”) and specifies it to be an integer type, saving a little storage space and keeping handling simple. The “=” sign assigns the result of the “analogRead” function on port A1. If the voltage applied to that pin was 2.5 Volts, for instance, the “supply” variable is now worth 512. That's because 2.5 volts is half the maximum 5 volts and, therefore, half of the maximum 1024. Make sense?

To display that as a voltage on our LCD screen we would use this line:

lcd.print(supply/47.7);

Why divide the supply variable by 47.7? Because that would make it correspond to the voltage that we were feeding the resistive scaling divider with. Find it by experiment. In this case you would see 10.73 on the display. Apply 10.73 volts to the top of the divider and you will see 2.5 volts on the tap where you have pin A1 attached and you will read 10.73 (or so) on the display.

Easy. Two resistors, two lines of code. You can use similar schemes to monitor any voltage or current. Rectify the voltage from a winding on a toroid that you run the antenna lead through and read output power (antenna current). Set up a VSWR bridge. Ahhh! The possibilities!

de ND6T


Return to Home