Anyone who understands basic mathematics and thinks about it for a bit can explain why 1024 is correct.

...

It is silly to stick with someone else's example, if it gives you the wrong answer.

I personally don't think that the ability to do basic maths has anything to do with the "divide by 1023 vs 1024" debate. I do think, however that there are far too many examples on the internet (including the one from the official Arduino website), that show the method that I employed above, and not enough examples which explain the key information required to make an informed decision.

The biggest misconception that I had - actually related to the Analog reading of 1023, and what that reading actually means. I thought that the reading of 1023 equates to 5V, or to the Vref. So when you have that misconception, it doesn't make sense to divide by 1024

----------------------------------------------------------------------------

*For example,*

If Vin is 5V, and Vref is 5V, then using the formula you provided, ADC = 1024. But you never get a reading of 1024, you get a reading of 1023.

Put another way, if you get a reading of 1023 on the analog pin, and know that Vref is 5V, and try to calculate Vin using that formula, you will NOT get the expected answer of 5V. You get 4.995117. But if you instead, divide by 1023, you get the expected result of 5V... and the misconception is fortified.-----------------------------------------------------------------------------

But there is some VERY IMPORTANT INFORMATION MISSING.According to the datasheet:

"

*The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. The*

minimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB. "

With that information in mind, the formula you provided from the datasheet makes a whole lot more sense.

That means, if you have a Vref of 5.0, the maximum Vin that the ADC can detect is actually 4.995117 and

not 5V.

Which means, that if you supply any voltage between 4.995117 to 5V to the Analog pin, it will show a reading of 1023.

Penny dropped at that moment.

Which means that if you choose to divide by 1024, you must understand that the calculated Vin may be out by as much as 1 LSB. So not only must you use the formula that you provided, you also need to calculate 1 LSB, in order to understand the range that the Analog reading represents.

Now that may have been clear to you all along, but if more people provided that key bit of information, then there would be much less debating.