I recently attempted to use my Uno R3 and TMP36 sensor to start a basic home automation project. I connected the sensor following the intro guide here (https://www.sparkfun.com/tutorial/AIK/ARDX-EG-SPAR-WEB.pdf) It's pretty straight forward, and I was able to get my temperature readings to the console. However, the average temperature was roughly 30-40 degrees below actual ambient temperature, and fluctuated +/- 10 degrees between readings each second. How do I go about diagnosing the problem? The Uno and sensor are about 4 years old and have been sitting in storage, could that impact the sensor?
Do as everyone does: Try an TMP36, notice that it can read the temperature, put it aside, buy a DS18B20.
The TMP36 is a analog temperature sensor, and the Arduino uses the 5V as reference. If your Arduino board is powered via the usb cable, the 5V could change a lot, and that causes the Arduino to read different temperatures.
Are you talking about degrees Celsius ? Then there is probably a bad connection somewhere.
It should work better when you use an external power supply, so the Arduino board can make a steady 5V.
The DS18B20 is a digital temperature sensor, and does not have all those analog troubles. In the Arduino IDE is the Library Manager, use that to install the OneWire and DallasTemperature libraries and try an example of the DallasTemperature library.
The Sparkfun code is too simple for this temp sensor.
Arduino's internal bandgap voltage reference has to be used for sensors like this if you want a stable readout.
Try this. Read the comments for calibrating.
Leo..
// TMP36 temp sensor output connected to analogue input A0
unsigned int total = 0; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
Serial.begin(9600);
}
void loop() {
// read the sensor
for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
total = total + analogRead(A0); // add each value
}
// temp conversion
tempC = total * 0.001632 - 50.0; // value to tempC >>> change last two or three digits slightly to calibrate temp <<<
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
Serial.print("The temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celcius ");
Serial.print(tempF, 0); // no decimal places
Serial.println(" Fahrenheit");
total = 0; // reset total
delay(500); // slows readings
}