Correct divisor for AD conversions?

Hi, folks.

I am curious about a detail of AD converters in Arduino processors.

On a UNO or NANO, the ATmega328p has a 10-bit AD converter, so it can return unsigned integer values from 0 (representing an input of 0V) to 1023 (representing an input of …, what exactly?)

I don't really know how the innards of an AD converter work. Normally, Arduino developers just use the power-supply voltage (5.0 V on UNO or NANO) as the AD reference voltage.

So does an AD value of 1023 actually represent EXACTLY the full reference voltage (e.g. EXACTLY 5.0V on UNO or NANO)? Or does 1023 actually represent JUST UNDER the reference voltage (e.g. JUST UNDER 5.0V; 4.9951171875V, to be exact :grinning: ), and the EXACT full reference voltage (5.0V) would be represented by the (theoretical, but unavailable) value of 1024?

In sketches that convert AD inputs to actual voltages, I have seen different people use either 1023 or 1024 as the divisor when calculating the voltage. I.e. either (assuming the reference is 5.0V):

float Vx = 5.0*(((float)ADvalue)/1023.0)


float Vx = 5.0*(((float)ADvalue)/1024.0)

Which of the above is the more correct calculation?

(Note: I use 1023 and 1024 above, assuming 10-bit AD converters. I know that some boards have 12-bit converters so, for those cases, substitute 4095 and 4096. :wink: )

I know that it does not really make any practical difference "for government work," but curious (and pedantic) minds (at least this one ) want to know!

BTW (and unrelated to the above, but sort of related to AD converters :wink:) I once read that reading in an AD converter value from an unconnected (i.e. open) AD pin, makes a good source of randomness for seeding the Arduino random number generator. Is that good advice?

Thanks and best regards,

The default voltage which the arduino uno compares with comes from the voltage regulator (5V) and it should be pretty much 5V.

So 0 is 0 V and 1023 is 5V.

When you do the proportion the second one is corrected

float Vx = 5.0*(((float)ADvalue)/1024.0)

because you are dividing for 1024 positions. The 1024th is 0.

This one i don't know

Assuming that the ADC reference voltage is 5.000V, an ADC value of 1023 represents a voltage that is slightly above about 4.995V, including possibly higher than 5.000V. More than that you cannot say.

Likewise, a value of 0 represents a voltage that is between and including 0 to slightly below 0.005V

The mathematically correct divisor is 1024. The problem lies in attempting to make claims about the actual value of input voltage. The ADC give you only a range.

No. It's a convenient method and requires no extra hardware, which is why you'll see it suggested frequently, but if you really want randomness, it's not adequate.

When asked this question, I usually simply ask back "Why do you think 4.096V voltage reference devices exist?"

(Really though, it makes no practical difference)

No, 1023 represents the reference voltage, minus 1 LSB* (at least that's what the AVR 328 reference usually states - other devices are different)

* and above

(That dot is supposed to be an asterisk. Grrrrr)

1 Like

Thanks, "AWOL". That is exactly the answer I was looking for. So, in the '328, using 5.0V as reference, then 1023 represents a theoretical exact voltage of 4.9951171875V, right? (Well, and above, too, of course, but you know what I mean, right?)

This has been discussed quite often. But think of it like this:
Your measuring range is 0 to 5 volts and, unlike a Uno etc. which has a 10 bit ADC you have only a 1 bit ADC.
This would give you the ability to measure voltage to a rather rough precision to the one of two 2.5 volts blocks.
That is a zero reading on your ADC would tell you that the voltage was in the range 0 to 2.5 volts and a 1 would indicate a range of 2.5 to 5 volts. Expressed mathematically volts = ADC/2 . Try the same thing with a 2 bit ADC.

1 Like

I know it is not "cryptographic" quality to use the unconnected AD as a random seed source but, then again, using the Arduino PRNG is an absolutely terrible idea for cryptographic work. But when a "random" source is needed for something that does not require "true randomness" (e.g. games, or something that only needs the appearance of randomness), it should be good enough?

@6v6gt Thanks for that amplification!* :grinning:

It really did help me to understand better.

*Your user ID reminds me that, when I sat my exam for my first amateur radio licence, way back in the early 1970's, I had to draw the schematic and explain (to the examiner), circuit diagrams for a transmitter, a VFO, and a super-het receiver. The local club instructor for the ham course we took, taught us the theory of these circuits, using "valves" instead of solid state devices.

Ah, well you see, my screen name came from my first big electronics project:

The author was also famous (or infamous) for publishing publishing a lot of designs which, by today's standards, would have been considered lethal. Recklessly using rectified mains voltage to achieve high tension was one of the features of his designs. I've still got a book of them. The amplifier design here is an exception otherwise I may not be here today.

LOL. It’s way easier these days… especially since they dropped the Morse code proficiency part.


LOL. Just earlier this very morning, I found this, (from searching Google for "1.5V power supply circuit.")

I cannot believe that someone who purports to be an "electronic engineer (dipIETE )" would publish such a circuit. It's downright SHOCKING! :astonished: (And probably quite literally so for anyone who tries to build it.)

Fixed it for ya.

1 Like

To be honest, such transformerless capacitive droppers aren't all that unusual. As far as I know, though, they are only ever used in double-insulated equipment, which the clock most likely won't be! :open_mouth:



Pick a generator that suites your needs. Use something like this to reseed.

It depends on your needs. Maybe for something trivial, test and find out. But I recall reading someone's testing showing that they didn't get all that many different numbers and if that's generally the case, I wouldn't be happy using it for anything more important than a game of "Guess a number "

(Yeah, this is getting Waaaayyy off-topic but...) I think, Steve, that you left out the word "Unfortunately."

Even with double-insulated equipment, I would not trust the safety of such a power supply. If that 1M resistor or 330 nF cap were to ever short-out, one may need to call the fire department and their home-owner insurance company. (Which would certainly be the case for the clock, I think.)

[And now back to our regularly scheduled program ...]

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.