analogRead

Can we get an official answer to this?

Is it 0 - 1023 (0 being /1/) like an array....
Is it 0 - 1024 (0 being 0) up to 1024.

I've seen so many conflucting examples now I really don't know which to believe... poll?

cjdelphi:
Is it 0 - 1023 (0 being /1/) like an array....
Is it 0 - 1024 (0 being 0) up to 1024.

It's 0-1023 where 0 is 0 volts and 1023 is 5V. It's 1024 "positions" because 0 counts as the first one.

0-1023 makes sense but I've been corrected here before by a mod saying it was NOT 0-1023.

The man page says:

... values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units ...

... which supports what mart says.

But beware the fence-post error here: it may well be 1024 values, but it's still only 1023 spaces.

For simplicity let's say the values were only 0, 1 and 2. That's 3 values clearly (0, 1, 2), but 3 values have only 2 gaps: the 0-1 gap and the 1-2 gap.

So if 0V is 0 on my pretend 0-1-2 analog sensor scale and 5V is 2, then it's clear that it's 2.5V per gap... position 0 is 0V, position 1 is 2.5V and position 2 is 5V. So the 5V is spread over 2 gaps not 3 positions.

By that logic, where the gaps are what count not the number of values (counting the start and end fence-posts), the 5V is divided over 1023 gaps not 1024 positions.

Edit: my calculator tells me 5/1023 is 0.0048875855327468 and 5/1024 is 0.0048828125, so I'd call those 0.00489 and 0.00488 both of which are 0.0049 so who cares in practice? But yes- it's good to be clear on the theory....

But beware the fence-post error here: it may well be 1024 values, but it's still only 1023 spaces.

Bad analogy (pardon the pun).

A one bit ADC would be capable of two readings (21 = 2) .
Those two readings would be
a) zero volts (or, more specifically less than Vref/2) and
b) Vref/2 or greater

Note - two fence posts, two spaces.

I really thought we'd nailed this one.

If anyone doubts this logic, ask yourself why companies spend many thousands of dollars producing voltage references with peculiar output voltages like 1.024V or 2.048V.

(Difficult to see how this thread originally started off in "Installation and troubleshooting")

So 1024 it is?

Still no clear answer here... or if there is, I see 2 answers.

(It does not need to be a sensor to use analogRead, eg a capacitor or battery)

For a 10 bit ADC, the readings run from 0 to 1023 inclusive.
That means 1024 different values.

Each reading represents a step of Vref / 1024.

Clear enough?

(It should not have been posted in a section clearly labelled "For problems with Arduino itself, NOT your project" )

cjdelphi:
I see 2 answers.

True but AWOL's carries a lot more weight than mine so it's down to 1 answer, I'm deferring to 1024.

(Not that it makes any difference to me personally, where I really need my LM35 to tell me the room temp is a bit cold near 0, still chilly about 10, nice about 20, getting pretty hot as it approaches 30, and very hot above that.)

The problem here is that you have not defined the question

cjdelphi:
Arduino Tutorials – Chapter 22 – the AREF pin | tronixstuff.com

Can we get an official answer to this?

Is it 0 - 1023 (0 being /1/) like an array....
Is it 0 - 1024 (0 being 0) up to 1024.

What is it?

When you do not define the question you get answers like 42

I agree, the distinction is a very fine one, particularly with the levels of noise normally experienced on the analogue inputs.

The other practical upshot is that if Vref is, say, 5V, you can never read 5V on an input - you can only ever say that the voltage is 5 - (5/1024) volts or greater.