Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: analogRead  (Read 347 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2547
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://tronixstuff.com/2013/12/12/arduino-tutorials-chapter-22-aref-pin/


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?
Logged

Santiago de Chile
Offline Offline
God Member
*****
Karma: 15
Posts: 515
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Work for what you love

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2547
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 123
Posts: 5274
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The man page says:

Quote
... 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....

« Last Edit: August 11, 2014, 12:45:45 am by JimboZA » Logged

What's Jen doin' wit' de Internet?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 318
Posts: 26927
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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")
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 123
Posts: 5274
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So 1024 it is?
Logged

What's Jen doin' wit' de Internet?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2547
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 318
Posts: 26927
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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" )
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 123
Posts: 5274
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
Logged

What's Jen doin' wit' de Internet?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 35023
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem here is that you have not defined the question

http://tronixstuff.com/2013/12/12/arduino-tutorials-chapter-22-aref-pin/


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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 318
Posts: 26927
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: