Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Soil Moisture Sensor with LED Indicator

View and Edit Project In Cirkit DesignerImage of ESP32-Based Soil Moisture Sensor with LED Indicator

Circuit Documentation

Summary

This circuit is designed to monitor soil moisture levels using a soil sensor and indicate the moisture status with an LED. The circuit uses an ESP32 microcontroller to read the soil sensor's output and control the LED. When the soil is dry, the LED will turn on, and when the soil is wet, the LED will turn off.

Component List

  1. ESP32

    • Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
  2. Soil Sensor

    • Description: A sensor used to measure the moisture content in the soil.
    • Pins: VCC, GND, D0, A0
  3. LED: Two Pin (red)

    • Description: A red LED used to indicate the soil moisture status.
    • Pins: Cathode, Anode
  4. Resistor

    • Description: A resistor used to limit the current through the LED.
    • Pins: Pin1, Pin2
    • Properties:
      • Resistance: 200 Ohms

Wiring Details

ESP32

Soil Sensor

LED: Two Pin (red)

Resistor

Code Documentation

Code for ESP32

#define SOIL_SENSOR_PIN 2  // Digital pin connected to soil sensor
#define LED_PIN 4          // Digital pin connected to LED

void setup() {
  pinMode(SOIL_SENSOR_PIN, INPUT);  // Set soil sensor pin as input
  pinMode(LED_PIN, OUTPUT);         // Set LED pin as output
  Serial.begin(115200);             // Initialize serial communication
}

void loop() {
  int sensorValue = digitalRead(SOIL_SENSOR_PIN);  // Read the digital value from the soil sensor
  Serial.println(sensorValue);  // Print the sensor value to the Serial Monitor

  if (sensorValue == LOW) {
    digitalWrite(LED_PIN, HIGH);  // Turn on the LED if soil is dry
  } else {
    digitalWrite(LED_PIN, LOW);   // Turn off the LED if soil is wet
  }

  delay(1000);  // Wait for a second before the next reading
}

This code initializes the soil sensor and LED pins, reads the soil sensor's digital output, and controls the LED based on the soil moisture level. The sensor value is also printed to the Serial Monitor for debugging and monitoring purposes.