I am having trouble getting coherent results from a TMP36 Thermistor. My circuit is
wired up as
using this code
// general constants
// we tie 3.3V to ARef
#define AREF_VOLTAGE 3.3
//the analog pin the TMP36's Vout
#define TEMP_PIN 1
// debug info switch
#define DEBUG true
// 15 minutes between data collections (ms)
#define INTERVAL 2000 // 900000
// general variables
// last time readings were taken
unsigned long previousMillis = millis();
// present moment
long currentMillis;
// the analog reading from the sensor
int tempReading;
// voltage
float voltage;
// temperature in Celsius
float temperatureC;
// temperature in Fahreinheit
float temperatureF;
/*==========================================*/
void setup()
{
// send debugging information via the Serial monitor
Serial.begin(9600);
// initialize for output
Serial.println("CLEARDATA");
Serial.println
("LABEL,Current Time,Raw Data,Voltage,Centigrade,Fahreinheit");
// read into TEMP_PIN
pinMode(TEMP_PIN, INPUT);
// set the aref to something other than 5v
analogReference(EXTERNAL);
} // end setup()
/*==========================================*/
void loop()
{
// get the present moment
currentMillis = millis();
// see if it is time to work
if (currentMillis - previousMillis >= INTERVAL)
{
// save the current time
previousMillis = currentMillis;
// get the reading from the sensor and show it
tempReading = analogRead(TEMP_PIN);
if (DEBUG)
{
Serial.print("Temp reading = ");
Serial.print(tempReading);
}
// converting that reading to voltage, which is based off
// the reference voltage and s
voltage = tempReading * AREF_VOLTAGE;
voltage /= 1024.0;
if (DEBUG)
{
Serial.print(" which equates to ");
Serial.print(voltage);
Serial.println(" volts");
}
// convert from 10 mv per degree with 750 mV offset
// to degrees ((voltage - 750 mV) times 100)
// and show it
temperatureC = (voltage - 0.75) * 100;
if (DEBUG)
{
Serial.print(temperatureC);
Serial.println(" degrees C");
}
// now convert to Fahrenheight and show it
temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
if (DEBUG)
{
Serial.print(temperatureF);
Serial.println(" degrees F");
Serial.println();
Serial.println();
}
// export the data to PLX-DAQ
Serial.print("DATA,TIME,");
Serial.print(tempReading);
Serial.print(',');
Serial.print(voltage);
Serial.print(',');
Serial.print(temperatureC);
Serial.print(',');
Serial.println(temperatureF);
} // end if time check
}
The code was adapted from this [adafruit tutorial](Using a Temp Sensor | TMP36 Temperature Sensor | Adafruit Learning System --) and originally used a voltage offset of 0.5 V. This gave the following overnight output
which shows, effectively, no temperature variation (and the temperature higher than it was,
When I checked the TMP36 Datasheet I found the Output Voltage listed as 0.75 V so I adjusted the code as shown above. Sadly, this gives the following output
Opening port
Port open
CLEARDATA
LABEL,Current Time,Raw Data,Voltage,Centigrade,Fahreinheit
Temp reading = 221 which equates to 0.71 volts
-3.78 degrees C
25.20 degrees F
DATA,TIME,221,0.71,-3.78,25.20
Temp reading = 221 which equates to 0.71 volts
-3.78 degrees C
25.20 degrees F
DATA,TIME,221,0.71,-3.78,25.20
Temp reading = 221 which equates to 0.71 volts
-3.78 degrees C
25.20 degrees F
DATA,TIME,221,0.71,-3.78,25.20
Temp reading = 222 which equates to 0.72 volts
-3.46 degrees C
25.78 degrees F
DATA,TIME,222,0.72,-3.46,25.78
Temp reading = 221 which equates to 0.71 volts
-3.78 degrees C
25.20 degrees F
This is Perth, Western Australia in high summer and I can assure you that it is not that cold
How do I get an accurate output?
Thanks