I recently bought an Arduino Uno starter kit and proceeded to do the projects in the book that came with it. In project 03 (Love-O-Meter) I ran into some problems. The temperature sensor returned what seemed like arbitrary, but somewhat constant values. In addition, it seemed to 'cool' instantly when I touched it or even when I came close to the sensor.
I tried to troubleshoot the problem, by making a simple circuit just for reading the sensor (see attached photo), and wrote the following code:
const int sensorPin = A1;
void setup() {
Serial.begin(9600); // open serial port?
}
void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
// Convert ADC reading to voltage
float voltage = (sensorVal / 1024.0) * 5.0;
Serial.print(", Volts: ");
Serial.print(voltage);
// Convert voltage to temperature
float temperature = (voltage - .5) * 100.0;
Serial.print(", degrees C: ");
Serial.println(temperature);
delay(10);
}
Now the sensor returns 0s, and an occasional 1, i.e.:
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 1, Volts: 0.00, degrees C: -49.51
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Sensor Value: 0, Volts: 0.00, degrees C: -50.00
Thinking the sensor might be broken, or short-circuiting, I bought a new one. Unfortunately, the problem persisted.
I replaced the temperature sensor with the potentiometer, and that worked like I expected (i.e. analogRead returns values between 0 & 1023, depending on the position of potentiometer).
Is this a typical read-out for a broken TMP36? If so, what could I have done that caused it to go defective? Or am I overlooking something?