Pages: [1]   Go Down
Author Topic: analogRead always returning 1023  (Read 244 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been trying to get a thermistor reading but despite all my best attempts, I am always getting 1023.  I have tried 3 different thermistors, 2 different Unos (and different analog pins) as well as different breadboards, wires, and 10k resistors.  No matter what, I've tried, the results are the same.

This is the wiring I am using (taken from Adafruit) :



I've also tried putting the 10k resistor between the thermistor and ground.

Here is the code sample I'm using:

Code:
#define SERIESRESISTOR 10000   
#define THERMISTORPIN A0
 
void setup(void) {
  Serial.begin(9600);
  pinMode(THERMISTORPIN, INPUT);
}
 
void loop(void) {
  float reading;
 
  reading = analogRead(THERMISTORPIN);
 
  Serial.print("Analog reading ");
  Serial.println(reading);
 
  reading = (1023 / reading)  - 1;
  reading = SERIESRESISTOR / reading;
  Serial.print("Thermistor resistance ");
  Serial.println(reading);
 
  delay(1000);
}

I'm sure it's something horribly obvious that I am missing, thanks.
Logged

Offline Offline
God Member
*****
Karma: 48
Posts: 665
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Try removing this statement:

Code:
pinMode(THERMISTORPIN, INPUT);

Analog pins are analog inputs by default.  Using pinMode on them configures them to work as digital inputs.

Regards

Ray
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17253
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Take you meter and measure just the sensor's resistance at ambient temp and tell us the value.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Try removing this statement:

Code:
pinMode(THERMISTORPIN, INPUT);

Analog pins are analog inputs by default.  Using pinMode on them configures them to work as digital inputs.

Regards

Ray


I had originally tried without that line and only added it in when I was troubleshooting.  Removing it makes no difference.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Take you meter and measure just the sensor's resistance at ambient temp and tell us the value.

~9.29
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13469
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ohm or kilo ohm or mega ohm ?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Logged

Oregon, USA
Offline Offline
Edison Member
*
Karma: 65
Posts: 2122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use your multimeter to measure the voltage between the analog input pin and ground. What do you get?
Logged

"It seems to run on some form of electricity"

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

shouldnt your statement: #define THERMISTORPIN A0   be:
#define THERMISTORPIN 0
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use your multimeter to measure the voltage between the analog input pin and ground. What do you get?

If I'm doing this right (been 15+ years since I've done any electronics work) 4.95V is what I'm getting from the multimeter between  analog and ground.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

shouldnt your statement: #define THERMISTORPIN A0   be:
#define THERMISTORPIN 0

Wouldn't 0 be the digital 0?  The examples and documentation I've read all seem to imply that you would want to use A0 for analog 0.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17253
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use your multimeter to measure the voltage between the analog input pin and ground. What do you get?

If I'm doing this right (been 15+ years since I've done any electronics work) 4.95V is what I'm getting from the multimeter between  analog and ground.

Then there has to be something not making proper contact on your breadboard or wired different then the picture. The analogRead is telling you the same thing that your meter is measuring between A0 and ground.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It turned out to be a bad wire.  Getting an actual reading now:

Analog reading 925.00
Thermistor resistance 94387.76

Thanks for the help!
Logged

Pages: [1]   Go Up
Jump to: