Esp8266 Wifi Auto Weather Irrigation

by Isaacs86 in Circuits > Arduino

782 Views, 2 Favorites, 0 Comments

Esp8266 Wifi Auto Weather Irrigation

Screen Shot 2022-12-15 at 12.26.07 PM.png
Screen Shot 2022-12-14 at 10.45.32 PM.png
Screen Shot 2022-12-14 at 10.45.45 PM.png
Screen Shot 2022-12-14 at 10.46.02 PM.png
Screen Shot 2022-12-14 at 10.46.14 PM.png

Esp8266 Wifi Auto Weather Irrigation


Features

  • Web server based (ESP8266WebServer)
  • Responsive UI (desktop/mobile/tablet) written around Jquery, Foundation5, and jsoneditor
  • 4 Zones
  • NTP Time (or set from browser)
  • RTC Option pcf8563 or ds1307
  • OLED Display Option
  • ArduinoOTA update (code and spiffs)
  • HTTP Server Update (code and spiffs)
  • Internet weather data
  • Auto stop when rain
  • Pre made Pcb


So i found this code project on Github for Irrigation system with esp8266. the project runs 8 valves using 74HC595 8 bit shift register. connected to SPI pins on the esp8266. this project use Ntp Client to sync esp8266 clock. optional to use PCF8563 or ds1307 for real time clock. and its work in 2 Wifi modes: STA: IP address means connected in Station mode to an access point. - AP: IP address means it is acting as an access point.


i decide to remove the 74HC595 8 bit shift register. component from this project and use only 4 valves to minimize the project. i changed the code to use pins GPIO15 GPIO13 GPIO12 GPIO14. to control the valves solenoids action. and i added a code that collect API local wether date from openweather.org. by using API Token And city ID on the configuration page. and some code that use this weather data to check and auto stop Irrigation when weather data is "Rain". for indication i added a 4 count down timers for each valve to display time that left for each schedule Irrigation valve. and for the final result i design a bit the buttons and the html pages for nice visibility.

Rota

Supplies

Requirements


Hardware and Pcb Components


  • ESP-12x (nodemcu, hazza, D1 Mini) (probably others)
  • ST1306 / SSD1306 OLED
  • 4X 12VDC solenoids
  • 4X 10K resistor
  • 4X 2n2222 transistor
  • 4X 1n4148
  • LM7805
  • 12V DC socket
  • 2X 0.1uf Cap
  • 2X 100uf Cap
  • 40 Header row female
  • 40 Header row male
  • 12vdc 2A transformer


Software


Hardware

Screen Shot 2022-12-15 at 12.26.07 PM.png
Screen Shot 2022-12-15 at 12.46.47 AM.png

Hardware

This project requires pcb assembly and soldering skills. Here is The pre-made board and the schematic.

https://oshwlab.com/rotabox/gardencontrolmcu

wiring and assembled in a water resistant project box.


General Hardware Description

An ESP8266 with 4MB (32Mb) of flash is required. The software makes extensive use of the flash storage for both OTA updates and spiffs. Generally this is an ESP-12x, but other models may be used. In my case I used a ESP8266 lolin v3 board. the usb to serial interface built on board. It also includes a nodemcu type reset and programming circuit.

The 4 valves are controlled through the ESP8266 pins GPIO15 GPIO13 GPIO12 GPIO14.


The ESP8266 pins are connected via resistors (10k or so) to the 4 NPN transistors acting as switches.

The transistors drives 4 12vdc solenoids valves. The solenoids contacts connect 12vdc to the corresponding output, and therefore energize a the solenoids.


The ST1306 OLED is an I2C device and therefore connected to SCL (GPIO5) and SDA (GPIO4) of the ESP8266.

For the optional real time clock (pcf8563 or ds1307),

The following schematic can be used as a guide. A schematic file is also included. It is also just a guide. Again DIY assembly and soldering skills are required to complete this project.

Pcb Schematic and Assembly

Screen Shot 2022-12-15 at 12.28.36 PM.png
Screen Shot 2022-12-15 at 8.37.53 PM.png

Back side of the pcb:

  • solder the 4X 10K resistors
  • solder the 4X 2n2222 transistors
  • solder the lm7805 regulator
  • solder the 4X 1n4148 diodes
  • solder the 12V Dc socket
  • solder the 2X 100uf Caps
  • solder the 2X 0.1uf caps


Front side of the pcb:

  • solder the 2 rows of 16 female headers for the Esp8266
  • solder row of 4 female headers for the I2C screen


Esp8266:

  • solder the 2 rows of 16 male headers on the Esp8266


I2C Screen:

  • solder the row of 4 male headers on the i2c screen



after soldering all components place the esp8266 on the PCB in the right direction by

inserting the male headers to the female headers on the board.

then place the i2c screen by inserting the 4 male headers to the 4 female headers on the board.


connect every solonoid positive tap to the 12VDC pads on the pcb

connect each solonoid negative tap to the SOL1 / SOL2 / SOL3 / SOL4 pads on the pcb.


Remember to power up the ESP8266 only from one source (usb or 12vdc) so if you using usb to power up the ESP8266 do not connect the 12VDC to power and via revers. that may cause damage to the ESP8266.


Tip: you can use usb cable with unconnected 5vdc pin to keep ide live for monitoring and programing when the 12vdc is power the system.


Software

Software


first install all libraries and boards


make sure you installing the right libraries versions.

if you need help to install the libraries check this link how to install libraries in arduino ide

Upload the Ino

Screen Shot 2022-12-15 at 1.53.41 AM.png
Screen Shot 2022-12-15 at 2.01.59 AM.png
Screen Shot 2022-12-15 at 1.56.20 AM.png

here is the .ino code and data files.

Set your esp settings.. the board, programing method, flash size 4M3M.


under arduino menu choose Tools -> Board -> ESP8266 boards -> nodeMCU 1.0 (in my case)

under arduino menu choose Tools -> Flash size -> 4MB(FS:3MB OTA~512KB)

under arduino menu choose Tools -> Port -> dev/cu.XXX


Then compile and upload the .ino

Upload Data Files to Spiffs

Screen Shot 2022-12-15 at 2.07.42 AM.png
Screen Shot 2022-12-15 at 2.08.13 AM.png

after uploading the code go to arduino IDE menu:

under Tools -> Port -> you will see new OTA port with IP address 192.168.4.1 choose this OTA port.

then connect to ESP8266_XXXXXX with a wifi enabled device (no password).


This project uses the SPIFFS file system. So we need to load that data filse in to your esp-12x.

Here is the MkSPIFFS Tool https://github.com/igrr/mkspiffs


if you need help to install the MkSPIFFS tool use this link

https://www.instructables.com/Using-ESP8266-SPIFFS/


Upload the contents of the "data" folder with MkSPIFFS Tool ("ESP8266 Sketch Data Upload" in Tools menu in Arduino IDE) thru OTA.

OpenWeather API

Screen Shot 2022-12-15 at 2.08.14 PM.png
Screen Shot 2022-12-15 at 7.58.09 PM.png

Create your account on https://openweathermap.org/

then log in to openweather.org and under your account and go to "My API Keys"

and create your API Token.


in OpenWeathe.org search bar search for your city and get into the city page.

for example search Tel Aviv and copy the city ID number from the page address

for this example the address is: https://openweathermap.org/city/293396


API token = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

City ID = 293396


keep your "API Token" number And the "City ID" number and use them in next step in Configuration Page to start collect weather data in your city and use "auto stop when rain" button.


Setup

FOOK2GOLBNO0HQB.png

Setup

When initially powered on, the internet access point will not be setup. ESP8266_XXXXXX will therefore switch to AP mode. It will be come an access point in itself.


connect to ESP8266_XXXXXX with a wifi enabled device (no password).

Browse to 192.168.4.1 The initial page will let you toggle the Valves on/off to test.


Now go to the Configuration page and click "Set Time from Browser". Both the time and the correct time zone are now set up.

Set a host name. This will help allow you to access the device from your browser (if you can use mDNS).

Set your access point name and password. You have 2 choices here.

  • If you want to connect the device to your network, fill in your access point SSID and password.
  • If you want to leave it as a stand alone access point all by itself, fill in the second set of SSID and Password, to secure the access point.


Set your API Token And City ID.

Click Save Configuration, then click Restart.


What is it's IP? If your computer supports mDNS (Anything but windows, but even on windows it'll be there if you have loaded iTunes), you can access it with the following url: http://<host>.local/, where <host> is the host you specified in your configuration. If you don't have mDNS available, you must find the IP address of the MyGardenMCU through one of the following methods (or make up your own method)

  • Look at the OLED display (if you're using one)
  • Log into your router and look at the dhcp leases (sometimes called dhcp client list) find the entry that shows ESP_xxxxxx
  • Connect a serial ttl dongle to the MyGardenMCU, set the baud rate to 74880. During startup, you'll see the IP address shown.
  • Get mDNS on your computer: here's some info for windows: http://stackoverflow.com/questions/23624525/standard-mdns-service-on-windows
  • ping from a computer that does handle mDNS -- ping <hostname>.local


General Usage

General usage

The Main web page of MyGardenMcu allows you to test each of the 4 Valves. Of course it also allows navigation to the other pages. The web pages use a combination of jQuery, and Foundation5 to create a simple UX that is also responsive to Desktop, Mobile and Tablet formats. In addition JsonEditor is used to simplify entering/editing the settings and schedules. The frameworks are all loaded onto the spiffs of the device, so it will work even when no internet is connected.


The OLED Screen

The OLED screen gives the current status of the device, as well as its IP address.

The top line will show the WiFi Status. - STA: IP address means connected in Station mode to an access point. - AP: IP address means it is acting as an access point. The second line

will show the access point name
  • DIS: means it is disconnected.

The bottom line shows that status of each zone (solonoid).


Schedules

The schedules page allows adding, specifying and arranging schedules of when to turn on and off each zone (relay). Start time, duration, days of week, are each set for each schedule.


The Image Page

The image page gives you a graphical representation of each sprinkler zone. This is handy when testing your sprinklers and setting them up.There is a default image supplied, and by default 4 buttons, representing each zone appear along the top of the image. The image could be a sketch or a satellite image of the are the sprinklers are installed.

The "Move Buttons" button can be activated, and the buttons may be moved around the image (mouse or touch) to indicate which zone is where on the image. "Save Buttons" then saves the button locations.

The name of the image file is simply "image.jpg" and it can be placed into the data folder before loading the spiffs into the device. It can also be uploaded using the built in spiffs editor .


Configuration Page

The configuration page allows you to set the MyGardenMcu as needed.

The save and load configuration buttons are self explanatory. Restart is a reset of the ESP8266. The "Stop All" button clears all configuration (and schedules and button settings).


Software Update

On the Configuration Page, there is a "Software Upload" button. This allows new firmware or a new spiffs binary to be loaded directly from your browser. Simply choose the binary image to upload, and then click "Upload!". This process can take some time. You can check progress on the OLED screen.


SPIFFS edit

On the Configuration Page, there is a "SPIFFS Editor" button. This allows you to upload, delete and change the files that the web server uses.