At the first part of the video (Part-A), I will explain each line of the small code.
At the second part of the video (Part-B) I will build the hardware.
I build a solution to power on a water pump(or other 220v devices) when there is water overflow.
You can do it to power on other AC (220V) appliances such as Lights, TVs, etc.
Serial.println("Relay-1 is OFF");
Serial.println ("Relay-2 is OFF");
Serial.print("\n");
}
void loop() {
sensorState= digitalRead(sensor);
//Serial.println(sensorState);
if (sensorState == HIGH) { // check if the sensor is in water(short circuit)
digitalWrite(relay1, !(HIGH)); // turns Relay1 ON
digitalWrite(relay2, !(HIGH)); // turns Relay2 ON
if (flag==0){
flag=1;
Serial.println("relays are now ON");
}
}
else{
digitalWrite(relay1, !(LOW)); // turns Relay1 OFF
digitalWrite(relay2, !(LOW)); // turns Relay2 OFF
if (flag==1){
flag=0;
Serial.println("relays are now OFF");
}
}
} //loop end bracket