Newbie trying to read to voltage meters


I am new to arduino development. I am looking to control a generator based off two different readings.

Essentially, I would like to read a battery bank voltage and if the voltage is less than 12.5V, start the generator.

Once the starting procedure has finished, I would like to read an AC voltage to ensure the generator is running.

During the generator running state I would like to check the DC voltage again to see if it is maintained above 14.2V and if so shut the generator down.

I currently have an arduino 101 board with 1 UART, but I need to read 2 Voltages (at different times).

The starting and stopping of the generator is no problem as it is done with simple 5V controlled relays. The real problem seems to be reading the AC voltage period (although it does not need to be accurate, simply above 100V or so) and at a different time reading the DC voltage.

Thanks for any help.

You could use an opto-coupler to check if there's 115V on the generator's output.
Reading the battery can be done using a resistive voltage divider, just scale 16V or so to the Arduino's 3.3V, and connect it to an analog input. (You could add a zener to protect against higher voltages).

What makes you think you need a UART to read voltages?


What makes you think you need a UART to read voltages?


No, not need, but I purchase an voltage meter for the arduino, would it not use a serial interface?

I am sure there are a thousand ways to do this simply, I am just not very versed in it and am looking for the simplest method available.

Thanks for the input.

First a couple of warnings -

1. The AC must be isolated from the Arduino (and you).
2. The Arduino can be damaged by voltages greater than +5V or negative voltages (including the negative half of an AC waveform).

The [u]Read Analog Voltage Example[/u] shows you how to read voltage. There are multiple analog inputs so it's easy to read two voltages.

The AC voltage can be isolated with a small step-down transformer. Then it can be rectified with a diode, and optionally filtered with a capacitor.* Note that a transformer without a load will usually put-out a voltage that's slightly higher than it's rated voltage, and the peak is about 1.4 times the RMS voltage.

Alternatively, you can use a relay with a 120V coil, or you can use an optical isolator.

You can use a [u]voltage divider[/u] (2 resistors) to bring the voltage down below 3.3V. (And of course, you'll have to scale your software to read correctly.)

Since you're connecting to the "unpredictable outside world", I also recommend [u]protection circuits[/u] on both analog inputs.

The starting and stopping of the generator is no problem as it is done with simple 5V controlled relays.

You'll need a driver to provide the current (and voltage) to activate the relay coil.

  • Filtering to DC with a capacitor will make things easier because you can once, rather than trying to find the peak of a rectified AC waveform. And, you'll need a resistor to ground to keep the input from "floating" because the diode prevents the input from being "pulled down" by the signal.

Also research "state machine". Your Arduino needs to do different things depending in what has happened before, so it needs to remember what state it is in.

Thanks for all the advice. I planned on using a state machine.

So, if I am understanding correctly, all analog inputs if scaled down below 3.3V will read the voltage on the pin?

If that is the case, all I need do is scale the values back up appropriately in software and I will have a fairly accurate reading.

This makes everything easier. Except I have to build periphery circuits to handle the input voltages. Although, not very difficult, this does make the whole scenario a lot more messy.

If after I finish the design, is there a way to put this all onto one PCB?

It depends on which Arduino you are using. If it's a 3.3V one, then you do need to divide the voltage down to 3.3V. 5V for a 5V one, of course.

Is this thing connected to mains power? Measuring the voltage of the powerline is actually much more dangerous than you realize. There are a lot of things that can zap your Arduino and start a fire. These days the very best way to detect mains voltage is to use a cheap 5V phone-charger adaptor. That will contain all the protection required to make the mains voltage safe. (Add a voltage divider to 3.3V if using a 3.3V Arduino.)