Uin =AnalogRead()*5/1023; // will do integer math
Uin =AnalogRead()*5.0/1023.0; // the .0 makes the compiler do floating point math
For better results measure the 5V of the Arduino. I get 4.977V so I use 1023/4.977I use a MOSFET to gate the voltages on and off.I have a delay of .09 before I take a A0 reading.Gives me readings of .005 off my volt meter
Relating ADC Value to VoltageThe ADC reports a ratiometric value. This means that the ADC assumes 5V is 1023 and anything less than 5V will be a ratio between 5V and 1023.https://learn.sparkfun.com/tutorials/analog-to-digital-conversion
Voltage to be measured to a P channel MOSFET drain. I use 2N7000's.Arduino pin, your choice, to one side of a 330 ohm resistor, other side of 330 ohm resistor to gate of MOFFET. Junction of gate of MOSFET and 330 ohm resistor place a 10k resistor to ground.Source of MOSFET to top of resistor divider network resistor R1, bottom of R1 connected to R2, Bottom of R2 connected to ground. Junction of R1/R2 to AX pin.Input of 330 ohm resistor to an Arduino pin to gate on/off voltage to be measured.I put in delay because I found the AX pin requires a little time for voltage to become stable on the pin. You don't have to *shrug*.Arduino pin used, output a 1, to gate on MOSFET, to allow voltage to be measure to be felt at the top of the voltage divider, than measure voltage with an analog read. You can do an analog read without gating on, an experiment, MOSFET to find that the AX pin will return a 0 volts measured.By gating off/on the voltage to be measured to the voltage divider, the voltage divider is only drawing battery power when being read, instead of drawing battery power continuously.
I found, with the voltage divider below the MOSFET, the circuit works quite well. Well enough to put the circuit on a PCB.