{"id":80957,"date":"2024-04-28T23:50:31","date_gmt":"2024-04-29T03:50:31","guid":{"rendered":"https:\/\/www.engineersgarage.com\/?p=80957"},"modified":"2024-04-22T22:07:03","modified_gmt":"2024-04-23T02:07:03","slug":"app-controlled-iot-watering-system-for-home-garden-farm","status":"publish","type":"post","link":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/","title":{"rendered":"How to design an app-controlled irrigation system"},"content":{"rendered":"<p><span data-preserver-spaces=\"true\">In this project, we<\/span><span data-preserver-spaces=\"true\">\u2019ll design a mobile app-controlled watering system that drip irrigates a home garden or small farm. This system is developed on an ESP8266 microcontroller, which controls the water pump through a 3V relay or an electronic valve.<\/span><span data-preserver-spaces=\"true\">\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">The user can switch the water\u2019s motor\/electronic valve ON or OFF and even set a watering schedule via the app.\u00a0<\/span><span data-preserver-spaces=\"true\">This<\/span><span data-preserver-spaces=\"true\">\u00a0means users can set a time for watering or switch the water on or off wherever they are, so long as they have the app installed.<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Components required<\/span><\/strong><\/p>\n<p><span data-preserver-spaces=\"true\"><strong>1. <\/strong>ESP8266 x1<br \/>\n<\/span><span data-preserver-spaces=\"true\"><strong>2.<\/strong> 3V relay x1<br \/>\n<\/span><span data-preserver-spaces=\"true\"><strong>3.<\/strong> Electrical wires for connecting the motor, relay, and main supply<br \/>\n<\/span><strong>4<\/strong><span data-preserver-spaces=\"true\"><strong>.<\/strong> Connecting<\/span><span data-preserver-spaces=\"true\">\/DuPont wires for connecting the ESP8266 to the relay<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Circuit connections<br \/>\n<\/span><\/strong><span data-preserver-spaces=\"true\">The device built in this<\/span><span data-preserver-spaces=\"true\">\u00a0project controls the operation of a water pump or an electronic valve through a 3V relay. The water pump or valve is attached to a relay, which is connected to the ESP8266 microcontroller.<\/span><span data-preserver-spaces=\"true\">\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">To connect the relay with the microcontroller:\u00a0<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">Connect the relay\u2019s input terminal with ESP8266\u2019s GPIO 16 <\/span><\/li>\n<li>Connect the relay\u2019s VCC and GND terminals with ESP8266\u2019s 3V3 and ground pins<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-01-3V-Relay-for-App-Controlled-Watering.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80959\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-01-3V-Relay-for-App-Controlled-Watering.png\" alt=\"\" width=\"424\" height=\"420\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-01-3V-Relay-for-App-Controlled-Watering.png 424w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-01-3V-Relay-for-App-Controlled-Watering-300x297.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-01-3V-Relay-for-App-Controlled-Watering-150x150.png 150w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-01-3V-Relay-for-App-Controlled-Watering-240x238.png 240w\" sizes=\"auto, (max-width: 424px) 100vw, 424px\" \/><\/a>To connect the relay with the water pump or electronic valve:<\/p>\n<ul>\n<li>Connect two wires to a two-pin top<\/li>\n<li>Connect one of the top\u2019s terminals with the relay terminal that\u2019s normally open<\/li>\n<li>Connect one of the pump\/valve\u2019s terminals with the relay\u2019s common contact.<\/li>\n<li>Connect the other pump\/valve\u2019s terminal with the other top\u2019s terminal<\/li>\n<\/ul>\n<p>The complete circuit is shown in the below diagram.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-02-App-Controlled-Watering-System-Circuit-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80960\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-02-App-Controlled-Watering-System-Circuit-Diagram.png\" alt=\"\" width=\"531\" height=\"480\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-02-App-Controlled-Watering-System-Circuit-Diagram.png 531w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-02-App-Controlled-Watering-System-Circuit-Diagram-300x271.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-02-App-Controlled-Watering-System-Circuit-Diagram-263x238.png 263w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><\/p>\n<p><strong><span data-preserver-spaces=\"true\">Building the app<br \/>\n<\/span><\/strong><span data-preserver-spaces=\"true\">The mobile app is the heart of this project and is built in the MIT App Inventor. It lets users switch ON\/OFF the motor\/valve or schedule its operation.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">The app has a single screen with buttons to turn the motor\/valve\u2019s water ON\/OFF and set its watering schedule. There are two options for picking the time: one to set the start and another to set the end time of the water motor\/valve\u2019s operation. The time \u201cpickers\u201d and their labels are organized in horizontal arrangements.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">A client UDP extension is also part of the screen, which can be downloaded from\u00a0<\/span><span data-preserver-spaces=\"true\">the\u00a0<\/span><a class=\"editor-rtfLink\" href=\"https:\/\/github.com\/AURSUN\/Extensions\/blob\/master\/co.com.dendritas.ClientUDP.aix\" target=\"_blank\" rel=\"noopener\"><span data-preserver-spaces=\"true\">this<\/span><span data-preserver-spaces=\"true\">\u00a0link<\/span><\/a><span data-preserver-spaces=\"true\">.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">After downloading the extension file, import it into the MIT App Inventor by navigating to Extension-&gt; Import extension.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-03-Importing-ClientUDP-extension-in-MIT-App.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80961\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-03-Importing-ClientUDP-extension-in-MIT-App.png\" alt=\"\" width=\"233\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-03-Importing-ClientUDP-extension-in-MIT-App.png 233w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-03-Importing-ClientUDP-extension-in-MIT-App-109x300.png 109w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-03-Importing-ClientUDP-extension-in-MIT-App-87x238.png 87w\" sizes=\"auto, (max-width: 233px) 100vw, 233px\" \/><\/a><\/p>\n<p>The main (and only) screen of the app has the below design.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-04-Watering-Mobile-App-Main-Screen.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80962\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-04-Watering-Mobile-App-Main-Screen.png\" alt=\"\" width=\"598\" height=\"480\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-04-Watering-Mobile-App-Main-Screen.png 598w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-04-Watering-Mobile-App-Main-Screen-300x241.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-04-Watering-Mobile-App-Main-Screen-297x238.png 297w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/a><\/p>\n<p>&#8216;Screen1&#8217; has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80963\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI.png\" alt=\"\" width=\"350\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI.png 350w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-164x300.png 164w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-130x238.png 130w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/a><\/p>\n<p>&#8216;Button1&#8217; is used to switch ON\/OFF the water pump\/valve. It has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80964\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-1.png\" alt=\"\" width=\"350\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-1.png 350w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-1-164x300.png 164w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-05-Watering-App-UI-1-130x238.png 130w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/a><\/p>\n<p>&#8216;Label1&#8217; for the &#8216;TimePicker1&#8217; has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-07-Watering-App-UI-Components.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80966\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-07-Watering-App-UI-Components.png\" alt=\"\" width=\"365\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-07-Watering-App-UI-Components.png 365w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-07-Watering-App-UI-Components-171x300.png 171w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-07-Watering-App-UI-Components-136x238.png 136w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><\/a><\/p>\n<p>The &#8216;TimePicker1&#8217; sets the start time of the motor\/valve. It has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-08-Watering-App-UI-Components.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80967\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-08-Watering-App-UI-Components.png\" alt=\"\" width=\"309\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-08-Watering-App-UI-Components.png 309w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-08-Watering-App-UI-Components-145x300.png 145w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-08-Watering-App-UI-Components-115x238.png 115w\" sizes=\"auto, (max-width: 309px) 100vw, 309px\" \/><\/a><\/p>\n<p>&#8216;Label2&#8217; for the &#8216;TimePicker2&#8217; has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-09-Watering-App-UI-Components.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80968\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-09-Watering-App-UI-Components.png\" alt=\"\" width=\"364\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-09-Watering-App-UI-Components.png 364w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-09-Watering-App-UI-Components-171x300.png 171w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-09-Watering-App-UI-Components-135x238.png 135w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/><\/a><\/p>\n<p>The &#8216;TimePicker2&#8217; sets the stop time of the motor\/valve. It has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-10-Watering-App-UI-Components.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80969\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-10-Watering-App-UI-Components.png\" alt=\"\" width=\"312\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-10-Watering-App-UI-Components.png 312w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-10-Watering-App-UI-Components-146x300.png 146w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-10-Watering-App-UI-Components-116x238.png 116w\" sizes=\"auto, (max-width: 312px) 100vw, 312px\" \/><\/a><\/p>\n<p>&#8216;Button2&#8217; schedules the operation of the motor\/valve. It has the following properties.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-11-Watering-App-UI-Components-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80970\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-11-Watering-App-UI-Components-1.png\" alt=\"\" width=\"310\" height=\"640\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-11-Watering-App-UI-Components-1.png 310w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-11-Watering-App-UI-Components-1-145x300.png 145w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-11-Watering-App-UI-Components-1-115x238.png 115w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/a><\/p>\n<p>The app has the following logic designed into the block editor.<\/p>\n<p><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-12-Watering-App-Logic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80971\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-12-Watering-App-Logic.png\" alt=\"\" width=\"480\" height=\"527\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-12-Watering-App-Logic.png 480w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-12-Watering-App-Logic-273x300.png 273w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-12-Watering-App-Logic-217x238.png 217w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p><strong>Arduino sketch<\/strong><br \/>\nAfter making the circuit connections, upload the following sketch to ESP8266. Remember to replace the SSID, Wi-Fi, password, and Weather API key in the app with your own.<\/p>\n<style>\n.gist-data{    height:250px; \/\/ Any height    overflow: auto;<br \/>}<\/style>\n<p><script src=\"https:\/\/gist.github.com\/Ajak58a\/901243ff37fe5097b378132fc7ae460f.js\"><\/script><\/p>\n<p><span data-preserver-spaces=\"true\"><strong>How it works<\/strong><br \/>\nUsers can instantly turn the water pump\/valve ON\/OFF or schedule its operation directly from their mobile app. A single button on the app\u2019s screen turns the motor\/valve ON\/OFF. When a user taps that button to turn the motor\/valve ON, the message \u201cT1\u201d is transmitted to ESP8266 from the app via the Internet over a UDP protocol. ESP8266 receives this message through the Wi-Fi network on the same protocol.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">When a user taps the<\/span><span data-preserver-spaces=\"true\">\u00a0button to turn the motor\/valve OFF, the app transmits the message \u201cT0\u201d to ESP8266 via the Internet over a UDP protocol.<\/span><span data-preserver-spaces=\"true\">\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">A user can also set a schedule for the motor\/valve to operate by setting its start and stop time.\u00a0<\/span><span data-preserver-spaces=\"true\">Simply<\/span><span data-preserver-spaces=\"true\">\u00a0click on the app\u2019s \u2018TimePickers\u2019 and\u00a0<\/span><span data-preserver-spaces=\"true\">then tap on<\/span><span data-preserver-spaces=\"true\">\u00a0the \u2018Schedule\u2019 button.<\/span><span data-preserver-spaces=\"true\">\u00a0When the schedule button is selected, a message in the format H&lt;starttime_hours&gt;M&lt;starttime_minutes&gt;X&lt;stoptime_hours&gt;Y&lt;stoptime_minutes&gt; is transmitted to ESP8266 over the UDP protocol. ESP8266 receives this message through the Wi-Fi network.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">The UDP packet received from the mobile app is analyzed on ESP8266. If the message received is \u201cT1,\u201d the motor\/valve is turned ON by activating the relay. The relay is activated by sending a LOW signal to its input terminal. If the message received is \u201cT0,\u201d the motor\/valve is turned OFF by deactivating the relay.\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">If ESP8266 receives a message to schedule the motor\/valve\u2019s operation, the start and stop times are set based on the current local time &#8212; retrieved from the Weather API. ESP8266 also operates according to the last message received via the UDP protocol.\u00a0<\/span><\/p>\n<p><strong><span data-preserver-spaces=\"true\">The code<br \/>\n<\/span><\/strong><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\" data-preserver-spaces=\"true\">The sketch begins by importing the ESP8266WiFi.<\/span><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\" data-preserver-spaces=\"true\">h, ESP8266HTTPClient.h, and WiFiClient.h libraries<\/span><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\" data-preserver-spaces=\"true\">, which<\/span><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\" data-preserver-spaces=\"true\">\u00a0are required to handle ESP8266\u2019s Wi-Fi connection.<\/span><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\" data-preserver-spaces=\"true\">\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">WiFiUdp.h is imported to handle the UDP protocol over Wi-Fi on ESP8266. An object of the WiFiUDP class is instantiated, and the variables are declared for the UDP port and packet. The variables are declared to store the Wi-Fi SSID, Wi-Fi password, and Weather API key. Variables are also declared for the pin connection with the relay and to store the current local time, the start and stop times of the motor\/valve, and the start and stop time\u2019s hour and minute values, which are determined by the UDP packet.\u00a0<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">The user-defined connectWiFi() function connects ESP8266 with the Wi-Fi network.\u00a0<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">The convertToMinutes() function converts the local time received from the Weather API into minutes passed (since\u00a0<\/span><span data-preserver-spaces=\"true\">12 AM<\/span><span data-preserver-spaces=\"true\">).\u00a0<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">The stringToCharArray() function is defined\u00a0<\/span><span data-preserver-spaces=\"true\">to<\/span><span data-preserver-spaces=\"true\">\u00a0<\/span><span data-preserver-spaces=\"true\">convert<\/span><span data-preserver-spaces=\"true\">\u00a0the string received from the Weather API into a character array.<\/span><span data-preserver-spaces=\"true\">\u00a0<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">The getCurrentTime() function retrieves the current local time from the Weather API.\u00a0<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">The\u00a0<\/span><span data-preserver-spaces=\"true\">processMsg<\/span><span data-preserver-spaces=\"true\">() function deconstructs the motor\/vale\u2019s start and\u00a0<\/span><span data-preserver-spaces=\"true\">stop<\/span><span data-preserver-spaces=\"true\">\u00a0times from the UDP message (received from the mobile app).<\/span><span data-preserver-spaces=\"true\">\u00a0<\/span><\/li>\n<\/ul>\n<p>In the setup() function, the baud rate for the serial port is set to 115200 for debug messages. The pin connecting to the relay is set as the digital output. ESP8266 is connected to the Wi-Fi network by calling the connectWiFi() function. The UDP port is initialized on ESP8266 and configured to \u201clisten\u2019 for messages received through the Internet.<\/p>\n<p>The current time is retrieved from the Weather API using the loop() function and stored in a global variable. The UDP packet is detected, and the first character of the packet is checked to verify if the message is to turn ON\/OFF the motor\/valve or schedule its operation.<\/p>\n<p>If the message is to turn the motor\/valve ON\/OFF, the second character of the message is decoded to determine the switching operation. If the message is received to schedule the motor\/valve\u2019s operation, the start and stop times are validated and deconstructed from the message, and continuously compared with the current local time.<\/p>\n<p><strong>The results<\/strong><\/p>\n<div style=\"width: 740px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-80957-1\" width=\"740\" height=\"416\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-DV.mp4?_=1\" \/><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-DV.mp4\">https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/P59-DV.mp4<\/a><\/video><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this project, we\u2019ll design a mobile app-controlled watering system that drip irrigates a home garden or small farm. This system is developed on an ESP8266 microcontroller, which controls the water pump through a 3V relay or an electronic valve.\u00a0 The user can switch the water\u2019s motor\/electronic valve ON or OFF and even set a&hellip;<\/p>\n","protected":false},"author":387,"featured_media":80973,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[13,1707,1871],"tags":[2641,4339,2012,4440,2479,1408,4439,4326,660],"class_list":{"2":"type-post","19":"entry","20":"has-post-thumbnail"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.2 (Yoast SEO v25.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to design an app-controlled irrigation system<\/title>\n<meta name=\"description\" content=\"Design an app-controlled IoT irrigation system for a home garden and or small agricultural farm.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to design an app-controlled irrigation system\" \/>\n<meta property=\"og:description\" content=\"Design an app-controlled IoT irrigation system for a home garden and or small agricultural farm.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\" \/>\n<meta property=\"og:site_name\" content=\"Engineers Garage\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/engineersgarage\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"504\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nikhil Agnihotri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:site\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Agnihotri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\"},\"author\":{\"name\":\"Nikhil Agnihotri\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6\"},\"headline\":\"How to design an app-controlled irrigation system\",\"datePublished\":\"2024-04-29T03:50:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\"},\"wordCount\":1191,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png\",\"keywords\":[\"app\",\"electronicproject\",\"esp8266\",\"farm\",\"internetofthings\",\"IoT\",\"irrigation\",\"mitappinventor\",\"video\"],\"articleSection\":[\"Electronic Projects\",\"ESP8266\",\"Video\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\",\"url\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\",\"name\":\"How to design an app-controlled irrigation system\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png\",\"datePublished\":\"2024-04-29T03:50:31+00:00\",\"description\":\"Design an app-controlled IoT irrigation system for a home garden and or small agricultural farm.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png\",\"width\":800,\"height\":504},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.engineersgarage.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to design an app-controlled irrigation system\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.engineersgarage.com\/#website\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"name\":\"Engineers Garage\",\"description\":\"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News\",\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.engineersgarage.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\",\"name\":\"Engineer's Garage - WTWH Media\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"width\":372,\"height\":52,\"caption\":\"Engineer's Garage - WTWH Media\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/engineersgarage\",\"https:\/\/x.com\/EngineersGarage\",\"https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6\",\"name\":\"Nikhil Agnihotri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g\",\"caption\":\"Nikhil Agnihotri\"},\"url\":\"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to design an app-controlled irrigation system","description":"Design an app-controlled IoT irrigation system for a home garden and or small agricultural farm.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/","og_locale":"en_US","og_type":"article","og_title":"How to design an app-controlled irrigation system","og_description":"Design an app-controlled IoT irrigation system for a home garden and or small agricultural farm.","og_url":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/","og_site_name":"Engineers Garage","article_publisher":"https:\/\/www.facebook.com\/engineersgarage","og_image":[{"width":800,"height":504,"url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png","type":"image\/png"}],"author":"Nikhil Agnihotri","twitter_card":"summary_large_image","twitter_creator":"@EngineersGarage","twitter_site":"@EngineersGarage","twitter_misc":{"Written by":"Nikhil Agnihotri","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#article","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/"},"author":{"name":"Nikhil Agnihotri","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6"},"headline":"How to design an app-controlled irrigation system","datePublished":"2024-04-29T03:50:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/"},"wordCount":1191,"commentCount":0,"publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"image":{"@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png","keywords":["app","electronicproject","esp8266","farm","internetofthings","IoT","irrigation","mitappinventor","video"],"articleSection":["Electronic Projects","ESP8266","Video"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/","url":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/","name":"How to design an app-controlled irrigation system","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage"},"image":{"@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png","datePublished":"2024-04-29T03:50:31+00:00","description":"Design an app-controlled IoT irrigation system for a home garden and or small agricultural farm.","breadcrumb":{"@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#primaryimage","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator.png","width":800,"height":504},{"@type":"BreadcrumbList","@id":"https:\/\/www.engineersgarage.com\/app-controlled-iot-watering-system-for-home-garden-farm\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.engineersgarage.com\/"},{"@type":"ListItem","position":2,"name":"How to design an app-controlled irrigation system"}]},{"@type":"WebSite","@id":"https:\/\/www.engineersgarage.com\/#website","url":"https:\/\/www.engineersgarage.com\/","name":"Engineers Garage","description":"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News","publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.engineersgarage.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.engineersgarage.com\/#organization","name":"Engineer's Garage - WTWH Media","url":"https:\/\/www.engineersgarage.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","width":372,"height":52,"caption":"Engineer's Garage - WTWH Media"},"image":{"@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/engineersgarage","https:\/\/x.com\/EngineersGarage","https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw"]},{"@type":"Person","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6","name":"Nikhil Agnihotri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g","caption":"Nikhil Agnihotri"},"url":"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/"}]}},"featured_image_src":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator-600x400.png","featured_image_src_square":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2024\/04\/Irrigation-system-for-garden-rotator-600x504.png","author_info":{"display_name":"Nikhil Agnihotri","author_link":"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/"},"_links":{"self":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/80957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/users\/387"}],"replies":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/comments?post=80957"}],"version-history":[{"count":0,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/80957\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media\/80973"}],"wp:attachment":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media?parent=80957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/categories?post=80957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/tags?post=80957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}