Experiment 10 : Build a Live Soil Moisture Monitoring System on Your Computer Dashboard
Published at : 23 Dec 2025
Learn how to build a live soil-moisture monitoring system and stream sensor data to a real-time dashboard on your computer. Full parts list, wiring, code (Arduino/ESP32 + Python), and dashboard setup included. Perfect for gardeners, students, and IoT beginners!
Here is the Code for it :
#include (WiFi.h) (angled brackets)
#include "ThingSpeak.h"
// -----------------------
// WiFi Credentials
// -----------------------
const char* ssid = "ssid Name";
const char* password = "password";
// -----------------------
// ThingSpeak Setup
// -----------------------
WiFiClient client;
unsigned long myChannelNumber = 1; // Example: 123456
const char* myWriteAPIKey = "WriteAPIKey";
// -----------------------
// Sensor Pin
// -----------------------
int soilPin = 34; // ESP32 ADC pin for soil moisture sensor
int soilValue = 0;
void setup()
(
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println("\nWiFi connected!");
ThingSpeak.begin(client);
)
void loop()
(
// Read Soil Moisture
soilValue = analogRead(soilPin); // Raw ADC value (0–4095)
// Convert to percentage (Optional)
// Adjust "dry" and "wet" values based on your calibration
int dry = 3500;
int wet = 1200;
int moisturePercent = map(soilValue, dry, wet, 0, 100);
moisturePercent = constrain(moisturePercent, 0, 100);
Serial.print("Raw Soil Value: ");
Serial.print(soilValue);
Serial.print(" | Moisture: ");
Serial.print(moisturePercent);
Serial.println("%");
// -----------------------
// Send to ThingSpeak
// -----------------------
ThingSpeak.setField(1, moisturePercent);
int status = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if (status == 200) (
Serial.println("Data sent to ThingSpeak successfully!");
) else (
Serial.println("Error sending data. HTTP Code: " + String(status));
)
delay(15000); // ThingSpeak requires at least 15 seconds between updates
)