Sprinkler system automation

Automating an existing lawn sprinkler system via wifi using MQTT.

Sprinkler system automation


What I wanted to for with this one was basic network control and monitoring of my existing sprinkler system.

Project goals:
• Network control
• Temperature, humidity or some sort of feedback to monitor watering requirements.
• scheduled watering
• manual control

Stretch goals:
• Weather system rain prediction or lockout
• Active monitoring of soil conditions (separate system)


So, I started with the link node R4 ESP 8266 based 4 channel relay. It seemed to be the best price point for a microcontroller and relays. I have a 4-zone system so it was ideal. An alternative would have been to use a multi-channel relay board or relays and wire them up but I can’t make a one off cheaper than this board. The system is a simple as possible on the MCU end. The scheduling is all handled by the node red software to keep as flexible as possible.

Because we are working with time specific response, I implemented an NTP timer and a queue system. The program will listen for new command requests directed at each relay and queue them up. I setup a max of 20 items in the queue which should be sufficient. Each message is given the current time if not specified or a future time stamp.

The main loop watches for new entries in the queue and checks against the current time to execute them. This way I font have the MCU sitting on wait loops and I can continue to read other data as required. The program cleans up the queue and keeps new entries sorted by time to execute. I didn’t think that anything was time critical enough for interrupts so it’s just on 5 second or so checks to execute commands.

Improvements and final thoughts:

Some flaws I want to sort out are better monitoring on the queue to prevent errors. I think I need an additional MQTT response that can display the queue upon request, or on my local web server.

Overall the system has run very reliably over the last 2 seasons to the point i feel confident letting it run unmonitored. A secondary system to monitor the performance via soil moisture readings would be ideal but i need to do additional research into monitoring that will work on lower power and work reliably over several months.


my code so far along with updates can be found here

Cover pohoto by Anthony Rossbach / Unsplash

Related Article