Soil Moisture Sensor

Z2M Part: EMS-00019-A

Measure soil moisture level.

Circuit Diagram
Circuit diagram for Soil Moisture Sensor
Wire Connections & Pin Configuration

Wire Color Connections:

Yellow → A0 to sensor, Pins 6–7 to LEDs
Red → 5V to sensor VCC
Black → GND to sensor, LED cathodes

Pin Configuration:

Arduino Analog Pin A0 → Soil moisture sensor A0
Arduino Digital Pin 6 → Red LED anode (via 220Ω)
Arduino Digital Pin 7 → Green LED anode (via 220Ω)
Arduino 5V → Soil moisture sensor VCC
Arduino GND → Soil moisture sensor GND, LED cathodes
Arduino Code
Edit
#define red 6     // Connect red LED to pin 6
#define green 7   // Connect green LED to pin 7
int sensor = A0;  // Connect soil sensor analog output to A0

int threshold = 400; // Threshold for moisture detection

void setup() {
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(sensor, INPUT);
  Serial.begin(9600);
}

void loop() {
  int value = analogRead(sensor);  // Read soil moisture sensor value
  Serial.println(value);           // Print sensor value to Serial Monitor

  if (value > threshold) {
    digitalWrite(red, HIGH);       // Soil dry -> red LED ON
    digitalWrite(green, LOW);      // Turn green LED OFF
  } else {
    digitalWrite(green, HIGH);     // Soil moist -> green LED ON
    digitalWrite(red, LOW);        // Turn red LED OFF
  }

  delay(1000); // Wait 1 second before next reading
}

Instruction Details

Wiring: Connect soil moisture sensor VCC to 5V, GND to GND, A0 to Analog Pin A0. Connect red LED to Digital Pin 6 via 220Ω, green LED to Pin 7 via 220Ω. Cathodes to GND.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Red LED = dry soil, green LED = moist. Open Serial Monitor at 9600 baud for values. Insert probes in soil.

How to Use

  1. Connect the required components as per the Pin Configuration above
  2. Open Arduino IDE and create a new sketch
  3. Copy and paste the code above
  4. Select your Arduino board and COM port from Tools menu
  5. Click the Upload button to upload the code to your Arduino
  6. Open Serial Monitor (if applicable) to see the output

Components Required

  • Arduino Uno
  • Soil Moisture Sensor Module
  • Red LED
  • Green LED
  • 2× 220Ω Resistors
  • Breadboard
  • Jumper Wires

Category: Sensors