An IoT-Based Automated Soil Moisture Monitoring and Irrigation System using ESP32, Node.js, MQTT and MongoDB
Smart irrigation platform that continuously monitors soil moisture, enables remote plant management through a web dashboard, and automates watering decisions based on configurable thresholds.
- Overview
- Motivation
- Key Features
- System Architecture
- Project Screenshots
- Technology Stack
- Project Structure
- Installation
- Running the Project
- ESP32 Firmware
- Future Improvements
- Lessons Learned
- Authors
- License
PlantGuard is an Internet of Things (IoT) project designed to automate soil moisture monitoring and irrigation for household plants and small-scale agricultural applications.
The system combines embedded hardware, cloud communication, and a modern web interface into a unified platform capable of monitoring soil conditions in real time and remotely controlling irrigation.
The hardware continuously measures soil moisture using an ESP32 microcontroller and a resistive soil moisture sensor. Sensor data is transmitted through the MQTT protocol to a Node.js backend where it is processed, stored in MongoDB, and presented through a responsive web dashboard.
In addition to live monitoring, the platform allows users to:
- monitor soil moisture remotely
- manually activate irrigation
- configure moisture thresholds
- manage multiple plants
- register ESP32 devices
- visualize historical moisture data
The project demonstrates the integration of Embedded Systems, Web Development, Cloud Communication, and Database Management into a complete full-stack IoT application.
Traditional irrigation methods often waste significant amounts of water because watering decisions are based on fixed schedules rather than actual soil conditions.
PlantGuard addresses this problem by introducing an intelligent irrigation workflow where watering decisions are driven by real-time sensor measurements.
The primary goals of this project include:
- reducing unnecessary water consumption
- improving plant health
- enabling remote monitoring
- providing an extensible IoT platform
- demonstrating practical integration of embedded systems with web technologies
- Add multiple plants
- Manage plant information
- Individual plant dashboard
- Plant profile page
- Live moisture percentage
- Automatic sensor updates
- Moisture visualization
- Historical measurements
- Manual watering
- Adjustable moisture thresholds
- Remote pump control
- Watering status visualization
- ESP32 firmware
- MQTT communication
- Node.js backend
- MongoDB persistence
- User authentication
- Secure login
- User registration
- Personalized dashboard
- Moisture history charts
- Plant statistics
- Dashboard widgets
- Responsive charts
The overall system consists of four major layers:
- Embedded Layer
- Communication Layer
- Backend Layer
- Frontend Layer
The ESP32 continuously reads soil moisture values and communicates with the backend through MQTT.
The backend processes incoming sensor data, stores measurements inside MongoDB, and exposes REST APIs used by the web interface.
The frontend provides a responsive dashboard where users can monitor plants, control irrigation, and configure system settings.
The project combines embedded systems, backend development, database management, and modern web technologies into a unified IoT platform.
| Layer | Technologies |
|---|---|
| Firmware | ESP32, ESP-IDF, C |
| Backend | Node.js, Express.js |
| Database | MongoDB (Mongoose) |
| Communication | MQTT |
| Frontend | HTML5, CSS3, JavaScript (ES6) |
| Authentication | JSON Web Token (JWT) |
| Development Tools | npm, Nodemon |
PlantGuard
│
├── docs/
│ ├── screenshots/
│ ├── architecture.png
│ └── Project_Report.pdf
│
├── web_app/
│ ├── back_end/
│ │ ├── controllers/
│ │ ├── middleware/
│ │ ├── models/
│ │ ├── mqtt/
│ │ ├── public/
│ │ ├── routes/
│ │ ├── app.js
│ │ └── package.json
│ │
│ └── esp32_firmware/
│ ├── main/
│ ├── components/
│ └── ...
│
└── README.md
The backend follows a modular architecture based on Express.js.
Its responsibilities include:
- User authentication
- Plant management
- Moisture data processing
- Sensor communication
- Device registration
- Configuration management
- Static frontend hosting
The application is organized into:
- Controllers
- Models
- Routes
- Middleware
- MQTT Client
- Static Web Interface
This separation improves maintainability, scalability, and readability.
The web application is implemented as a responsive multi-page interface using vanilla HTML, CSS, and JavaScript.
Main pages include:
- Login
- Sign Up
- Dashboard
- My Plants
- Plant Details
- Add New Plant
- Add ESP32 Device
- Settings
The frontend communicates with the backend through REST APIs and provides a clean dashboard for monitoring and controlling the irrigation system.
git clone https://github.com/<username>/PlantGuard.git
cd PlantGuardcd web_app/back_end
npm installThe backend uses the following major packages:
- Express
- Mongoose
- MQTT
- JWT
- dotenv
- cors
Development dependency:
- Nodemon
Start the backend server using:
npm startor for development:
npm run devThe Express application serves the frontend from the public/ directory while exposing REST API endpoints for authentication, plant management, sensor communication, and system configuration.
The firmware is located in
web_app/esp32_firmware/
The firmware is responsible for:
- Reading soil moisture values
- Processing analog sensor data
- Communicating through MQTT
- Receiving irrigation commands
- Controlling the water pump
- Registration
- Authentication
- JWT-based authorization
- Add plants
- Delete plants
- Plant details
- Multiple plant support
- Real-time measurements
- Historical records
- Moisture visualization
- Manual watering
- Moisture thresholds
- Pump control
- ESP32 registration
- Device configuration
- Sensor communication
| Directory | Description |
|---|---|
controllers/ |
Business logic |
models/ |
MongoDB models |
routes/ |
REST API endpoints |
middleware/ |
Authentication middleware |
mqtt/ |
MQTT communication |
public/ |
Frontend application |
esp32_firmware/ |
ESP32 source code |
docs/ |
Documentation, screenshots, and project report |
The README provides an overview of the project.
For readers interested in the engineering process, implementation details, hardware design decisions, firmware workflow, and development methodology, a comprehensive project report is included in the docs/ directory.
This report complements the repository by documenting the complete design and implementation process of the PlantGuard system.
PlantGuard was designed with extensibility in mind. Several enhancements can be implemented in future versions to expand its capabilities:
- Support for multiple environmental sensors (temperature, humidity, light intensity, etc.)
- Smart irrigation scheduling based on weather forecasts
- Push notifications for critical plant conditions
- Historical analytics dashboard with advanced charts
- Mobile application for Android and iOS
- OTA (Over-the-Air) firmware updates for ESP32 devices
- Role-based access control for multiple users
- Automatic detection of sensor failures
- Integration with cloud IoT platforms
- AI-assisted irrigation recommendations based on historical data
Developing PlantGuard provided practical experience across multiple engineering disciplines.
Throughout this project, we gained hands-on experience with:
- Designing and implementing an end-to-end IoT system
- Developing RESTful APIs using Express.js
- Building a responsive web interface using HTML, CSS, and JavaScript
- Managing NoSQL databases with MongoDB
- Implementing MQTT-based communication between embedded devices and backend services
- Structuring a scalable backend using modular architecture
- Integrating embedded firmware with a full-stack web application
- Applying software engineering principles to a real-world engineering problem
The project also highlighted the importance of modular software design, reliable communication protocols, and user-centered interface development in modern IoT applications.
Some of the technical challenges encountered during development included:
- Integrating embedded hardware with the backend server
- Managing reliable MQTT communication
- Designing a modular backend architecture
- Synchronizing real-time sensor data with the web interface
- Implementing authentication and secure user management
- Organizing the project into reusable and maintainable components
Overcoming these challenges significantly improved both the robustness of the system and our understanding of full-stack IoT development.
Ali Dehghani
Electrical and Computer Engineering
University of Tehran
GitHub: https://github.com/
Armin Nezafat
Electrical and Computer Engineering
University of Tehran
This project was developed as part of the Electrical Circuit I course at the Department of Electrical and Computer Engineering, University of Tehran.
We would like to express our appreciation to the course instructors and teaching assistants for their guidance and valuable feedback throughout the development process.
This project is released under the MIT License.
See the LICENSE file for more information.
The following GitHub topics are recommended for this repository:
iot
esp32
smart-irrigation
soil-moisture
mqtt
nodejs
express
mongodb
embedded-systems
internet-of-things
automation
agriculture
smart-farming
web-dashboard
plant-monitoring
rest-api
javascript
embedded-c
full-stack
engineering-project
An IoT-based smart irrigation system using ESP32, MQTT, Node.js, and MongoDB for real-time soil moisture monitoring and automated plant watering.








