This project uses an Off-The-Shelf ESP32 8-Relay board or a seperate ESP32 Dev board and 8-Relay module to create the 8 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.
- WiFi based OTA code updates after an initial serial loading from the IDE.
There are lots of 8-Relay boards available on the market today. Choose one that uses the ESP32-WROOM version and uses direct cpu to relay drive. ESP8266 boards and some ESP32 boards that use a smaller cpu, requires a port expansion chip via I2C or SPI. This project is coded for direct pin drive. You will need to determine which 8 GPIO pins are in use and which controls what relay. You will edit the ESP32_Sprinkler.ino file lines 8-15 with that mapping. Use the number that follows the letters GPIO (e.g. GPIO23 is number 23) and not the physical chip or module pin position number.
This board accepts 7-30vDC for power so I added a 24vac to 12vdc converter module so eveything runs off of a single standard 24vac transformer. NOTE: Do not power the board directly from the ac transformer.
OpenWeatherMap APIBefore 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.
http://api.openweathermap.org/data/2.5/weather?id=5338783&units=imperial&APPID=your_key_here
Requests are made every 15 minutes.
units=metric is the metric format option.
Edit line 124 in WeatherClient to have the correct id and API
SoftwareBecause of its size, the project software has been broken down into 4 files. Be sure to transfer all of the files to the sketch folder created via the Arduino IDE.
ESP32_Sprinkler.ino
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 internet NTP servers or a local NTP server. Change this on line 43. Time STD/DST change over is handled automatically per current USA rules.
Define your local WiFi ssid and password on lines 39 and 40.
SprinklerControl.h
This h file is also included to provide the needed variable externs that connect all modules together.
WeatherClient.cpp
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 the raw data this project is receiving, click on the Current Weather link on the status web page and it will display the last response received from the api. There is a 5 minute delay from startup before the first weather data arrives, then every 15 minutes.
WebServer.cpp
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 ESP32 EEPROM section so power failures do not necessitate schedule re-entry. On some boards, this section is actually emulated in flash by the Arduino library.
Loading the softwareBoard Setup
The Arduino IDE requires that the first load be done via serial port. On some boards, this is accomplished by connecting a USB cable between the board and the PC. On other boards, a seperate 3 volt serial adaptor is needed. The board I used has a 6 pin header for this purpose.
Left to right the pins are: D0, GND, GND, RX, TX, 5V
Map the TX->RX, RX->TX, and GND->GND of the adaptor to board.
NOTE: The ESP32 pins are 3.3v level, 5v will damage the chip.
Connect the adaptor to the board and plug into the PC. In the IDE, select the new COM port as access for this board. Verify the sketch compiles.
First Program Load
1. Power up the board.
2, Press and hold both the EN and D0 buttons.
3. Release the EN button only.
4. Release the D0 button.
5. Click Upload on the IDE.
6. When completed, start the board program running by pressing and releasing the EN button.
7. From this point on, use the WiFi firmware upload feature of the IDE, no serial connection or button presses required.
Note: The code uses the serial monitor feature for some debugging. If connected via USB, this feature is available in the IDE. If updating via WiFi, you will need to use a PC serial program like Putty or Realterm plus the USB adaptor used previously to monitor it.
Accessing the web serverOnce the ESP32 is powered up and operational with the project code loaded, obtain its LAN IP address 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: http://192.168.1.128:8080/status.html. The 8080 port the server is on is defined in the project source code; you can change it if desired. You must enter the IP address: port / status.html exactly as in the example or your browser will not connect. Use your router's reserve IP function to make this address permanent.
The web interface consists of screens as shown below.
In 2017, I created a hackster.io 6 zone Photon based controller which you can still access here. This project is an upgraded ESP32 version of that original.












_3u05Tpwasz.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)


Comments