I have a temperature control project in which I have a fan that is automatically turned on or off depending on the reading given from a sensor. And that part works fine but now I need a manual override toggle switch which when it is closed/on it will turn the fan on until manually switched off. at which point it will resume the normal program. However the switch is constantly reading as high and therefore stopping the rest of the function regardless of the switches position. aside from this, will the code work as intended once this issue is fixed or am I missing something?
edit: my switch pin is connected 1 to pin 7 and 3 to 5V.
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(fan,OUTPUT);
pinMode(switch_pin, INPUT);
delay(500);
}//Delay to let system boot
void loop() {
if
(digitalRead(switch_pin) == HIGH)
{digitalWrite(fan,LOW);
lcd.setCursor(0,1);
lcd.print("Manual Stop");
Serial.print("Manual Stop");}
if
(digitalRead(switch_pin) == LOW){
DHT.read11(dht_apin);
Serial.print(" Temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(1500);//Wait 1.5 seconds before accessing sensor again.
lcd.setCursor(0,0);
lcd.print(DHT.temperature);
lcd.println(" *C");
if
(isnan(DHT.temperature)) {
Serial.println(" Failed to read transformer temperature");
lcd.print("Failed reading");}
if
(DHT.temperature>=40)
{digitalWrite(fan,HIGH);
lcd.setCursor(0,1);
lcd.print("Fan = ON");
Serial.print("Fan = ON");}
else
{digitalWrite(fan,LOW);
lcd.setCursor(0,1);
lcd.print("Auto Fan = OFF");
Serial.print("Auto Fan = OFF");}
}
}
TEMP_SENSOR_PROJECT.ino (1.31 KB)