I made a project where a fan turns on after the temperature exceeds 73.5 F and turns off when it goes below 73.5 F.The problem is when the temp data is being sent to the serial monitor, it's showing 140 F and 120 F ,etc.,when it's actually about 70-80 F in the room.Sometimes it works when I start it up and shows:74 F,but mostly the serial monitor shows temperature values in the 100-160 range.Any reason or coding problem?Is it a bad sensor?I modified the love o meter code from the starter kit examples on the arduino ide.I think its a Celsius to Fahrenheit conversion problem because the love o meter sent values to the serial monitor in celsius but I used a formula to convert it to fahrenheit.A1 gets the data from the temp sensor.Digital Pin 3 is an output that controls the motor.What does the second line do? Here is the code:
const int sensorPin = A1;
const float baselineTemp = 20.0;
void setup(){
Serial.begin(9600);
pinMode(3,OUTPUT);
}
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);
Serial.print(", degrees F: ");
float temperature = ((voltage - .5) * 100*1.8)+32;
Serial.println(temperature);
if(temperature>73.5)
{
digitalWrite(3,HIGH);
}
else
{
digitalWrite(3,LOW);
}
}