Temp Sensor Help

Let it be known this is my first project. I'm trying to replicate some of the aspects of this project,
http://hruska.us/tempmon/

I have a uno and it is hooked up like so,

Larger Version
http://www.2kgt.com/s3/bbq/IMG_6221.jpg

I have uploaded a basic sketch that just writes the value coming from A0 to serial.

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
unsigned int food_temp = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Start bbq mon");
  delay(2000);  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  food_temp = thermister_temp(sensorValue);
  Serial.println(food_temp);  
  delay(2000);
 }

int thermister_temp(int aval) {
	double R, T;

	// These were calculated from the thermister data sheet
	//	A = 2.3067434E-4;
	//	B = 2.3696596E-4;
	//	C = 1.2636414E-7;
	//
	// This is the value of the other half of the voltage divider
	//	Rknown = 22200;
        int Rknown = 21630;
	// Do the log once so as not to do it 4 times in the equation
	//	R = log(((1024/(double)aval)-1)*(double)22200);
	R = log((1 / ((1024 / (double) aval) - 1)) * (double) Rknown);
	//lcd.print("A="); lcd.print(aval); lcd.print(" R="); lcd.print(R);
	// Compute degrees C
	T = (1 / ((2.3067434E-4) + (2.3696596E-4) * R + (1.2636414E-7) * R * R * R)) - 273.25;
        
	// return degrees F
	return ((int) ((T * 9.0) / 5.0 + 32.0));
}

The output from Serial just jumps back and forth from 7 and 9 sitting on my table in my office where it's about 75*F, so I get something like
7
9
7
9
7
9
9
7
7
7

That is a 22K Resistor and a Maverick ET-732 Probe.

Any ideas what I screwed up? Code? Connections? I'm not much of a hardware guy, mostly software but this stuff just seems too cool not to start messing around with.

Thanks,
Chad

whats that probe? just a resistor that changes its value with temperature?

can u just quickly draw a schematic of how u connected everything, would be easier for me as id like to try and help u

That would be my guess. I got them off ebay as replacements for this unit,
http://www.maverickhousewares.com/et732.htm

Chad

can u quickly draw a schematic in paint how u connected everything? looks to me that u dont use any analog input

Well I think i have it hooked up just like this,


Only no blower, no LCD and only 1 Temp Probe (in A0).

If you look at the larger pic (and zoom) you'll see I have an orangeish wire hooked to A0, which then goes to the breadboard column 'D'. Then the green wire in Column 'C' goes to the 'Tip' of the probe. 22k resistor is in Column A going to +5v. Ring of probe is grounded.

Make sense?
Chad

maybe try my code. i had problems with a tutorial, so i calculated a formula which should fit for u too, as u have the same order of resistor and thermistor.
Hope i altered it right, see if it works.

#include <math.h>

#define ThermistorPIN 0                 

#define printByte(args)  write(args);


double vs;                      
long Resistance; 
float Temp; 
float Thermistor(int RawADC) {
  Resistance=((-1.0*RawADC*5.0/1024.0*22000.0)/(RawADC*5.0/1024.0-5.0));

  Temp = log(Resistance); 
  Temp = 1 / (0.00023067434 + (0.00023696596 * Temp) + (0.00000012636414 * Temp * Temp * Temp));
  Temp = ((Temp - 273.15));  // Convert Kelvin to Celsius                      
  vs = RawADC*(5.0/1023.0);

  Serial.print("ADC: "); 
  Serial.print(RawADC); 

  Serial.print(" Kohms, Volts: "); 
    
  Serial.print(", Resistance: "); 
  Serial.print(Resistance);

  return Temp;                                      // Return the Temperature
}

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

void loop() {
  
  
  
  float temp;
  temp=Thermistor(analogRead(ThermistorPIN));       // read ADC and  convert it to Celsius
  Serial.print("Celsius: "); 
  Serial.print(temp,1);    

  Serial.println("");                                   
  delay(1000);                                      // Delay a bit... 
}

if its not working, maybe i made a mistake by changing it for u, this is my original working code.

int switchPin = 2;              // switch is connected to pin 2
int val;                        // variable for reading the pin status
int buttonState; 
#include <math.h>

#define ThermistorPIN 0                 // Analog Pin 0

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

#define I2C_ADDR    0x27  // Define PCF8574A's I2C Address

#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

#define  LED_OFF  0
#define  LED_ON  1


#define printByte(args)  write(args);

  
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);


double vs;                      
long Resistance; // thermistor nominal resistance
float Temp;  // Dual-Purpose variable to save space.

float Thermistor(int RawADC) {
  Resistance=((-1.0*RawADC*5.0/1023.0*10000.0)/(RawADC*5.0/1023.0-5.0));

  Temp = log(Resistance); 
  Temp = 1 / (0.00524521 + (-0.00052519684 * Temp) + (0.0000041635158 * Temp * Temp * Temp));
  Temp = ((Temp - 273.15));  // Convert Kelvin to Celsius                      
  vs = RawADC*(5.0/1023.0);

  Serial.print("ADC: "); 
  Serial.print(RawADC); 

  Serial.print(" Kohms, Volts: "); 
    
  Serial.print(", Resistance: "); 
  Serial.print(Resistance);

  return Temp;                                      // Return the Temperature
}

void setup() {
  Serial.begin(9600);
   lcd.begin (20,4);  // initialize the lcd 
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(LED_ON);

  lcd.home();
 pinMode(switchPin, INPUT);    // Set the switch pin as input

  
 buttonState = digitalRead(switchPin); 
}

void loop() {
   val = digitalRead(switchPin);
 if (val != buttonState) { 

     if (val == LOW) {  
    // turn LED on:    
     lcd.setCursor(0, 0);
  lcd.setCursor(7, 0);
  lcd.print(Resistance); 
  lcd.setCursor(0, 1);
 

  lcd.print("    Temperatur:  ");

  lcd.setCursor(0, 2);

  lcd.setCursor(6, 2);
  lcd.print(Temp); 
  lcd.print((char)223);
  lcd.print("C"); 
  lcd.setCursor(0, 3);
   } 
  else {
   
   lcd.setCursor(2, 3);
   lcd.print(vs);
   delay(5000);
      
      
    
    
 }
  
  
  buttonState = val;
  
  
  
  float temp;
  temp=Thermistor(analogRead(ThermistorPIN));       // read ADC and  convert it to Celsius
  Serial.print("Celsius: "); 
  Serial.print(temp,1);    

  Serial.println("");                                   
  delay(1000);                                      // Delay a bit... 
}

With your code I get -14.2. I even tried another sensor same model I just bought 4 of them, same thing. Do you have the ET-732's? If I stick it up in my overhead light the 'C' value goes up the A0 value goes down, does that sound like its working correctly I just need to calibrate it?

I'll be out of town for the next few days but I appreciate all the help!

Chad

well in the first code i tried to use the calibration data u had in ur post.

in my 2nd code there is my own calibration data.

Do you see the "resistance" in ur serial monitor? if that changes when u heat the sensor then its just a calibration issue.

I use this one:
http://www.ebay.de/itm/261026313725?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

Just the upper schematic is important
Differences to u r 10K instead of 22K and N1 is my thermistor, pin3 thats whats going to ur A0, so it seems to be the same as in ur example.
I calibrated with a fever thermometer and another thermometer on 3 points 4°C, 25°C and 40°C and it works fine.
For calibration u need the resistance data i mentioned above:

Yea, I think it's just a calibration issue. I removed all code except the Analog output and when sticking the probe up at a light it changed and removing it made it change. I must have a different one than the other guy used. Any idea how I can find the 3 values for the resistor? I can't seem to find a datasheet anywhere. If I can't find that I'll just do a test that makes it output 0 and 1023 and figure out a conversion chart, does that seem reasonable?

Thanks for the help,
Chad

Absolutely, Boiling water for 100 deg C, ice and salt for 0 deg C and a regular thermometer for in-between values would be a great start. The two extremes and a center point or teo should give you good calibration.

Doc

If I can’t find that I’ll just do a test that makes it output 0 and 1023 and figure out a conversion chart, does that seem reasonable?

not so much

hkchad, all you need is in my posts…i think i have one bracket to much in the code…

read the part in my code that says “resistor” guess what it is for…

what you need to do is take another thermometer, then put that one and ur creation to the same temp, read the serial print on resistor for 3 different temperatures, put those values with the temps in the link i gave u. put those coefficients in the code and voila

Question is if u want to understand and learn something, or just get it working.

#include <math.h>
#define ThermistorPIN 0                 // Analog Pin 0
double vs;                      
long Resistance; 
float Temp;  

  float Thermistor(int RawADC) {
  Resistance=((-1.0*RawADC*5.0/1023.0*22000.0)/(RawADC*5.0/1023.0-5.0));

  Temp = log(Resistance); 
  Temp = 1 / (0.00524521 + (-0.00052519684 * Temp) + (0.0000041635158 * Temp * Temp * Temp));
  Temp = ((Temp - 273.15));                      
  vs = RawADC*(5.0/1023.0);

  Serial.print("ADC: "); 
  Serial.print(RawADC); 
  Serial.print(", Resistance: "); 
  Serial.print(Resistance);
  return Temp;                                      
}
void setup() {
Serial.begin(9600);
}

void loop() {
  float temp;
  temp=Thermistor(analogRead(ThermistorPIN));       
  Serial.print("Celsius: "); 
  Serial.print(temp,1);    
  Serial.println("");                                   
  delay(1000);                                     
}

Ok. I think I have something. So I did like you said and measured the 3 values A,B,C (used my multimeter and the 22k resistor though instead of lugging my stuff to the kitchen) and plugged them into the website and got this,

double A = 4.717016E-4;
double B = 1.90988E-4;
double C = 9.955908E-8;

I then put those in the equation and stuck my probe in a bowl of ice water and this was output,

aval = 1017 32.0 F
aval = 1015 41.0 F
aval = 1016 36.0 F
aval = 1017 32.0 F
aval = 1014 44.0 F
aval = 1016 36.0 F
aval = 1021 4.0 F
aval = 1016 36.0 F
aval = 1017 32.0 F
aval = 1015 41.0 F
aval = 1016 36.0 F
aval = 1017 32.0 F
aval = 1017 32.0 F
aval = 1022 -8.0 F
aval = 1017 32.0 F
aval = 1017 32.0 F
aval = 1018 26.0 F
aval = 1016 36.0 F
aval = 1018 26.0 F
aval = 1016 36.0 F
aval = 1017 32.0 F

aval is the value from analogRead. That was on a 2 sec delay. Any idea why the values jump around so much? Is that normal? In my final program should I take the average of aval over say 10 seconds pass that to the equation and return that as the actual temp? I even tried another sensor, same model, and got similar results.

Thanks for the help!
Chad

used my multimeter and the 22k resistor

that doesnt make any sense to me, u need the resistance of ur probe at certain temperatures

Any idea why the values jump around so much?

something is wrong

These probes are also subject to more mysterious errors than the ET-72/73 probes, making the temperatures fluctuate for no apparent reason. The only solution is to ground the probe's braided shielding.