Best way to measure high voltage DC with arduino ADC

We have a project where a mains voltage (240V) is converted to DC with a rectifier and then the DC voltage to the resistive load is varied using an IGBT fed with a PWM signal on its gate from an Arduino. This works well. However we want to log the voltage and current to an SD card. For measuring current we are using a 30A current sensor (Based on the ACS712 IC.). This also works well.

So the question is: what is the best way to measure the voltage - simple voltage divider? Or is there a more sophisticated and potentially safer way?

Any helps is much appreciated.


Am I reading this correctly? Is there no isolation between mains and ground? If so your circuit is highly dangerous and probably illegal depending where you live.

You need at least an isolation transformer, then you can use a potential divider to read your voltage.

If the voltage is subject to PWM it must be smoothed first before it will measure correctly.

The Arduino can measure 1kV DC or more with a voltage divider with very high values (where R1 is split up into multiple resistors). But that is for a small circuit with the same GND.

With a AC voltage, the Arduino has to take enough samples to calculate the RMS or top value.
Have a look at the OpenEnergyMonitor website, for example this page:

Good link, but my reading of the question is that he is trying to measure the DC PWMed voltage not the AC voltage.

Can you please post a circuit diagram of your project?
Please include where you wish to measure the voltage?

What is the application?

Thanks... Tom... :grinning: :+1: :coffee: :australia:

1 Like

Thanks for the replies.

Yes its for DC.

The Application is for controlling the voltage to an electrocoagulation unit (used in waste water treatment - Electrocoagulation - Wikipedia). Essentially waste water is pumped through a series of metal plates arranged in series like a parallel plate capacitor and a voltage is applied across them. The combination of the DC voltage and the plate material causes contaminates to coagulate for easy removal in a later stage. Usually lab based units use a high power Triac to control the incoming AC voltage then rectify this to send to the electrocoagulation unit. We are trialing rectified mains and using an IGBT to do the same.

Will try an upload a cct when i have more time but essentially an Arduino controls an IGBT using PWM (via an optocoupler - cny65) . AC voltage is 220 - 240 but the rectified DC output to the electocoagulation unit (via the IGBT) rarely exceeds 150V. An experiment may last an hour or two and the design spec requires logging of voltage and current every few seconds. So i need feedback on the voltage (current is handled by the ACS712). A previous prototype unit worked well but only monitored fluctuations in current. Voltage was set by simply reading the output of a voltmeter but it was found that that voltage fluctuated quite a bit so it was decided to record this as well hence the need for voltage feedback to the Arduino.

Any help or thoughts on this that you can give would be much appreciated.


The thing that really scares us, is the GND of the Arduino.
You can not connect that to the negative voltage after the rectifier.
Suppose you have a laptop with no connection to earth, so no earth-current-leak-detector will trip. When the laptop is connected to the Arduino and the Arduino to the mains (via a diode), that is a serious unsafe situation.

The Arduino runs the PWM at about 500Hz. If you want to keep track of that signal, then you need to be really fast.

When you use a RC filter, then you can read the average voltage.
The same for the current, since the ACS712 is analog, a RC filter turns the signal into the average current.

If the voltage is fixed then it should not fluctuate. If you are finding fluctuations this is probably because the current demand at times can not be met by the power supply and as a result is dropping. So there should be a strong correlation between current demand and voltage drop.

Oddly enough I did supervise an MSc student making a detector to try and measure the difference between sewage and sludge, so that when pumping sludge into a tanker for disposal, they knew when to stop the transfer and not pump sewage. We tried detection plates similar to that described in that link and we found the cell actually generated a voltage when in the sewage / sludge mixture.

My worry about the PWM method of controlling the voltage is, it is not actually controlling the voltage, as that will always be the peak voltage. Rather it is turning the voltage on and off and altering the duty cycle. This will change the average voltage but not the peak voltage. The physicist in me is wondering about the importance of the actual voltage and the effect it has on the electrolysis process, which in the end you are trying to investigate.

By the way the student doing the sewage / sludge detector was not very popular with other users of the lab. :anguished: