Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to design an app-controlled irrigation system

By Nikhil Agnihotri April 28, 2024

In this project, we’ll 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. 

The user can switch the water’s motor/electronic valve ON or OFF and even set a watering schedule via the app. This means 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.

Components required

1. ESP8266 x1
2. 3V relay x1
3. Electrical wires for connecting the motor, relay, and main supply
4. Connecting/DuPont wires for connecting the ESP8266 to the relay

Circuit connections
The device built in this project 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. 

To connect the relay with the microcontroller: 

  • Connect the relay’s input terminal with ESP8266’s GPIO 16
  • Connect the relay’s VCC and GND terminals with ESP8266’s 3V3 and ground pins

To connect the relay with the water pump or electronic valve:

  • Connect two wires to a two-pin top
  • Connect one of the top’s terminals with the relay terminal that’s normally open
  • Connect one of the pump/valve’s terminals with the relay’s common contact.
  • Connect the other pump/valve’s terminal with the other top’s terminal

The complete circuit is shown in the below diagram.

Building the app
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. 

The app has a single screen with buttons to turn the motor/valve’s 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’s operation. The time “pickers” and their labels are organized in horizontal arrangements. 

A client UDP extension is also part of the screen, which can be downloaded from the this link. 

After downloading the extension file, import it into the MIT App Inventor by navigating to Extension-> Import extension. 

The main (and only) screen of the app has the below design.

‘Screen1’ has the following properties.

‘Button1’ is used to switch ON/OFF the water pump/valve. It has the following properties.

‘Label1’ for the ‘TimePicker1’ has the following properties.

The ‘TimePicker1’ sets the start time of the motor/valve. It has the following properties.

‘Label2’ for the ‘TimePicker2’ has the following properties.

The ‘TimePicker2’ sets the stop time of the motor/valve. It has the following properties.

‘Button2’ schedules the operation of the motor/valve. It has the following properties.

The app has the following logic designed into the block editor.

Arduino sketch
After 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.

How it works
Users can instantly turn the water pump/valve ON/OFF or schedule its operation directly from their mobile app. A single button on the app’s screen turns the motor/valve ON/OFF. When a user taps that button to turn the motor/valve ON, the message “T1” 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. 

When a user taps the button to turn the motor/valve OFF, the app transmits the message “T0” to ESP8266 via the Internet over a UDP protocol. 

A user can also set a schedule for the motor/valve to operate by setting its start and stop time. Simply click on the app’s ‘TimePickers’ and then tap on the ‘Schedule’ button. When the schedule button is selected, a message in the format H<starttime_hours>M<starttime_minutes>X<stoptime_hours>Y<stoptime_minutes> is transmitted to ESP8266 over the UDP protocol. ESP8266 receives this message through the Wi-Fi network. 

The UDP packet received from the mobile app is analyzed on ESP8266. If the message received is “T1,” 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 “T0,” the motor/valve is turned OFF by deactivating the relay. 

If ESP8266 receives a message to schedule the motor/valve’s operation, the start and stop times are set based on the current local time — retrieved from the Weather API. ESP8266 also operates according to the last message received via the UDP protocol. 

The code
The sketch begins by importing the ESP8266WiFi.h, ESP8266HTTPClient.h, and WiFiClient.h libraries, which are required to handle ESP8266’s Wi-Fi connection. 

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’s hour and minute values, which are determined by the UDP packet. 

  • The user-defined connectWiFi() function connects ESP8266 with the Wi-Fi network. 
  • The convertToMinutes() function converts the local time received from the Weather API into minutes passed (since 12 AM). 
  • The stringToCharArray() function is defined to convert the string received from the Weather API into a character array. 
  • The getCurrentTime() function retrieves the current local time from the Weather API. 
  • The processMsg() function deconstructs the motor/vale’s start and stop times from the UDP message (received from the mobile app). 

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 “listen’ for messages received through the Internet.

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.

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’s operation, the start and stop times are validated and deconstructed from the message, and continuously compared with the current local time.

The results

https://www.engineersgarage.com/wp-content/uploads/2024/04/P59-DV.mp4

You may also like:


  • How to build an IoT-based flood monitor using ESP8266

  • How to build a plant health monitor using ESP8266 and…

  • How to make an Internet clock using ESP8266

  • How to get started with MIT App Inventor

  • How to design an IoT-based smart alarm

  • How to build a portable WiFi repeater using ESP32 or…

  • How to use MicroPython’s watchdog timer in ESP8266 and ESP32

Filed Under: Electronic Projects, ESP8266, Video
Tagged With: app, electronicproject, esp8266, farm, internetofthings, IoT, irrigation, mitappinventor, video
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Right Half Plane Zero
  • dc-dc converter in series
  • Single ended measuring ports and balanced antenna
  • Thermal modelling of repetitive power pulse
  • Permittivity and Permealibility in CST

RSS Electro-Tech-Online.com Discussions

  • Fun with AI and swordfish basic
  • Microinverters and storeage batteries?
  • FFC connector white
  • Is AI making embedded software developers more productive?
  • Can I make two inputs from one??

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe