Weather Aware Sprinkler Controller

Made by Martin Smaha

About the project

6 station Photon controller uses the Weather Underground API to prevent watering when windy, rainy, or too cold.

Project info


Estimated time:

4 hours


30th July 2018

Items used in this project

Hardware components

JBtek 8 Channel DC 5V Relay Module x 1
Particle Photon x 1



This project uses the Particle Photon and a relay module to create a 6 station sprinkler controller. It has these features not found in similar projects:

  • Uses Weather Underground API to prevent watering when windy, rainy, or too cold. Signup for a free developer account here.
  • Has a built in web interface that you can access from any browser device on your local WiFi network.
  • Manual control page lets you trigger any zone from your phone's browser to facilitate sprinkler adjustment and testing.


Construction can be done by using a proto board and push-pin wiring or if you don't mind soldering, place female headers pin-to-pin and mount the Photon directly to the module board as in this enhanced photo.

Solder two headers together plus a jumper.

You will also need to supply the relay module with 5V from the Photon's GND and VIN pins (upper right corner of photo). The Photon and relay coils are powered from the 5vVUSB power adapter connected to the Photon's USB port. The relay board has 2 VCC pins but the one shown above (inputs) is powered from 3.3v and the other (coils) is 5v. DO NOT CONNECT VCC's TOGETHER. The sprinklers will be powered from a 24vAC transformer wired to the relay contacts. Some people recommend RC snubbers placed across the relay contacts, but the preferred connection is actually across the valve coils. Either position can be accomplished from the relay module screw connections.

As installed with .15uf 100v snubber caps, 24v 750ma fuse, and sprinkler wiring.

Weather Underground

Before you can install the software presented here, you must edit it to use your API key as well as the city or weather station ID for your area. To get the API key, signup for a free developer account here. Then select the default Free option for an API key here. Select Purchase Key (for $0 USD) then answer all of the questions. If you do not have a project website, put NONE in the response field.

Once you have your key, use your browser and their example to get a response

You will need to use their site and modify this example until you get the desired response for your location. Use that information when modifying the WeatherClient file line 103 described below.


Because of its size, the project software has been broken down into 4 files. Be sure to transfer all of the files in the Code section below to your project folder.


This is the main file and it performs the initialization and timing control functions. It also contains the logic that interfaces the weather data with timer cycle starting.

The time zone and GMT offset reported from the weather station is used to correct the projects clock to local time. The time is also synced from Particle once a day.

An h file is also included to provide the needed variable externs that connect all modules together.


This file contains the Weather Underground API interface. It accesses the API every 10 minutes to get the latest weather data. The weather data is returned in JSON format but because it is simple and very specific, a simple parser is coded to recover just the fields we need.

Edit lines near 103 to use your API key and city or station information discovered above. Only select one query line to use and comment out the other.

//by city example 
WeatherClient.println("GET /api/Your_Key/conditions/q/CA/Loma_Linda.json HTTP/1.0");
//by station example
WeatherClient.println("GET /api/Your_Key/conditions/q/pws:KCALOMAL4.json HTTP/1.0");

This project is setup for temperature in degrees F but if you want degrees C instead, change temp_f to temp_c on line 36 and the correct version will be recovered from the weather data.

If you are having problems getting weather information to appear, verify your example from above. To see exactly what this project is seeing, click on the Current Weather link on the status web page and it will display the last response received from wunderground as shown in this screenshot.

Partial listing of the Weather Underground API response


This file contains the user interface to the project. This project specific server, formats and returns the desired page. It also parses the schedule form and stores the information in the Photon's EEPROM section so power failures do not necessitate schedule re-entry.

Accessing the web server

Once the Photon is powered up and operational with the project code loaded, obtain its LAN IP address from either the initial setup process or from your wireless router's connected devices page. Then, use any LAN connected computer or smart device (phone or tablet) and enter the LAN IP address (e.g. into the browser site box as in this example: The 8080 port the server is on is defined in the project source code. You must enter the IP address: port / status.html exactly as in the example or your browser will not connect to the Photon. Use your router's reserve IP function to make this address permanent.

The interface consists of screens as shown below.

Status page - Click on Current Weather link for API response

Manual page - click on zones to control ON-OFF.

Schedule page - make changes then click Submit


There are a lot of sprinkler controller projects and platforms out there. By using the low cost Photon, and this project code, I was able to DIY a $50 system that has more features than the $200 versions available at my local hardware store. So even if you do not replicate the entire project, the web server and weather client code presented here may help make your next project easier.


Sprinkler Control

Basic Wiring Schematic




User Interface


Main control code


Common info for all files


Weather Underground API interface


Martin Smaha

Designing hardware and software since 1975.

Leave your feedback...