 # Measure voltage with Arduino

Hi,

I have followed a tutorial to measure the voltage of a power supply by using 2 resistors of 10K and 100K to take the input voltage down so I can measure voltages up to ~55 volts

This works pretty good. The tutorial is Dutch but very simple: http://domoticx.com/arduino-de-arduino-als-dc-voltmeter/

As far as I understand the voltage is measured against its own input voltage the board receives to be powered on.
In the tutorial this is 5V and they use 4.7 because of some loss. They use the voltage as a variable to make a calculation.

I want to power the arduino with a 12V power supply through the barrel connector. As far as I know the voltage regulator of the arduino will step it down to 5V.

My question is, in the code do I need to change the variable to 12V or keep it at 5V.
I think the latter because internally it still works on 5V but I’m not sure.

As far as I know the voltage regulator of the arduino will step it down to 5V.

I think you answered the question yourself. The 12V power supply converts the 12V to 5V. Just keep it as it is.

I have followed a tutorial to measure the voltage of a power supply by using 2 resistors of 10K and 100K to take the input voltage down so I can measure voltages up to ~55 volts

If you want to measure the voltage of the power supply rather than the voltage of the Arduino 5V then you need to connect to the supply voltage, not the Arduino 5V pin

What is it exactly that you want to measure ?

@dyso, thanks then I was thinking right.

@UKHeliBob I have made the following setup:

In the future it is possible the setup changes to 24V. So in that case I have to place a voltage regulatetor between the power supply and the barrel connector. But for now the barrel can handle 12V. So this is the setup I use.

I use this with an ESP2866-01 to send battery voltage to 'home' so I can see if I need to replace the battery.

OK, so it is the supply voltage that you are measuring

I use this with an ESP2866-01

This is confusing because there is no barrel connector on an ESP8266-0,1 so I assume that you are passing the voltage data from the Arduino to the ESP. Could you not just measure the supply voltage using the 8266 ?

Step down the voltage to 0-1V (so change the resistor ratio) and measure with the ESP's analog input (it's got its own 1V reference), or if you use the Arduino select the internal 1.1V reference - that's independent from your supply voltage and gives much more stable results.

The Arduino supply must be calibrated (it's specified as having a 10% tolerance); the ESP's likely as well, the chip is not well documented so no idea on its tolerance on that 1V. In my experience it tends to be a tad higher than 1V.

Now in reality using the ESP8266 for this is a little more complicated. The ESP-01 does not have the analog pin broken out, and development boards like the NodeMCU and WeMOS have a 220k/100k voltage divider on the analog input, to take a 0-3.2V input. You have to keep those resistors in mind when designing your voltage divider.