# Convert ADC value to real voltage

I want to measure the input voltage to my circuit. The input voltage is supposed to be anything between 7 to 35 Volts.

I have a micro-controller with 12bit ADC. I am using a simple voltage divider to connect a fraction of input voltage to the ADC pin.

The voltage divider is simply a R1 = 82k on top and R2 = 5.6k resistor on bottom.

According to my calculation, at 35V I should get (never mind the tolerance):

V_IN = (V_SUPPLY * R2) / (R1 + R2) = (V_SUPPLY * 5k6) / (82k + 5k6) = 2.24


And the same calculation at 7 Volts I should get 0.4V into the ADC pin.

Now the question is, how to convert the raw value of the ADC to a voltage?

If I supply my circuit with 12V and if I did the programming of ADC correct, I am reading the raw value of around 840 out of my ADC.

The ADC reference voltage of controller is 3.3 Volts.

• What is the ADC reference voltage? Oct 21, 2018 at 13:52
• @LongPham it is 3.3 volts Oct 21, 2018 at 13:55
• Well, use the formula: V = reading * Vref / (2^n - 1). Since the ADC voltage is proportional with the input voltage, you can calculate it easily. Oct 21, 2018 at 14:04
• Just a note: If you are doing fast conversions the SAR sampling current (if unbuffered) will reduce your measured voltage because of that 82K resistor- check your RC time constants to make sure you are OK on accuracy. Oct 21, 2018 at 14:27
• A quick and dirty way is to add a capacitor in parallel with R2, however to do accurate continuous conversions you will either have to have an op-amp or compensate for the drop in voltage by adding in the SAR load on your R1/R2 voltage divider. The scaling equation has already been done by Spehro below. Oct 21, 2018 at 14:31

## 1 Answer

V = (R/4096)Vref(82K + 5.6K)/5.6K

Which gives me about 10.6V, which I suspect is too far off from 12.0V to be explained by even 5% resistor tolerances and a few percent Vref tolerance.

• Thanks! Apparently I have the wrong resistors in place. now it works fine :) Oct 21, 2018 at 16:11