Blynk sprinkler system

Hi Everybody.

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:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx";

void setup()


// Debug console


pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);

digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);

Blynk.begin(auth, ssid, pass);

void loop()

Please edit your post and add triple backticks ( ``` ) before and after your whole sketch.

Sorry for that.

No problem buddy, now can you provide more details please, like blynk IOT or legacy, library version, wiring diagram etc.

Is this the whole code? Only thing you’re doing now is activating (or deactivating) your outputs one time with starting device.

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


Hello. All the configuration I did it directly in Blynk app. The only functionality of the code is the following:

  • To put all the valves “off” when the system is turned on (in case of power shortage);
  • To link the HW with the Blynk app (where the configuration is done).

//--------- stop car when connection lost`
  { 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);