Soil moisture sensor - ESP32
Print Profile(1)

Description
Boost Me (for free)
Soil Moisture Monitoring with ESP32 and Hygrometer Sensor
I took the battery compartment from this project. (https://makerworld.com/en/models/539919-18650-battery-case-21700-battery-case#profileId-467576)
Project Description
This project uses an ESP32 and a soil moisture sensor to monitor the soil’s humidity levels and send updates to a Telegram bot. The system is designed to optimize power consumption while ensuring reliable measurements over time.
The sensor is powered only when needed to prevent false readings and reduce battery consumption. Additionally, the ESP32 enters deep sleep between measurements to maximize battery life.
Components Used
- ESP32 → WiFi microcontroller for data acquisition and communication with Telegram https://a.aliexpress.com/_EHgo05I
- Soil Moisture Sensor → Measures soil humidity (analog output) (https://a.aliexpress.com/_EwnxyCG)
- Rechargeable Battery + 3.3V Voltage Regulator Module → Portable power supply
- Step - Down converter (https://a.aliexpress.com/_EwCGChA)
- Charger module board (https://a.aliexpress.com/_Ewn07kC)
Code
#include <WiFi.h>
#include <HTTPClient.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
#define WIFI_SSID "YOUR_WIFI"
#define WIFI_PASSWORD "YOUR_PASSWORD"
#define BOT_TOKEN "YOUR_BOT_TOKEN"
#define CHAT_ID "YOUR_CHAT_ID"
#define SENSOR_PIN 34 // Pin analogico per il sensore di umidità
#define POWER_PIN 32 // Pin per accendere/spegnere il sensore
#define SLEEP_TIME 30 // Minuti di deep sleep
float soglia_secco = 30.0; // Soglia per terreno troppo secco (%)
float soglia_umido = 70.0; // Soglia per terreno umido (%)
float ultima_umidita = -1; // Per evitare invii ripetuti
WiFiClientSecure client;
UniversalTelegramBot bot(BOT_TOKEN, client);
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnesso a WiFi!");
client.setInsecure(); // Per connessione senza certificati SSL
pinMode(POWER_PIN, OUTPUT);
digitalWrite(POWER_PIN, HIGH); // Accende il sensore
delay(1000); // Attendi stabilizzazione
int raw_value = analogRead(SENSOR_PIN);
float umidita = map(raw_value, 0, 4095, 100, 0); // Mappa il valore in %
Serial.print("Umidità rilevata: ");
Serial.print(umidita);
Serial.println("%");
if ((umidita < soglia_secco && ultima_umidita >= soglia_secco) ||
(umidita > soglia_umido && ultima_umidita <= soglia_umido)) {
String message = "🌱 Umidità attuale: " + String(umidita) + "%";
if (umidita < soglia_secco) {
message += "\n⚠️ Il terreno è troppo secco!";
} else if (umidita > soglia_umido) {
message += "\n✅ Il terreno è sufficientemente umido.";
}
bot.sendMessage(CHAT_ID, message, "");
}
ultima_umidita = umidita;
digitalWrite(POWER_PIN, LOW); // Spegne il sensore
Serial.println("Entrando in deep sleep...");
esp_sleep_enable_timer_wakeup(SLEEP_TIME * 60 * 1000000); // Tempo in microsecondi
esp_deep_sleep_start();
}
void loop() {
// Vuoto, non verrà mai eseguito a causa del deep sleep
}
License
You shall not share, sub-license, sell, rent, host, transfer, or distribute in any way the digital or 3D printed versions of this object, nor any other derivative work of this object in its digital or physical format (including - but not limited to - remixes of this object, and hosting on other digital platforms). The objects may not be used without permission in any way whatsoever in which you charge money, or collect fees.










Comment & Rating (5)