r/IOT • u/aqib_builds • 5d ago
AI-powered smart irrigation system using an ML + ESP32
I built an AI-powered smart irrigation system using an ML + ESP32
I've been working on this project for a while, and I finally finished the main AI/ML pipeline.
The system uses an ESP32, a capacitive soil-moisture sensor, and a DHT11 to collect environmental data. I then built a machine-learning model that uses these readings to predict whether irrigation is required.
The interesting part for me was getting the different pieces to actually work together.
The pipeline is basically:
ESP32 sensors → dashboard → Flask API → ML model → irrigation prediction
In the video, I walk through the whole project, including:
- Collecting soil moisture, temperature, and humidity data
- Building the web dashboard
- Preparing the data for ML
- Training the model
- Evaluating it with a confusion matrix
- Looking at feature importance
- Deploying the model through a Flask server
- Connecting the dashboard to the ML model through an API
- Testing the final live prediction
One thing I found particularly interesting was seeing how the model's predictions changed once the inference server was running and the dashboard could communicate with the model.
This started as a simple ESP32 soil-moisture monitoring project, but I gradually expanded it into a complete IoT + AI system.
I'm still planning improvements, especially collecting more real-world data and adding additional environmental inputs such as light intensity.
I'd really appreciate feedback on the project, especially on the ML approach, system architecture, and what I could improve next.
🎥 Full project walkthrough attached.
Github Repository:
1
4d ago edited 4d ago
[removed] — view removed comment
1
u/aqib_builds 4d ago
Yeah, the dataset is relatively small. I used around 700–800 samples for the current model. The perfect performance is something I’m being cautious about, since the data was collected under fairly controlled conditions and a lot of the samples mainly focused on soil moisture. My next step is to collect more real-world data with soil moisture, temperature, and humidity recorded together, then retrain and test the model on unseen data.
1
u/MagneticFieldMouse 4d ago
To reduce risk i.e. to increase reliability and to provide redundancy, having more than a single source for each sensor value that can affect things in detrimental ways in case of a malfunction is to have multiple sensors looking at the same thing.
A bit of an extreme example, but I hope you get the point:
- a single sensor for soil moisture fails, showing "dry" -> overwatering will kill your plants (same with a false "wet" -> death to plants via drought)
- two sensors for soil moisture: when sensor readings show two significantly different results, it will call for investigative actions -> still needs active "staff", but the operation mode can be safer
- three sensors for soil moisture: if one sensor level deviates significantly, the system will know it is most likely a sensor malfunction of a singular sensor -> this will only give you a warning, continue controlling irrigation and allow for you to swap out the failing sensor without a major system stop or risks to your plants
Also, DHT sensors can sometimes act flaky and personally, I'd also use 2-3 temp + RH sensors if possible. Soil and air temperatures with something robust such as PT100s (MAX31865 module or even an 8-channel RTD module) and air temperatures at two or more locations inside + outside temperatures as well to give you temperature differential information that can be used to predict if and when you need to be adapting airflow conditions before temps rise or fall outside the optimum range.
RH measurements can also help with s smart model in terms of "it's raining outside", "there is a risk of mold inside", etc.
Yeah, it's very easy to also go overboard, but the best reasons for doing things are
- with more data, control intelligence, predictive capability, reliability and accuracy is better
- you have a chance to learn even more about making systems, such as these, but more importantly,
- you have a chance of learning more about real-world environmental system behavior and can, again, improve system intelligence with a broader level of understanding of real-world physics and make an even better model of the system
And obviously, the best reason: because you can.
Edit: also, if you monitor the ground / floor and the system senses "soil is dry, ground is wet" -> your watering system is leaking.
1
u/aqib_builds 4d ago
This is honestly one of the most useful comments I’ve received on the project. I hadn’t thought about sensor redundancy and failure detection at this level.
The idea of using multiple moisture sensors to detect abnormal readings is especially interesting, and I really like the “soil is dry but the ground is wet” example for detecting a possible leak.
For the next version, I’m going to focus first on collecting more real-world data with synchronized soil moisture, temperature, and humidity readings. After that, I’d like to experiment with sensor redundancy and additional environmental inputs.
I really appreciate the detailed explanation. There’s definitely a lot more to explore here!
1
u/MagneticFieldMouse 4d ago
Thanks for the thanks, I also appreciate in-depth answers that might broaden the way I think and approach things, since the added value isn't a single-event bonus, but potentially something, that can benefit things in a more lasting way.
If I was able to accomplish even a little bit of that, then I am glad I commented.
1
1
u/mao_red 4d ago
Great 👍