Skip to content

AliDehghani06/PlantGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 

Repository files navigation

PlantGuard Banner

🌱 PlantGuard

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.


License Node.js ESP32 MongoDB MQTT JavaScript


Table of Contents


Overview

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.


Motivation

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

Key Features

🌿 Smart Plant Management

  • Add multiple plants
  • Manage plant information
  • Individual plant dashboard
  • Plant profile page

💧 Real-Time Soil Moisture Monitoring

  • Live moisture percentage
  • Automatic sensor updates
  • Moisture visualization
  • Historical measurements

🚿 Irrigation Control

  • Manual watering
  • Adjustable moisture thresholds
  • Remote pump control
  • Watering status visualization

📡 IoT Connectivity

  • ESP32 firmware
  • MQTT communication
  • Node.js backend
  • MongoDB persistence

👤 User Management

  • User authentication
  • Secure login
  • User registration
  • Personalized dashboard

📊 Data Visualization

  • Moisture history charts
  • Plant statistics
  • Dashboard widgets
  • Responsive charts

System Architecture

The overall system consists of four major layers:

  1. Embedded Layer
  2. Communication Layer
  3. Backend Layer
  4. 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.

Hardware Architecture

Hardware Architecture


Project Screenshots

Login

Login


Sign Up

Sign Up


Dashboard

Dashboard


My Plants

My Plants


Plant Details

Plant Details


Add New Plant

Add Plant


Add ESP32 Device

ESP32


Settings

Settings


Technology Stack

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

Project Structure

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

Backend Architecture

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.


Frontend

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.


Installation

Clone Repository

git clone https://github.com/<username>/PlantGuard.git
cd PlantGuard

Install Backend Dependencies

cd web_app/back_end
npm install

Required Packages

The backend uses the following major packages:

  • Express
  • Mongoose
  • MQTT
  • JWT
  • dotenv
  • cors

Development dependency:

  • Nodemon

Running the Project

Start the backend server using:

npm start

or for development:

npm run dev

The Express application serves the frontend from the public/ directory while exposing REST API endpoints for authentication, plant management, sensor communication, and system configuration.


ESP32 Firmware

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

Main Functional Components

User Management

  • Registration
  • Authentication
  • JWT-based authorization

Plant Management

  • Add plants
  • Delete plants
  • Plant details
  • Multiple plant support

Moisture Monitoring

  • Real-time measurements
  • Historical records
  • Moisture visualization

Irrigation Control

  • Manual watering
  • Moisture thresholds
  • Pump control

Device Management

  • ESP32 registration
  • Device configuration
  • Sensor communication

Folder Highlights

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

Additional Documentation

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.

Future Improvements

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

Lessons Learned

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.


Challenges

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.


Authors

Ali Dehghani

Electrical and Computer Engineering
University of Tehran

GitHub: https://github.com/


Armin Nezafat

Electrical and Computer Engineering
University of Tehran


Acknowledgments

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.


License

This project is released under the MIT License.

See the LICENSE file for more information.


Repository Topics

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


Repository Description

An IoT-based smart irrigation system using ESP32, MQTT, Node.js, and MongoDB for real-time soil moisture monitoring and automated plant watering.


⭐ If you found this project interesting, consider giving it a star!

Made with ❤️ using ESP32, Node.js, MongoDB, and MQTT

About

An IoT-based smart irrigation system using ESP32, MQTT, Node.js, and MongoDB for real-time soil moisture monitoring and automated plant watering.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors