Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Irrigation Controller (up to 16 valves with Shift Registers)

Irrigation Controller (up to 16 valves with Shift Registers)

Scheduled Pinned Locked Moved My Project
371 Posts 56 Posters 247.9k Views 52 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BulldogLowellB BulldogLowell

    If you are worried about Program Space you can turn off Serial debug to rid yourself of a bunch of overhead in the sketch. I am not using String class so there is PLENTY of RAM and I've been using this for a while with no stack corruption issues:

    #define DEBUG_ON   // comment out to surpress serial monitor output
    

    if you propose to turn ON the master valve when each valve is cycled on, then I believe all you need to do is add that valve to the bitmask (logical OR) each time you updateRelays().

    void updateRelays(int value)
    {
      if(value)
      {
        value |= 0b0000000010000000;  // master is the eighth relay, there are 7 controlled in this example (active HIGH in this example)
      }
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, highByte(value));
      shiftOut(dataPin, clockPin, MSBFIRST, lowByte(value));
      digitalWrite(latchPin, HIGH);
    }
    

    not tested

    fusion_manF Offline
    fusion_manF Offline
    fusion_man
    wrote on last edited by
    #116

    @BulldogLowell

    By commenting out the DEBUG, it went from 99% to 63% used memory.
    The modification to void updateRelays worked very nicely. I only wish the master control valve would remain ON during cycling through each valve (subjected to VALVE_RESET_TIME) as I am using it to control a chemical feed pump to prevent hydrogen proxide (30%) from entering my irrigation system.

    Awesome job and I am very pleased with your design.
    The only problem I had when building the controller was getting the LCD to communicate.
    I added this comment to my program under Instructions.

    • If your LCD is unresponsive, download sketch http://forum.arduino.cc/index.php?topic=128635.0 then check serial monitor for LCD address. Insert your address below.
    1 Reply Last reply
    1
    • BulldogLowellB BulldogLowell

      If you are worried about Program Space you can turn off Serial debug to rid yourself of a bunch of overhead in the sketch. I am not using String class so there is PLENTY of RAM and I've been using this for a while with no stack corruption issues:

      #define DEBUG_ON   // comment out to surpress serial monitor output
      

      if you propose to turn ON the master valve when each valve is cycled on, then I believe all you need to do is add that valve to the bitmask (logical OR) each time you updateRelays().

      void updateRelays(int value)
      {
        if(value)
        {
          value |= 0b0000000010000000;  // master is the eighth relay, there are 7 controlled in this example (active HIGH in this example)
        }
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, MSBFIRST, highByte(value));
        shiftOut(dataPin, clockPin, MSBFIRST, lowByte(value));
        digitalWrite(latchPin, HIGH);
      }
      

      not tested

      fusion_manF Offline
      fusion_manF Offline
      fusion_man
      wrote on last edited by
      #117

      @BulldogLowell

      I ended up going a different approach. I modified the program so I could use Arduino digital pin6 as an output powering my master valve relay. I then added digitalWrite (masterValvePin, HIGH) where you have updateRelays(BITSHIFT_VALVE_NUMBER) to turn ON the valve. To turn off the valve I added a delay then digitalWrite (masterValvePin, LOW) to if (state == STAND_BY_ALL_OFF). This has tested perfectly for my situation.
      The only thing missing from the Controller is the ability to add the RainBird rain sensor to the board. I think the way of achieving this is an input to my Vera controller.

      BulldogLowellB 1 Reply Last reply
      0
      • fusion_manF fusion_man

        @BulldogLowell

        I ended up going a different approach. I modified the program so I could use Arduino digital pin6 as an output powering my master valve relay. I then added digitalWrite (masterValvePin, HIGH) where you have updateRelays(BITSHIFT_VALVE_NUMBER) to turn ON the valve. To turn off the valve I added a delay then digitalWrite (masterValvePin, LOW) to if (state == STAND_BY_ALL_OFF). This has tested perfectly for my situation.
        The only thing missing from the Controller is the ability to add the RainBird rain sensor to the board. I think the way of achieving this is an input to my Vera controller.

        BulldogLowellB Offline
        BulldogLowellB Offline
        BulldogLowell
        Contest Winner
        wrote on last edited by
        #118

        @fusion_man

        maybe we can add a rain sensor this season. It is a good idea to include it.

        fusion_manF 1 Reply Last reply
        0
        • BulldogLowellB BulldogLowell

          @fusion_man

          maybe we can add a rain sensor this season. It is a good idea to include it.

          fusion_manF Offline
          fusion_manF Offline
          fusion_man
          wrote on last edited by
          #119

          @BulldogLowell

          I already did and it is up and running. I used A0 as the input for the rain sensor. I can see the rain sensor in Vera as a motion sensor. I didn't post the code as I didn't want to offend the designer. Being a newbie, I didn't know how to handle this update.

          BulldogLowellB 1 Reply Last reply
          0
          • fusion_manF fusion_man

            @BulldogLowell

            I already did and it is up and running. I used A0 as the input for the rain sensor. I can see the rain sensor in Vera as a motion sensor. I didn't post the code as I didn't want to offend the designer. Being a newbie, I didn't know how to handle this update.

            BulldogLowellB Offline
            BulldogLowellB Offline
            BulldogLowell
            Contest Winner
            wrote on last edited by
            #120

            @fusion_man

            why not just post your code? I'm sure the guy who wrote the original code won't mind, if you include his original notes and credits.

            1 Reply Last reply
            0
            • Mark JeffordM Offline
              Mark JeffordM Offline
              Mark Jefford
              wrote on last edited by
              #121

              Quick question, semi also referenced on the openhab binding.

              Looking to use this with Openhab, I have managed to get it to work with the serial gateway, however i don't see a way i can pass out any configuration of a valve time, i can however trigger valves with a runtime of 0 seconds.

              Any ideas how i can amend this to either use a fixed runtime in the project (happy to run it in 1min increments trigged from openhab hydro sensor results)

              BulldogLowellB 1 Reply Last reply
              0
              • Mark JeffordM Mark Jefford

                Quick question, semi also referenced on the openhab binding.

                Looking to use this with Openhab, I have managed to get it to work with the serial gateway, however i don't see a way i can pass out any configuration of a valve time, i can however trigger valves with a runtime of 0 seconds.

                Any ideas how i can amend this to either use a fixed runtime in the project (happy to run it in 1min increments trigged from openhab hydro sensor results)

                BulldogLowellB Offline
                BulldogLowellB Offline
                BulldogLowell
                Contest Winner
                wrote on last edited by
                #122

                @Mark-Jefford

                In that case, I would just treat each zone as a separate relay/lamp and use Openhab to control the individual ON times... I think.

                johnecyJ Mark JeffordM 2 Replies Last reply
                0
                • BulldogLowellB BulldogLowell

                  @Mark-Jefford

                  In that case, I would just treat each zone as a separate relay/lamp and use Openhab to control the individual ON times... I think.

                  johnecyJ Offline
                  johnecyJ Offline
                  johnecy
                  wrote on last edited by
                  #123

                  can I use pin D6 instead ok pin D8 to control the shift register. I am making the controller on the easy/newbie pc board and there is nothing connected to pin D8 on this board.

                  BulldogLowellB 1 Reply Last reply
                  0
                  • johnecyJ johnecy

                    can I use pin D6 instead ok pin D8 to control the shift register. I am making the controller on the easy/newbie pc board and there is nothing connected to pin D8 on this board.

                    BulldogLowellB Offline
                    BulldogLowellB Offline
                    BulldogLowell
                    Contest Winner
                    wrote on last edited by
                    #124

                    @johnecy

                    const int latchPin = 8;
                    

                    I think you should be OK to try that

                    johnecyJ 1 Reply Last reply
                    0
                    • BulldogLowellB BulldogLowell

                      @johnecy

                      const int latchPin = 8;
                      

                      I think you should be OK to try that

                      johnecyJ Offline
                      johnecyJ Offline
                      johnecy
                      wrote on last edited by
                      #125

                      @BulldogLowell thanks for the reply i will post pictures when i get it finished

                      1 Reply Last reply
                      1
                      • BulldogLowellB BulldogLowell

                        @Mark-Jefford

                        In that case, I would just treat each zone as a separate relay/lamp and use Openhab to control the individual ON times... I think.

                        Mark JeffordM Offline
                        Mark JeffordM Offline
                        Mark Jefford
                        wrote on last edited by Mark Jefford
                        #126

                        @BulldogLowell

                        Gave up with using openhab now using domoticz which is a lot nicer, forced it to hard coded run times by doing this:

                        else if (message.type == V_VAR1)
                        {
                        int variable1 = 5; // atoi(message.data);// RUN_ALL_ZONES time
                        DEBUG_PRINT(F("Recieved variable1 valve:"));
                        DEBUG_PRINT(i);
                        DEBUG_PRINT(F(" = "));
                        DEBUG_PRINTLN(variable1);
                        if (variable1 != allZoneTime[i])
                        {
                        allZoneTime[i] = variable1;

                              zoneTimeUpdate = true;
                            }
                          }
                          else if (message.type == V_VAR2)
                          {
                            int variable2 = 5; //atoi(message.data);// RUN_SINGLE_ZONE time
                            DEBUG_PRINT(F("Recieved variable2 valve:"));
                            DEBUG_PRINT(i);
                            DEBUG_PRINT(F(" = "));
                            DEBUG_PRINTLN(variable2);
                            if (variable2 != valveSoloTime[i])
                            {
                              valveSoloTime[i] = variable2;
                              zoneTimeUpdate = true;
                            }```
                        

                        one thing to note the shift register 0b0000000010000000 does not seem to work, will work out a plan around this as i need to run a 12 pump off the relay bank to draw water from the water butt.

                        BulldogLowellB 1 Reply Last reply
                        0
                        • Mark JeffordM Mark Jefford

                          @BulldogLowell

                          Gave up with using openhab now using domoticz which is a lot nicer, forced it to hard coded run times by doing this:

                          else if (message.type == V_VAR1)
                          {
                          int variable1 = 5; // atoi(message.data);// RUN_ALL_ZONES time
                          DEBUG_PRINT(F("Recieved variable1 valve:"));
                          DEBUG_PRINT(i);
                          DEBUG_PRINT(F(" = "));
                          DEBUG_PRINTLN(variable1);
                          if (variable1 != allZoneTime[i])
                          {
                          allZoneTime[i] = variable1;

                                zoneTimeUpdate = true;
                              }
                            }
                            else if (message.type == V_VAR2)
                            {
                              int variable2 = 5; //atoi(message.data);// RUN_SINGLE_ZONE time
                              DEBUG_PRINT(F("Recieved variable2 valve:"));
                              DEBUG_PRINT(i);
                              DEBUG_PRINT(F(" = "));
                              DEBUG_PRINTLN(variable2);
                              if (variable2 != valveSoloTime[i])
                              {
                                valveSoloTime[i] = variable2;
                                zoneTimeUpdate = true;
                              }```
                          

                          one thing to note the shift register 0b0000000010000000 does not seem to work, will work out a plan around this as i need to run a 12 pump off the relay bank to draw water from the water butt.

                          BulldogLowellB Offline
                          BulldogLowellB Offline
                          BulldogLowell
                          Contest Winner
                          wrote on last edited by
                          #127

                          @Mark-Jefford said:

                          one thing to note the shift register 0b0000000010000000 does not seem to work, will work out a plan around this as i need to run a 12 pump off the relay bank to draw water from the water butt.

                          Can you explain more? is there a bug?

                          Mark JeffordM 1 Reply Last reply
                          0
                          • BulldogLowellB BulldogLowell

                            @Mark-Jefford said:

                            one thing to note the shift register 0b0000000010000000 does not seem to work, will work out a plan around this as i need to run a 12 pump off the relay bank to draw water from the water butt.

                            Can you explain more? is there a bug?

                            Mark JeffordM Offline
                            Mark JeffordM Offline
                            Mark Jefford
                            wrote on last edited by
                            #128

                            @BulldogLowell
                            Hi! :)

                            Rather than using valve 8, i am using only a block of 4, but currently have a 2 channel for testing.

                            My reading into shift registers showed 0b0000000010000000 is 2x 8 bit outputs, B0-B7

                            tried configuing B0 and B7 to try and activate relay 1, was still seeing 5V on all pins apart from the output pin for the zone in use (EG zone 2 expecting Zone1 to alway be on)

                            or am i doing this completely wrong? :)

                            BulldogLowellB 1 Reply Last reply
                            0
                            • Mark JeffordM Mark Jefford

                              @BulldogLowell
                              Hi! :)

                              Rather than using valve 8, i am using only a block of 4, but currently have a 2 channel for testing.

                              My reading into shift registers showed 0b0000000010000000 is 2x 8 bit outputs, B0-B7

                              tried configuing B0 and B7 to try and activate relay 1, was still seeing 5V on all pins apart from the output pin for the zone in use (EG zone 2 expecting Zone1 to alway be on)

                              or am i doing this completely wrong? :)

                              BulldogLowellB Offline
                              BulldogLowellB Offline
                              BulldogLowell
                              Contest Winner
                              wrote on last edited by
                              #129

                              @Mark-Jefford

                              hmmm... are your relays ACTIVE HIGH (actuate wiht a 5V signal) or ACTIVE LOW (actuate when brought to ground) type?

                              Mark JeffordM 1 Reply Last reply
                              0
                              • BulldogLowellB BulldogLowell

                                @Mark-Jefford

                                hmmm... are your relays ACTIVE HIGH (actuate wiht a 5V signal) or ACTIVE LOW (actuate when brought to ground) type?

                                Mark JeffordM Offline
                                Mark JeffordM Offline
                                Mark Jefford
                                wrote on last edited by
                                #130

                                @BulldogLowell

                                Oh, well this is strange, if i disconnect the pin to the relay, it does not activate when unpowered.

                                but from the shift register it is +5 when the zone is not active, and 0V when active, so i assume its an active low not active high by your example... surely removing the 5V feed to the relay pin should make it activate.. not sure whats going on there, some sort of black magic :P

                                My reading of shift registers has made my brain hurt.. do i need to reverse the 0000000010000000 for 1111111101111111?

                                1 Reply Last reply
                                0
                                • rechin304R Offline
                                  rechin304R Offline
                                  rechin304
                                  wrote on last edited by
                                  #131

                                  Dear all,

                                  i have trying to make the irrigation controller to start all zones in same time and run for the specified. I'm using version for domoticz. Can you please help me out with hint of what i can change in the code ?
                                  Another thing is that from domoticsz when i start a zone that zone start and previous is stopped but that status is not updated.

                                  Thank you in advance.

                                  P.S. I will post some pictures of the hardware build soon.

                                  BulldogLowellB 1 Reply Last reply
                                  0
                                  • rechin304R rechin304

                                    Dear all,

                                    i have trying to make the irrigation controller to start all zones in same time and run for the specified. I'm using version for domoticz. Can you please help me out with hint of what i can change in the code ?
                                    Another thing is that from domoticsz when i start a zone that zone start and previous is stopped but that status is not updated.

                                    Thank you in advance.

                                    P.S. I will post some pictures of the hardware build soon.

                                    BulldogLowellB Offline
                                    BulldogLowellB Offline
                                    BulldogLowell
                                    Contest Winner
                                    wrote on last edited by
                                    #132

                                    @rechin304

                                    have you tried changing the eight to one?

                                    #define NUMBER_OF_VALVES 8  // Change this to set your valve count up to 16.
                                    

                                    trigger all your relays with the same output.

                                    1 Reply Last reply
                                    0
                                    • rechin304R Offline
                                      rechin304R Offline
                                      rechin304
                                      wrote on last edited by
                                      #133

                                      Well, that's not the point.
                                      I will have 4 zones that need different type of water needs. For example one zone will be with micro irrigation watering, another one with lawn sprinkler. i do not understand why not to start all zones at once and they will finish according to the time set and not to start one after other. Another thing is why to wait for a zone to finish when you trigger another one.

                                      To start all valve at once when is trigger all zones i did change:

                                      else if (state == RUN_ALL_ZONES)
                                        {
                                          if (lastValve != valveNumber)
                                          {
                                            for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
                                            {
                                              if (i == 0 || i == valveNumber)
                                              {
                                                gw.send(msg1valve.setSensor(i).set(true), false);
                                              }
                                              else
                                              {
                                                gw.send(msg1valve.setSensor(i).set(false), false);
                                              }
                                            }
                                          }
                                          lastValve = valveNumber;
                                          fastToggleLed();
                                          if (state != lastState)
                                          {
                                            valveNumber = 1;
                                            updateRelays(ALL_VALVES_OFF);
                                            DEBUG_PRINTLN(F("State Changed, Running All Zones..."));
                                          }
                                          unsigned long nowMillis = millis();
                                          if (nowMillis - startMillis < VALVE_RESET_TIME)
                                          {
                                            updateRelays(ALL_VALVES_OFF);
                                          }
                                          else if (nowMillis - startMillis < (allZoneTime[valveNumber] * 60000UL))
                                          {
                                            updateRelays(BITSHIFT_VALVE_NUMBER);
                                          }
                                          else
                                      

                                      with

                                      else if (state == RUN_ALL_ZONES)
                                        {
                                          if (lastValve != valveNumber)
                                          {
                                            for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
                                            {
                                              if (i == 0 || i == valveNumber)
                                              {
                                                gw.send(msg1valve.setSensor(i).set(true), false);
                                              }
                                              else
                                              {
                                                gw.send(msg1valve.setSensor(i).set(true), false); //to update domoticz
                                              }
                                            }
                                          }
                                          lastValve = valveNumber;
                                          fastToggleLed();
                                          if (state != lastState)
                                          {
                                            valveNumber = 1;
                                            updateRelays(ALL_VALVES_OFF);
                                            DEBUG_PRINTLN(F("State Changed, Running All Zones..."));
                                          }
                                          unsigned long nowMillis = millis();
                                          if (nowMillis - startMillis < VALVE_RESET_TIME)
                                          {
                                            updateRelays(0); //all outputs will be on
                                          }
                                          else if (nowMillis - startMillis < (allZoneTime[valveNumber] * 60000UL))
                                          {
                                            updateRelays(BITSHIFT_VALVE_NUMBER);
                                          }
                                          else
                                      
                                      BulldogLowellB 1 Reply Last reply
                                      0
                                      • rechin304R rechin304

                                        Well, that's not the point.
                                        I will have 4 zones that need different type of water needs. For example one zone will be with micro irrigation watering, another one with lawn sprinkler. i do not understand why not to start all zones at once and they will finish according to the time set and not to start one after other. Another thing is why to wait for a zone to finish when you trigger another one.

                                        To start all valve at once when is trigger all zones i did change:

                                        else if (state == RUN_ALL_ZONES)
                                          {
                                            if (lastValve != valveNumber)
                                            {
                                              for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
                                              {
                                                if (i == 0 || i == valveNumber)
                                                {
                                                  gw.send(msg1valve.setSensor(i).set(true), false);
                                                }
                                                else
                                                {
                                                  gw.send(msg1valve.setSensor(i).set(false), false);
                                                }
                                              }
                                            }
                                            lastValve = valveNumber;
                                            fastToggleLed();
                                            if (state != lastState)
                                            {
                                              valveNumber = 1;
                                              updateRelays(ALL_VALVES_OFF);
                                              DEBUG_PRINTLN(F("State Changed, Running All Zones..."));
                                            }
                                            unsigned long nowMillis = millis();
                                            if (nowMillis - startMillis < VALVE_RESET_TIME)
                                            {
                                              updateRelays(ALL_VALVES_OFF);
                                            }
                                            else if (nowMillis - startMillis < (allZoneTime[valveNumber] * 60000UL))
                                            {
                                              updateRelays(BITSHIFT_VALVE_NUMBER);
                                            }
                                            else
                                        

                                        with

                                        else if (state == RUN_ALL_ZONES)
                                          {
                                            if (lastValve != valveNumber)
                                            {
                                              for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
                                              {
                                                if (i == 0 || i == valveNumber)
                                                {
                                                  gw.send(msg1valve.setSensor(i).set(true), false);
                                                }
                                                else
                                                {
                                                  gw.send(msg1valve.setSensor(i).set(true), false); //to update domoticz
                                                }
                                              }
                                            }
                                            lastValve = valveNumber;
                                            fastToggleLed();
                                            if (state != lastState)
                                            {
                                              valveNumber = 1;
                                              updateRelays(ALL_VALVES_OFF);
                                              DEBUG_PRINTLN(F("State Changed, Running All Zones..."));
                                            }
                                            unsigned long nowMillis = millis();
                                            if (nowMillis - startMillis < VALVE_RESET_TIME)
                                            {
                                              updateRelays(0); //all outputs will be on
                                            }
                                            else if (nowMillis - startMillis < (allZoneTime[valveNumber] * 60000UL))
                                            {
                                              updateRelays(BITSHIFT_VALVE_NUMBER);
                                            }
                                            else
                                        
                                        BulldogLowellB Offline
                                        BulldogLowellB Offline
                                        BulldogLowell
                                        Contest Winner
                                        wrote on last edited by
                                        #134

                                        @rechin304 said:

                                        Well, that's not the point.
                                        I will have 4 zones that need different type of water needs. For example one zone will be with micro irrigation watering, another one with lawn sprinkler. i do not understand why not to start all zones at once and they wi finish according to the time set and not to start one after other. Another thing is why to wait for a zone to finish when you trigger another one.

                                        I see your point an understand your questions. The purpose of zone cycling is to be able to have enough pressure in each zone independently while also having pressure for household use. Drawing water to every zone (in my case 9) makes the pressure so low, there may not be enough to open the individual pop-up valves, much less fill the washing machine.

                                        The wait period (which you may set) is there to allow the time for hydraulic actuation of solenoid valves. These types of valves close slowly, and since they are in a manifold, the next valve to start opens faster if the water pressure at the manifold is allowed time to reach normal static pressure.

                                        The beauty of open source is that you get to do it your way. If you have the pressure to run all your valves at the same time, with enough to spare to take a shower, then you are fortunate!

                                        So, did you add another 'switch' to your controller to send the all zone command?

                                        1 Reply Last reply
                                        0
                                        • rechin304R Offline
                                          rechin304R Offline
                                          rechin304
                                          wrote on last edited by
                                          #135

                                          @rechin304 said:

                                          {
                                                 updateRelays(0); //all outputs will be on
                                               }
                                          

                                          I did this so all relays on is ok now.
                                          What i miss is to start individual zones more than once at a time :).

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          13

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular