I have a problem with my Arduino based sprinkler system…and I would like to gather some ideas from you side, if possible, to find the best way to solve it. The “system” is quite simple…I have one Node MCU wifi board, which with the help of some relays, turns off or on the water solenoid valves from the garden. All this is linked to the Blink app (used on Android devices). The problem is that the Node MCU board sometimes it loses signal and disconnects from wifi. If this happens when the solenoid valves are on, the solenoid valves don’t receive anymore the instruction to turn them off when needed…and they simply continue to work…flooding the garden.
Blynk version: 2.27.32
Blynk library version: v1.0.1
Do you know how can I avoid this, by including something in the code (maybe a “safety timer” …?). Below, my current code:
You’re using Blynk legacy. It’s always a good idea to use library version 0.6.1 with Legacy, but it’s an even better idea to switch to Blynk IoT, as legacy will be retired and decommissioned at some point.
Your project uses digital pins, which is another bad idea, you would be far better using virtual pins.
You could use a BlynkTimer to periodically check if your device is connected to WiFi or Blynk, and turn off all of your relays if it isn’t.
It’s probably a good idea to switch to up a managing your own WiFi connection and using Blynk.config and Blynk.connect instead of Blynk.begin
//--------- stop car when connection lost`
BLYNK_WRITE(V12)
{ block_driv = 0;
}
void CarStream() // 0,5 sec
{ block_driv++;
if (block_driv > 3) // stop
{ digitalWrite(AIN1, LOW);
digitalWrite(AIN2, LOW);
}
if (block_driv > 120)
{ ESP.deepSleep (10e6); // after minute of downtime - reboot or sleep
}
if (block_driv < 6) // if blynk automation does not respond, we send no more than 6 messages
{ Blynk.virtualWrite(V12, 0); // otherwise we will overflow buffer.
Blynk.virtualWrite(V12, 1);
}
}