Skip to main content

Sprinkler Control 6: Multiple Zones

Loading...

In the final version of the Sprinkler Control project, we go multi-zone. The application only controls two relays (to save the slot space inside your TPS), but you can easily extend it to individually control many more watering zones.

The first step in adding the multi-zone support was to add the sprinkler_num field to the sprinkler_schedule table. Notice how the field's Minimum and Maximum properties come in handy here: the minimum sprinkler number is 1, and the maximum is 2:

sprinkler_table_config_2

The second step was adding the For-Next Loop block to the diagram. This is the first project where we do "loops." Click on the For-Next Loop block to open its properties. As you can see, the block iterates from 0 to 1 (inclusive). The block runs twice, first, with the value of 0, and second, with the value of 1.

sprinkler_for

When a block chain is connected to the Iterate output of the For-Next Loop block, this entire chain runs once for each for-next loop. This means the application will perform the Table Lookup and everything behind it twice.

sprinkler_table_lookup

Record Offsets

Now it is time to look inside the Table Lookup block. The element interesting to us right now is the Record Offset property. The current_iteration parameter of the For-Next Block is there. The Table Lookup will first run with the Record Offset of zero and then with the Record Offset of one.

When at zero, the Record Offset instructs the Table Lookup block to search from the beginning of the table and find the first data table record matching the search criteria. Setting the Record Offset to one will make the Table Lookup block search for the second record matching the search criteria.

If you fix the record offset at zero, this application won't work correctly when both sprinkler relays are to be activated simultaneously. The following example illustrates why. Let's say that you have this watering schedule:

sprinkler_numwatering_timeduration
108:00 AM300
208:30 AM300
106:00 PM600
206:00 PM600

At 08:00 AM, the first record will be fetched. At 08:30 AM, the second record will be fetched. Now, what will happen at 06:00 PM? At the first for-next loop iteration, the third record will be fetched. When the loop runs for the second time, the same third record will be fetched again -- that is, if the Record Offset parameter is always at 0. If this parameter is set to match current_iteration, then the first matching record (the third record) will be ignored, and the second matching record (the fourth record) will be found!

This, and many other projects, takes advantage of the LUIS interface. The application makes two settings -- Ethernet DHCP and Ethernet IP -- accessible from the LUIS smartphone app.

Monitoring the Sprinkler Relay State

On the AppBlocks Demo Kit (ADK), the first "sprinkler" relay is connected to the green LED marked "RL1." The second "sprinkler" relay is connected to the red LED "RL2." Either LED is on when the corresponding relay is on.