Dividing by 1023 or 1024? The final verdict on analogRead

I didn't expect any replies on this topic, I thought it would be old news by now! If I could end this thread I would, but let me see if I can put it to rest with a few pictures, explaining what we are dealing with.

In this image above, I show the possible Analog input (readings) and two possible digital conversions: 4bit (for simplicity sake) and 10bit, what the Arduino uses.

When any analog Volt value is read, it is converted to digital by simply putting it in the bin directly below it.

To be clear, the bin number, is NOT a volt value. It's an ID number, just like a trash can in the street with your house number on it.

Let me work on the house and trash can analogy a bit:
Imagine your are the cleaner who needs to empty the bins, and you find a rare empty bottle of Wiskey in one of the bins. You will be able to tell from which house this comes by simply looking at the bin number, right?

But what if some of the houses shares a bin? How will know from which house it comes then?

This example tries to show 3 things:

  1. The more bins we have, the better change we have at estimating where the bottle comes from.
  2. If we know there are four houses, but give them only 3 bins to put their trash in, we will be less sure where the bottle comes from.
  3. If there are 10 people living in each house, we will still not know who's bottle it was, but with 1 bin per house, at least we can narrow it down a bit.

Now back to the measurements:

In the example above (just looking for now at the 2 bit A2D conversion), the first two measurements (0.3 and 1.1) will land in bin 0, nothing in bin 1, 2.6 in bin 2, and 3.9, 4.1 and 4.9 in bin 3.

Now remember, once we have the digital (bin) numbers, we know nothing anymore of the original values.

All we know now is this:

NB: No matter what you do, once the value is converted to digital, there is now way of going accurately back to the original analog value (only more or less inaccurate ways)!

The same holds true for the 10bit (1024 bins) system. Your Arduino reports a bin number, not a voltage.

Since there are 1024 bins, that is the number to use, but, if you argue that 1023 is more convenient, since it can produce both 0 and 5Volt output values in your display, there is some merit to your madness, since lets be honest, the error is really small:

5/1024 = 4.883mV
5/1023 = 4.888mV

a difference of 4.77microVolt (0.00477mV), much smaller than the expected fluctuations in the reference voltage in any case.

But just understand, that when using 1023, although it might be convenient, adds to the inaccuracy since more measurements will be reported as 0 than when using 1024, as well as more values that will be reported as being a full 5V when in fact it should have been less.

So make your bed, and sleep in it!

Good night.
Paul