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.
Part-A (Code explanation).
Video link for Part-A below this line:
https://youtu.be/mQLTWnA4ZHI
Download code here: Download link
or copy the code unter this line:
#define relay1 4 //Defines pin 4
#define relay2 7 //Defines pin 7
#define sensor 2 //Define sensor pin 2 (input pin)
#define alwaysHigh 10 //gives 5v to the sensor
//#define ledPin 8
int sensorState=0; //keeps the reading of sensor pin 2 (high or low)
int flag=0; // Takes values 0 or 1. When the sensorState changes.
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
//pinMode(ledPin, OUTPUT); // Set the LED pin as output
pinMode(sensor, INPUT); // Set the Sensor pin as input
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode (alwaysHigh, OUTPUT); //5V sourch, gives power to sensor
digitalWrite(relay1, !(LOW)); //OFF
digitalWrite(relay2, !(LOW)); //OFF
digitalWrite(alwaysHigh, HIGH); //ON
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
Part-B (Hardware)
Video link for Part-B below this line:
https://youtu.be/mimGR6aEHNA
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.
Part-A (Code explanation).
https://youtu.be/mQLTWnA4ZHI
Download code here: Download link
or copy the code unter this line:
#define relay1 4 //Defines pin 4
#define relay2 7 //Defines pin 7
#define sensor 2 //Define sensor pin 2 (input pin)
#define alwaysHigh 10 //gives 5v to the sensor
//#define ledPin 8
int sensorState=0; //keeps the reading of sensor pin 2 (high or low)
int flag=0; // Takes values 0 or 1. When the sensorState changes.
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
//pinMode(ledPin, OUTPUT); // Set the LED pin as output
pinMode(sensor, INPUT); // Set the Sensor pin as input
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode (alwaysHigh, OUTPUT); //5V sourch, gives power to sensor
digitalWrite(relay1, !(LOW)); //OFF
digitalWrite(relay2, !(LOW)); //OFF
digitalWrite(alwaysHigh, HIGH); //ON
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
Part-B (Hardware)
Video link for Part-B below this line:
https://youtu.be/mimGR6aEHNA
Interesting project. ,😁😁
ReplyDelete