I have a temperature sensor hooked and a fan hooked up to the arduino. The objective of this is that when the temperature sensor reads above a certain number the fan shuts off. The fan is wired up through a transistor and hooked up to the arduino. The fan is also connected to a 9V power source. I have tested the wiring and everything is correct but I can't seem to get the fan to shut off when it reads above a certain temperature. Any help would be great thanks.
const int temperatureSensor = A0;
const int fanPin = 1;
const int threshold = 56;
int temp1;
void setup (){
pinMode (fanPin,OUTPUT);
Serial.begin (9600);
}
void loop() {
int analogValue = analogRead (temperatureSensor);
temp1 = (0.0049100analogValue-50)*(9/5)+32;
Serial.println(temp1);
delay(500);
if (temp1 < threshold) {
digitalWrite(fanPin, HIGH);
}
else {
digitalWrite(fanPin, LOW);
}
}
The equation in the temp1 line is just a conversion from celcius to fahrenheit