How to Create a Solar-Powered Balcony Plant Soil Moisture Monitoring System with ESP32-C6

This tutorial will guide you through creating a sustainable, low-power balcony plant monitoring system using the FireBeetle ESP32-C6, a soil sensor, a solar panel, and a lithium battery. The system collects real-time soil moisture data and wirelessly transmits it to the user for remote monitoring and alerts. This comprehensive guide covers everything from hardware selection and circuit design to software development and data analysis, helping urban gardeners efficiently care for their plants.


a sustainable, low-power balcony plant monitoring system
1 FireBeetle ESP32-C6
1 Monocrystalline Solar Panel
1 Gravity: Analog Soil Moisture Sensor
1 Lithium Battery

Hardware Connections


Wiring Diagrams of FireBeetle ESP32 C6, solar panel, and soil sensor
Wiring Diagrams of FireBeetle ESP32 C6, solar panel, and soil sensor

Data Collection and Processing

The ESP32 microcontroller handles data collection, processing, and wireless transmission. Key functions include:

 1. Battery Voltage Collection: Use the IO0 pin to read battery voltage and convert it to a digital signal via ADC.

 2. Soil Moisture Collection: Use the IO3 pin to read soil moisture sensor voltage and convert it to a digital signal via ADC.

 3. Data Processing: Convert digital signals to actual voltage values and moisture percentages.

 4. Data Reporting: Connect to a WiFi network and send data to a server via HTTP for remote monitoring.


The sample code:

#include <WiFi.h>
#include <HTTPClient.h>

// #define DATA_SEND_INTERVAL_MS 15 * 60 * 1000
#define DATA_SEND_INTERVAL_MS 60 * 1000

int lastDataSentTimestamp = 0;
unsigned long previousMillis = 0;
unsigned long interval = 30000;

// WiFi network information
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

// Server URL
const char* serverName = "";
const char* serverToken = "your_influx_token";

// Define ADC pins
const int batteryPin = 0; // IO0
const int soilMoisturePin = 3; // IO3

void sendData() {
  // Collect battery voltage
  int batteryVoltage = analogReadMilliVolts(batteryPin)*2;
  Serial.print("BAT millivolts value = ");

  // Collect soil sensor voltage
  int soilMoisturePercent = analogReadMilliVolts(soilMoisturePin);
  Serial.print("Soil sensor voltage = ");

  // Create HTTP client
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.addHeader("Content-Type", "text/plain");
    http.addHeader("authorization", serverToken);
    // Create POST data
    String httpRequestData = "batteryVoltage=" + String(batteryVoltage) + "&soilMoisture=" + String(soilMoisturePercent);
    // Send HTTP POST request
    int httpResponseCode = http.POST(httpRequestData);
    // Print response result
    if (httpResponseCode > 0) {
      String response = http.getString();
    } else {
      Serial.print("Error on sending POST: ");
    // End HTTP request

void setup() {
  // Set the resolution to 12 bits (0-4096)

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("Connecting to WiFi...");
  Serial.println("Connected to WiFi");
  Serial.print("IP address: ");

void loop() {
  unsigned long currentMillis = millis();
  // if WiFi is down, try reconnecting
  if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >= interval)) {
    Serial.println("Reconnecting to WiFi...");
    previousMillis = currentMillis;
  if (millis() > lastDataSentTimestamp + DATA_SEND_INTERVAL_MS) {

    Serial.print("Millis since last measurement: ");
    Serial.println(millis() - lastDataSentTimestamp);
    lastDataSentTimestamp = millis();


Data Viewing Methods Server Setup

On your computer, follow these steps:

 1. Install Python 3.

 2. Install Flask:

    - Press Win+R, type cmd, and open the command prompt.

    - Enter pip install flask to install Flask.

 3. Run the Python code in the command line.

from flask import Flask, request, jsonify

app = Flask(__name__)

# Endpoint to handle data from Arduino
@app.route('/update', methods=['POST'])
def update():
    auth_header = request.headers.get('authorization')
    if auth_header == 'your_influx_token':
        data = request.data.decode('utf-8')
        print(f"Received data: {data}")
        # Process the data sent from Arduino here, such as storing it in a database
        return jsonify({"status": "success", "message": "Data received"}), 200
        return jsonify({"status": "error", "message": "Unauthorized"}), 401

def home():
    return "Hello from Flask server!", 200

if __name__ == '__main__':
    app.run(host='', port=5000)


Now, you can check the data:


check the data

Debugging and Running

 - Ensure Proper Hardware Connections: Connect the FireBeetle ESP32-C6, soil moisture sensor, solar panel, and lithium battery according to the circuit diagram.

 - Set WiFi Information: Enter the correct WiFi name and password in the code.

 - Server Configuration: Ensure the server-side code runs correctly and enter the correct server address and authorization token.

 - Initial Run: Troubleshoot potential issues like unstable hardware connections or code errors. Check each step carefully to ensure solid connections and correct code.

 - View Serial Monitor: Use the serial monitor to view ESP32-C6 outputs, aiding in debugging and troubleshooting.

Project Expansion

The onboard GDI interface allows for easy connection to screens, ensuring efficient data visualization. Detailed screen lists and configuration tutorials are provided to facilitate seamless integration of ESP32-C6 functionalities into any setup.

DFRobot's all Gravity and Fermion series sensors are compatible with the FireBeetle 2 ESP32-C6, offering a comprehensive selection for various projects.


This project provides a practical solution for monitoring balcony plants using the ESP32 microcontroller, soil moisture sensor, solar panel, and lithium battery. The system offers real-time environmental data and intelligent alerts, helping users efficiently care for their plants. The successful implementation shows the system's potential to improve balcony plant maintenance.

All Rights