Simple 4 relay irrigation scheduler

@hagay I set timer start 1:05 emd 1:06 but start time 1:05 timer Start and finish at the same time. i see from debug. I removed slider and fix it.

  // MAX DURATION SLIDER INPUT                                                      //
  else if (pin >= VP_MAX_DUR_SCHD0) {                                       //V24..V27
     if (pin < VP_MAX_DUR_SCHD0+SCHEDULER_CNT){ 
         max_duration_sec[pin-VP_MAX_DUR_SCHD0] = 86400;
         max_duration_sec[pin-VP_MAX_DUR_SCHD0] = 864000; // set to 10 days is equivalent to not setting max duration
  else if (pin >= VP_IMMD_ACTV_SCHD0) {                                     //V20..V23
    if ( pin <(VP_IMMD_ACTV_SCHD0+SCHEDULER_CNT) ) {
      if (param.asInt()==0)
        scheduler_turn_off(pin-VP_IMMD_ACTV_SCHD0, 0);
        (pin-VP_IMMD_ACTV_SCHD0,TIME_CNT); // immediate turn on using duration from slider
  // DEFAULT ACTIVE DURATION SLIDER INPUT                                          //
  else if (pin >= VP_ACTV_DUR_SCHD0) {                                       //V16..V19
    // default duration is written in extra "timer"
    if (pin <VP_ACTV_DUR_SCHD0+SCHEDULER_CNT) active_duration_sec[pin-VP_ACTV_DUR_SCHD0][TIME_CNT] = 86400;

@hagay I’ve been studying your code trying to understand its operation. Am I correct that pressing System Sleep will prevent any events from turning on until system sleep button is pressed again? Schedule timers are still running but can’t turn anything on.
However system disable shuts down schedule timers but has limited duration based on shutdown duration?

Yes the sleep mode will temporally turn off all tasks keeping them (and schedule events) live in the background. For example if I use this to control my garden irrigation I may want to temporally prevent the sprinklers while I am out, but once I go in again I want everything to return to it’s prev state.

System disable will shut down everything (turn off every active device and all schedulers) and after end of “disable time” it will only activate devices when reaching start time (not due to old schedules). For example if I connect this to my boiler and am going out to the weekend. Then I will disable the system for the next few days.

The duration of both (if not manually deactivated) is defined by the Disable Days slider.

I see the sleep mode as a more short term then the disable mode. Therefore for my sprinklers I will set the disable days to 0 (Or I can remove it from my app) so that if I forget to activate the system again it will still operate the next day.
Of course you may have your own use case where you can see differently.

A post was merged into an existing topic: How to make Blynk.sync ALL after the power loss?

Hi Arizona, I like your code but I would like to modify your App.

I want control “Zone 1” output with 2 differents start time.

0- Zone 1 T1 (Pin V0) > I use only a start time (Allow start/stop input > NO) : OK (Work fine)
1- I want use a “Zone 1 Duration (MIN)” (Pin V16) for end setting of the Zone 1 : OK (Work fine)

2- I want use a “MAX DURATION” (Pin V24) for end setting of the Zone 1 for a second Zone 1 T2 (Pin V1)

3- These 2 end settings are independents for each 4 Zones.

I’m not able to change your code to get what I want to have mentioned.

Help me. Thank you

Note : I use this hardware



I am running your code and GUI on my NodeMCU. Thks a lot for your good work. I want to add a Rain Delay of maximum 7 days. On GUI I already did under Virtual Pin V33.

  1. is your code ready to do that?
  2. if I select for example 2 days delay. Is it necessary to click on OFF button V50?


Approved 101,

The code I posted does not have rain delay. hagay”s code has what you need but you have to integrate his code into yours. Hagay is an advanced programmer.

I tried to integrate his rain delay into my code but I could not figure it out. I just slide the system to offf manually when it rains.

Thks for your reply. I already show the code in Hagay’s code the reference to Sleep function. I am tripping to adapt but it is not easy for me. For the time being I will use as you are doing. I am able to run it, I will share.

nice project and work very well.
maybe 1 button is missed… i think is userfull to have 1 more button for manual irrigation, like manual automation., and it do start Relay 1, 2, 3,… in sequence. so start 1, after timeout start relay 2, ecc…
This is my first experience with blink, do you think it is possible?

1 Like

Hi to all. I already make my irrigation system work. The problem is the solenoid I have. My former systems was by battery then they are not NC (normally closed), with one electricity signal they open the valve and with another one they close. Now I have a problem because when I activate the system with my app it open the valve and start to irrigate but when I click off it doesn’t stop irrigating. I have 2 options, to buy 4 new valves 9V NC or to do it by software if possible. Any suggestion?

you can change the button to reverse the status (yours will be same like the picture down change 0 to 1 and 1 to 0), on for Low and off for High from the application
without rewriting any code


This is my button, I think it is a problem of hardware. My solenoid is running by pulses, this means that each time you send an small signal of 9v the solenoid change from close to open, then to close, etc. I need solenoid NC 9v.

you could solve this by code only , the button will send the pulse every time to change the solenoid ON/OFF and save the value into variable (integer) and map this value to LED widget (Virtual pin) for example

mostly you have a 9V source there in your old system , use your relay to just pulse this 9V DC as explained above (more easier)

or trigger the 9V source using 3.3V from ESP8266 will need lever shifter

here is the links guiding you to do so (i didn’t tried this before but it should work)
link 2

no need to buy new hardware in my opinion

only an idea
you can control it with BLYNK using MQTT

Thks for your support. This morning I did some test with the solenoid. If I connect it to a 9V battery, red cable to + and black cable to - the solenoid open it. Then if I connect the red cable to - and the black cable to + then solenoid close. It is not necessary to keep supplying electricity all the time the system is irrigating, just one second is enough to change the status of the solenoid.

This is most difficult to solve via software because it’s necessary to change the polarity of the cables.

I should find solenoid NC (usually closed) and then when supplying 9V it will open and when relay will close electricity supplying then it will close again, or I need to find some device between relay and the solenoid which will change the polarity each time it receive energy, I mean … receive energy positive/negative, receive again energy negative/positive, but I think cannot be done.

that is very interesting device that you have i never faced such one , but still can be manipulated using DPDT relays to reverse polarity such module will help

more infor about the DPDT here Link

Thks for your support. I saw this DPDT, if I have 4 relays I need to buy 4 of these DPDT? Where I should put them?

this cheap water tight enclosure should be a good selection for any outdoor thing

Finally I should adapt my code to my 9V latching solenoids. I ordered 2 H Bridges for controlling 4 valves. Now I should adapt my Arizona’s code to reverse polarity.

  1. send 20ms positive to open solenoid
  2. irrigating as per selected time/duration
  3. send 20ms negative to close solenoid

The reverse will be managed by H Bridge. I founded below code that I should adapt.

 Ejemplo de control de motor DC usando modulo L298
 Creado 16/05/14
 por Andres Cruz

int IN3 = 5;    // Input3 conectada al pin 5
int IN4 = 4;    // Input4 conectada al pin 4 
int ENB = 3;    // ENB conectada al pin 3 de Arduino
void setup()
 pinMode (ENB, OUTPUT); 
 pinMode (IN3, OUTPUT);
 pinMode (IN4, OUTPUT);
void loop()
  //Preparamos la salida para que el motor gire en un sentido
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);
  // Aplicamos PWM al pin ENB, haciendo girar el motor, cada 2 seg aumenta la velocidad
  // Apagamos el motor y esperamos 5 seg

I will try but I will need your help.

Thks a lot.

You’ve been posting code here long enough to know that it needs to have triple backticks at the beginning and end.
Please edit your last post to add the code in correctly.


1 Like