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 OpenWeatherMap API to prevent watering when windy, rainy, or too cold. Signup for a free 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.
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.
Before you can install the software presented here, you must edit it to use your API key as well as the city ID for your area. To get the API key, signup for a free account here. Lookup your city ID; it goes after the id= in the example below. Your API key goes in place of your_key_here.
Only request every 15 minutes or your account will be locked out for 24 hours. This project follows that rule and only updates weather information every 15 minutes.
units=metric is the metric format option.
Edit line 127 in WeatherClient to have the correct id and API
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 assuming you are using the Particle Desktop development system. If you are using the web based development system, you will need to combine all 4 files into one large file.
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 is also synced from Particle once a day but you will have to enter the correct timezone on line 62 in SprinklerControl.
An h file is also included to provide the needed variable externs that connect all modules together.
This file contains the OpenWeatherMap API interface. It accesses the API every 15 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.
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 the api.
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.
Once the Photon is powered up and operational with the project code loaded, obtain its LAN IP address from either the initial Particle.io 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. 192.168.1.128) into the browser site box as in this example: 192.168.1.128:8080/status.html. 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.
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.
This project originally used WeatherUnderground API as its weather information source. They no longer offer free API access so the project was converted to use the OpenWeatherMap API instead which does offer free access.