 # Temp sensor code

Hallo

I have one of these sensor: Temp sensor

they write both: 40°C to 120°C 0°C to 150°C

In the text.

Do i wire it op to 5v and A0 or to gnd and A0?

and what would the code for this look like? they write 29150 - 1270 Ω how to convert it to degrees.

I'm pretty new to arduino. hope you can help.

/ Bruno, Denmark

and what would the code for this look like? they write 29150 - 1270 Ω how to convert it to degrees.

This looks like a thermistor--hopefully it is NTC (negative temperature coefficient) where the resistance goes down with increasing temperature. It's not clear what the resistance is at 25C and the temperature coefficient of the device from the details you posted.

Wiring and Code for reading this device can be found here in the Arduino Playground. Focus on the third example "The Elaborate Code (cleaned up a bit)". http://playground.arduino.cc/ComponentLib/Thermistor2

Do i wire it op to 5v and A0 or to gnd and A0?

The sensor will be part of a resistor divider network and the test codes referenced above are based on a wiring of the Arduino analog input between the thermistor and the reference thermistor with the thermistor connected at one end to 5v an d the reference resistor on the ground side of the divider.

(Ground) ---- (10k-Resistor) -------AnalogRead pin------- (Thermistor) ---- (+5v)

thanks...

Thermistors aren't linear so you need the Steinhart-Hart model or Beta model to convert resistance to temperature. To get the coefficients for those equations you can measure the resistance at three known temperatures. Typically you would use room temperature, ice water (0°C) and boiling water (100°C).

cattledog:
This looks like a thermistor
<…>

(Ground) ---- (10k-Resistor) -------AnalogRead pin------- (Thermistor) ---- (+5v)

The lasttime I messed with one (Europa aircraft) the “stock” series resistor was 910 Ohms. As the sensor screws into the block, negative ground vehicles would mean your diagram is backwards.

I think this is correct:
Ground) ---- (Thermistor) -±- (910-Resistor)---- (+5v)

Connect Ax on the Arduino to “+” junction of thermistor/resistor.

Steinhart-Hart equation works well.
While this has little to do with Op’s question, it is a remarkable analysis on thermistors by a late friend.
http://www.phanderson.com/picaxe/lin_thermistor.html

Rotax CHT sender.pdf (38 KB)

Rotax Sensor data.pdf (957 KB)

@mrburnett

The lasttime I messed with one (Europa aircraft) the "stock" series resistor was 910 Ohms. As the sensor screws into the block, negative ground vehicles would mean your diagram is backwards.

Ray, I'm not sure what the OP actually has, but I think that if the sensor were meant to be grounded at the block, it would have only one lead instead of two. How may leads did the Europa sensor have?

Also, if the resistance range is 29150 - 1270 Ω I'm not sure that 910 ohm would be better than 10K for capturing the range.

@mrburnett Ray, I'm not sure what the OP actually has, but I think that if the sensor were meant to be grounded at the block, it would have only one lead instead of two. How may leads did the Europa sensor have?

Also, if the resistance range is 29150 - 1270 Ω I'm not sure that 910 ohm would be better than 10K for capturing the rang

Good point! The Europa only has the 1 terminal. The Op only needs to check the two terminals on his/her unit with an Ohm meter to the unit base... if there is infinite resistance between either lead and the thermistor case, then the initial wiring diagram can be utilized.

Ray

Now I have tried The Elaborate Code (cleaned up a bit)

with the Steinhart-Hart equation

my data is:

40c = 23000ohm
56c = 12000ohm
84c = 5000ohm

and that gave me in the calculator:

a= -0.6413404425
b= 4.609515679
c= -7.845300961

that i used to put ind to the Elaborate Code

``````/*
* Inputs ADC Value from Thermistor and outputs Temperature in Celsius
*  requires: include <math.h>
* Utilizes the Steinhart-Hart Thermistor Equation:
*    Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]3}
*    where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08
*
* These coefficients seem to work fairly universally, which is a bit of a
* surprise.
*
* Schematic:
*   [Ground] -- [10k-pad-resistor] -- | -- [thermistor] --[Vcc (5 or 3.3v)]
*                                               |
*                                          Analog Pin 0
*
* In case it isn't obvious (as it wasn't to me until I thought about it), the analog ports
* measure the voltage between 0v -> Vcc which for an Arduino is a nominal 5v, but for (say)
* a JeeNode, is a nominal 3.3v.
*
* The resistance calculation uses the ratio of the two resistors, so the voltage
* specified above is really only required for the debugging that is commented out below
*
*
* I have used this successfully with some CH Pipe Sensors (http://www.atcsemitec.co.uk/pdfdocs/ch.pdf)
* which be obtained from http://www.rapidonline.co.uk.
*
*/

#include <math.h>

#define ThermistorPIN 0                 // Analog Pin 0

float vcc = 4.91;                       // only used for display purposes, if used
// set to the measured Vcc.
float thermr = 10000;                   // thermistor nominal resistance

long Resistance;
float Temp;  // Dual-Purpose variable to save space.

Temp = log(Resistance); // Saving the Log(resistance) so not to calculate  it 4 times later
Temp = 1 / (-0.6413404425 + (4.609515679 * Temp) + (-7.845300961 * Temp * Temp * Temp));
Temp = Temp - 273.15;  // Convert Kelvin to Celsius

// BEGIN- Remove these lines for the function not to display anything
//Serial.print("/1024");                           // Print out RAW ADC Number
//Serial.print(", vcc: ");
//Serial.print(vcc,2);
//Serial.print(" Kohms, Volts: ");
//Serial.print(", Resistance: ");
//Serial.print(Resistance);
//Serial.print(" ohms, ");
// END- Remove these lines for the function not to display anything

// Uncomment this line for the function to return Fahrenheit instead.
//temp = (Temp * 9.0)/ 5.0 + 32.0;                  // Convert to Fahrenheit
return Temp;                                      // Return the Temperature
}

void setup() {
Serial.begin(9600);
}

void loop() {
float temp;
Serial.print("Celsius: ");
Serial.print(temp,1);                             // display Celsius
//temp = (temp * 9.0)/ 5.0 + 32.0;                  // converts to  Fahrenheit
//Serial.print(", Fahrenheit: ");
//Serial.print(temp,1);                             // display  Fahrenheit
Serial.println("");
delay(5000);                                      // Delay a bit...
}
``````

but it returne :
Celsius: -273.2

all the time.

can you help me with what I’m doing wrong?

/Bruno

``````Temp = 1 / (-0.6413404425 + (4.609515679 * Temp) + (-7.845300961 * Temp * Temp * Temp));
``````

You are not using the coefficients for the A,B,C values established with the calculator.

A = -0.6413404425 e-3 B = 4.609515679 e-4 C = -7.845300961 e-7

``````Temp = 1 / (-0.0006413404425 + (0.0004609515679 * Temp) + (-0.0000007845300961 * Temp * Temp * Temp));
``````

Thanks so much for your help... soon i need to pay you for alle the helt you give.. :)