So I am having a problem in this project with the TMP temperature input that is used. Every time I open the serial monitor, the first value for temperature I get is very low and random. Each value after that is always -50.0, and the sensor value (out of 1023) is 0. And when I tried to put my finger around the sensor, the readings did not change. Is my TMP not working, or is there another issue I am overlooking?
I believe that the program I wrote is the same as the one written in the kit's book, but I'm not sure, so I will post it below.
const int sensorPin = A0;
const float baselineTemp = 20.0;
void setup(){
Serial.begin(9600);
for(int pinNum = 2; pinNum < 5; pinNum++){
pinMode(pinNum, OUTPUT);
digitalWrite(pinNum, LOW);
}
}
void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", Volts: ");
Serial.print(voltage);
float temp = (voltage - .5)*100;
Serial.print(", degrees C: ");
Serial.println(temp);
if(temp < baselineTemp){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}else if (temp >= baselineTemp+2 && temp < baselineTemp+4){
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}else if(temp >= baselineTemp+4 && temp < baselineTemp+6){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
}else{
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
delay(1000);
}