#define BLYNK_PRINT Serial #include #include "char auth[] = ""X1DqjhmiaznrS3LuV8BVYQoNLLY1qXAq""; // Put your Auth Token here. (see Step 3 above)" "char ssid[] = ""kao"";" "char pass[] = ""09091999"";" #define Pump D6 //Pump #define solinoid D7 //solinoid const int Trig = D3; int echo = D0; #define sensorPin D4 // WeMos & NodeMCU D3 BlynkTimer timer; WidgetLED led1 (V9); WidgetLED led2 (V10); int level; bool isFirstConnect = true; bool Over = false; int Level_max = 0; int Level_min = 0; float percen = 0; int check_pump; int check_solinoid; int check_sensorPin; BLYNK_WRITE(V0) ///control solinoid { int button = param.asInt(); if(button == 1){ " digitalWrite(solinoid,HIGH);" check_solinoid = 1; }else{ " digitalWrite(solinoid,LOW);" check_solinoid = 0; } if(check_solinoid == 1){ led2.on(); } if(check_solinoid == 0){ led2.off(); } } BLYNK_WRITE(V5) ///control pump { int button = param.asInt(); if(button == 1){ " digitalWrite(Pump,HIGH);" check_pump = 1; }else{ " digitalWrite(Pump,LOW);" check_pump = 0; } if(check_pump == 1){ led1.on(); } if(check_pump == 0){ led1.off(); } } /////////Read data from blynk numeric input BLYNK_WRITE(V1) { int value = param.asInt(); // Assigning incoming value from pin V3 to a variable Level_max = value; } /////////Read data from blynk numeric input BLYNK_WRITE(V2) { int value = param.asInt(); // Assigning incoming value from pin V3 to a variable Level_min = value; } ////// read data from DHT void LevelSensor() { "long duration, cm,level;" "pinMode(Trig, OUTPUT);" "digitalWrite(Trig, LOW);" delayMicroseconds(2); "digitalWrite(Trig, HIGH);" delayMicroseconds(5); "digitalWrite(Trig, LOW);" "pinMode(echo, INPUT);" "duration = pulseIn(echo, HIGH);" cm = microsecondsToCentimeters(duration); level = 58 - cm; percen = level * 585.35/1000; " Serial.print(""level = "");" Serial.print(level); " Serial.println("" cm"");" Serial.println(sensorPin); " Blynk.virtualWrite(V3, level);" " Blynk.virtualWrite(V4, percen);" if(level < Level_min ){ " digitalWrite(Pump,HIGH);" check_pump = 1; } if(level > Level_max ){ " digitalWrite(Pump,LOW);" check_pump = 0; } if(check_pump == 1){ led1.on(); } if(check_pump == 0){ led1.off(); } } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. "// The ping travels out and back, so to find the distance of the" // object we take half of the distance travelled. return microseconds / 29 / 2; } void setup() { // Debug console Serial.begin(115200); " pinMode(sensorPin, INPUT);" " digitalWrite(sensorPin, LOW);" " pinMode(Pump,OUTPUT);" " digitalWrite(Pump,LOW);" " pinMode(solinoid,OUTPUT);" " digitalWrite(solinoid,LOW);" " Blynk.begin(auth, ssid, pass,""pkdb10.thddns.net"",8334); " " timer.setInterval(1000L, LevelSensor);" " timer.setInterval(30000L, reconnectBlynk); " " attachInterrupt(digitalPinToInterrupt(sensorPin), PumpOff, RISING);" } void loop() { if (Blynk.connected()) { Blynk.run(); } timer.run(); } ICACHE_RAM_ATTR void PumpOff(){ detachInterrupt(digitalPinToInterrupt(sensorPin)); " digitalWrite(Pump,LOW);" " attachInterrupt(digitalPinToInterrupt(sensorPin), PumpOff, RISING);" } void reconnectBlynk() { if (!Blynk.connected()) { if(Blynk.connect()) { " BLYNK_LOG(""Reconnected"");" } else { " BLYNK_LOG(""Not reconnected"");" } } } BLYNK_CONNECTED() { if (isFirstConnect) { Blynk.syncAll(); " Blynk.notify(""Test! v_1.0"");" isFirstConnect = false; } }