I’m running a DHT-22 and a L3336 thermistor off an Arduino uno with the below code. The DHT-22 works fine, but the thermistor is running backwards i.e when we heat it the output temperature goes down, whilst when we cool it the output temperature becomes higher. I’m not sure if it is the code that isn’t working or our thermistor. From all that I’ve seen the thermistor is a NTC (because PTC is mainly used for circuit breakers rather than measuring temperature) so I believe that my code should be the right way around for this. I’ve tried a few different thermistors from this batch and they all have the same problem, any ideas?
#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 pad = 1000; // balance/pad resistor value, set this to
// the measured resistance of your pad resistor
float thermr = 1000; // thermistor nominal resistance
float Thermistor(int RawADC) {
long Resistance;
float Temp; // Dual-Purpose variable to save space.
Resistance=pad*((1024.0 / RawADC) - 1);
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celsius
// 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(19200);
}
void loop() {
float temp;
temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
Serial.print("Celsius: ");
Serial.print(temp,1); // display Celsius
Serial.println("");
delay(1000); // Delay a bit...
}