Temperature sensor module

I am trying to use an Arduino Uno to read the ambient temperature of a room. Sounds simple i know, but when i connect the temp module to the analog input and map the output to the temperature range for the sensor, i get a result that is nowhere close to ambient temperature. I have attached the spec sheet for the sensor and the code I am using.
i have tried using code from the examples and still don’t get a decent result.I am sure i am missing something pretty basic, but any help would be greatly appreciated.

int sensorPin.pdf (180 KB)

You're missing telling us what sensor you're using. If the code is not yours and it's online, you can just link to it.

. I have attached the spec sheet for the sensor and the code I am using.

As you may have noticed by now, the attachment didn't work...

but when i connect the temp module to the analog input and map the output to the temperature range for the sensor, i get a result that is nowhere close to ambient temperature.

Do the readings go up & down with temperature? (Try a hair dryer and/or some ice.) i.e. Is the sensor doing anything at all?

Could it be a Celsius-Fahrenheit mix-up?

Testing is usually easy. Breathe on it. The temperature will go up, then down as the remaining moisture evaporates.

the code is :

int sensorPin=0;//the analog pin the sensor is connected to
void setup()
Serial.begin(9600); // set the serial comms at 9600 baud

void loop()
int reading=analogRead(A0);
Serial.println(" degrees C");

and the sensor is XC-4538 from Jaycar.
Breathing on the sensor does cause the temperature to go up then down as the moisture evaporates.


The from range is NOT 1023 to -55.

Where did you find that code? I found something that says "Arduino Library Available", but I didn't find the library.

if the readings are going up & down, I have to assume the problem is with the map() values.

Without the schematic or the data for the thermistor I'm not sure how to make the calculations, but you can do some experiments to try and correlate the raw readings with the temperature and make the appropriate changes to the map() values.

P.S. The thermistor should "work" once you get the calibration figured-out, but if you want something that's accurate and linear check out the [u]LM35[/u].

i have been having trouble getting the attachment to upload. this should answer your questions about the sensor.I put the code together myself. the sensor uses One wire Dallas protocol, and the more i read about it the more confused i have become about using an analog pin or digital pin. Code i have looked at for one wire temp sensors don’t specify which pin to use and i don’t know how to read their code to determine the pin addresses. This is why i have gone with a simple analog read bit of code.

int sensorPin.pdf (180 KB)

PaulS: The from range is NOT 1023 to -55. According to the reference help the map function does this:

Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.

now the sensor returns a value between 0 and 1023, by trial and error i have found as the temperature increases the value approaches 0,therefore i remap the scale so that "fromLow"( being 1023) becomes "toLow" now (-55). Is there a flaw in that logic? or have i misundertood the map function?

The documentation does not look correct. I believe that you have a 10K NTC and a 10K fixed resister and you read the value between the two with 5v over the pair. I think this has has nothing to do with Dallas one wire.

Use the thermistor code in this link http://playground.arduino.cc/ComponentLib/Thermistor2 I have successfully used the code noted as "The Elaborate Code (cleaned up a bit)" which is near the bottom.

Jaycar seriously stuffed up here. They have a picture of a 10k thermistor with a 10k resistor on a small circuit board. And they advertise it as a Dallas 1-wire sensor.



Drop the useless code, and find a proper 10k thermistor code. Start by enter "10k thermistor" in the search box on top of this page. Leo..

I have used thermistors for temperature sensing many times. They give excellent and highly reliable results. There is an equation out there called the Hart-Steinhart equation (or maybe other way around) which is not linear, but seems to provide very good accuracy. The thermistor is wired in series with a 10K resistor, from Vcc to ground, and you read the voltage at the center of the voltage divider (of course).

Thanks. I really appreciate all your help. I will try you suggestions.

Cannot see anything in that pdf or the web to say that it uses a 10K thermistor, though it probably is.

If you have a test meter , with the power off you can measure the resistance across the themistors pins.

It will not harm things but the code I use below is a decent NTC routine, set for a 10K themistor.

It also has a good averaging routine to eliminate spurious readings.

NTC_WORKING.zip (82.2 KB)