Skip to main content

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 Carroted Data instance for visualization and analysis.

Repo Link: https://github.com/harborscale/harbor-esp32-soil-sensor


Overview​

This project wakes up periodically, reads soil moisture percentage from the 2-prong sensor, sends it to Carroted Data, 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 Carroted Data using the official SDK.
  • Timestamped Data: Each reading is recorded with an ISO8601 UTC timestamp.
  • Grafana Dashboards: Ready for visualization with Carroted Data.

Hardware Requirements​

ComponentDescriptionApproximate Cost
ESP32Development board (NodeMCU ESP32, WROOM, etc.)$3.82 (AliExpress) / $9.90 (Amazon US)
2-Prong Soil SensorCapacitive or resistive soil moisture probe$1.50–$3.00
Jumper wiresFor connecting sensor$0.42 (AliExpress) / $5.49 (Amazon US)
Micro USB cableFor power & programming$3.00 (AliExpress) / $5.00 (Amazon US)
Battery (optional)For standalone, low-power operationCost varies

Software Requirements​

  • Arduino IDE (1.8.13 or newer) or PlatformIO

  • ESP32 board support package

  • Required libraries:

    • Carroted Data SDK
    • WiFi Library (built into ESP32 core)
  • Carroted Data account

Wiring Diagram​

Connect the 2-prong soil sensor to the ESP32:

Soil Sensor PinESP32 PinFunction
VCC3.3VPower
GNDGNDGround
Signal / OutputGPIO 34Analog 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​

  1. Connect the 2-prong soil sensor to the ESP32 according to the wiring diagram.
  2. Connect the ESP32 to your computer via USB.

2. Software Setup​

  1. Install Arduino IDE.

  2. Add ESP32 board support:

    • Preferences → Additional Boards Manager URLs:

      https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
  3. Install required libraries via Library Manager:

    • Carroted Data SDK
    • WiFi Library (built-in)

3. Carroted Data Configuration​

  1. Create a Carroted Data account.
  2. Create a new Harbor called "ESP32_Soil_Monitor" (or your preferred name).
  3. Copy the API ENDPOINT and API Key from the Harbor details page.

4. Configure and Upload the Code​

  1. Open your soil sensor .ino file in Arduino IDE.

  2. Update the following variables at the top of the file:

    • WiFi SSID and password
    • Carroted Data API Endpoint URL and API Key
    • shipId (e.g., "Garden 1")
  3. Select your ESP32 board and COM port.

  4. Upload the code.

5. Visualize Your Data​

  1. Log in to your Carroted Data account.
  2. Navigate to the Harbor details page and Grafana dashboard.
  3. 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 Carroted Data: Verify API Key and Endpoint URL.