ESP32 Soil Monitoring
This guide will walk you through building a low-power ESP32-based soil monitor using a Soil sensor. The device uses deep sleep mode to conserve power, waking up at set intervals to collect a soil moister data and send it to your Telemetry Harbor instance for visualization and analysis.
Repo Link: https://github.com/TelemetryHarbor/harbor-esp32-soil-sensor
Overview
This project wakes up periodically, reads soil moisture percentage from the 2-prong sensor, sends it to Telemetry Harbor, and returns to deep sleep for ultra-low-power operation. Ideal for gardens, potted plants, and soil monitoring projects.
Features
- Ultra-Low Power: Uses ESP32 Deep Sleep mode to extend battery life.
- 2-Prong Soil Sensor Support: Accurate analog readings from standard 2-prong sensors.
- Cloud Connectivity: Sends readings to Telemetry Harbor using the official SDK.
- Timestamped Data: Each reading is recorded with an ISO8601 UTC timestamp.
- Grafana Dashboards: Ready for visualization with Telemetry Harbor.
Hardware Requirements
Component | Description | Approximate Cost |
---|---|---|
ESP32 | Development board (NodeMCU ESP32, WROOM, etc.) | $3.82 (AliExpress) / $9.90 (Amazon US) |
2-Prong Soil Sensor | Capacitive or resistive soil moisture probe | $1.50–$3.00 |
Jumper wires | For connecting sensor | $0.42 (AliExpress) / $5.49 (Amazon US) |
Micro USB cable | For power & programming | $3.00 (AliExpress) / $5.00 (Amazon US) |
Battery (optional) | For standalone, low-power operation | Cost varies |
Software Requirements
-
Arduino IDE (1.8.13 or newer) or PlatformIO
-
ESP32 board support package
-
Required libraries:
- Telemetry Harbor SDK
- WiFi Library (built into ESP32 core)
-
Telemetry Harbor account
Wiring Diagram
Connect the 2-prong soil sensor to the ESP32:
Soil Sensor Pin | ESP32 Pin | Function |
---|---|---|
VCC | 3.3V | Power |
GND | GND | Ground |
Signal / Output | GPIO 34 | Analog input |
Notes:
- Ensure both sensor prongs share a common ground with ESP32.
- Capacitive sensors are recommended for long-term use; resistive sensors may corrode over time.
- Analog values can be noisy; consider averaging multiple readings.
Setup Instructions
1. Hardware Assembly
- Connect the 2-prong soil sensor to the ESP32 according to the wiring diagram.
- Connect the ESP32 to your computer via USB.
2. Software Setup
-
Install Arduino IDE.
-
Add ESP32 board support:
-
Preferences → Additional Boards Manager URLs:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
-
-
Install required libraries via Library Manager:
- Telemetry Harbor SDK
- WiFi Library (built-in)
3. Telemetry Harbor Configuration
- Create a Telemetry Harbor account.
- Create a new Harbor called
"ESP32_Soil_Monitor"
(or your preferred name). - Copy the API ENDPOINT and API Key from the Harbor details page.
4. Configure and Upload the Code
-
Open your soil sensor
.ino
file in Arduino IDE. -
Update the following variables at the top of the file:
- WiFi SSID and password
- Telemetry Harbor API Endpoint URL and API Key
shipId
(e.g.,"Garden 1"
)
-
Select your ESP32 board and COM port.
-
Upload the code.
5. Visualize Your Data
- Log in to your Telemetry Harbor account.
- Navigate to the Harbor details page and Grafana dashboard.
- Monitor soil moisture in real time and over time.
Customization
Sleep Interval
Change how often the ESP32 wakes up:
const int SLEEP_INTERVAL_SEC = 300; // 5 minutes
Sensor Calibration
Adjust offset for more accurate readings:
const float SOIL_OFFSET = 0.0; // +/- percentage for calibration
Debug Mode
Add Serial prints for testing:
Serial.printf("Raw ADC: %d, Moisture: %.2f%%\n", raw, moisture);
Disable deep sleep during debugging to view Serial output.
Troubleshooting
- Sensor gives constant values: Verify wiring, common ground, and analog output.
- WiFi connection fails: Check credentials; device retries on next wake cycle.
- Data not appearing in Telemetry Harbor: Verify API Key and Endpoint URL.