Go Down

Topic: analogRead always returning 1023 (Read 432 times) previous topic - next topic

smcgettrick

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: [Select]

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

Hackscribble

Hello

Try removing this statement:

Code: [Select]
pinMode(THERMISTORPIN, INPUT);

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

Regards

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

retrolefty

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


smcgettrick


Hello

Try removing this statement:

Code: [Select]
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.

smcgettrick


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


~9.29

robtillaart

Rob Tillaart

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


jremington

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

Ed1960

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

smcgettrick


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.

smcgettrick


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.

retrolefty



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.

smcgettrick

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!

Go Up