PinoutSearch

Plant Moisture Monitor (Arduino)

Read a soil moisture sensor and light an LED when your plant needs watering. Learn analog thresholds.

Beginner20 min

What you need

Wiring

Hover a pin or a wire to trace the connection.

Code

soil_monitor.ino
// Light an LED when the soil is too dry.
const int soilPin = A0;
const int ledPin  = 13;
const int dryThreshold = 600;  // calibrate: read in dry air vs. wet soil

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int moisture = analogRead(soilPin);
  Serial.println(moisture);
  // Resistive sensors usually read HIGHER when dry. Flip if yours is opposite.
  digitalWrite(ledPin, moisture > dryThreshold ? HIGH : LOW);
  delay(500);
}

Steps

  1. Wire: VCC to 5V, GND to GND, AO to A0. LED on D13 through a 220Ω resistor to GND.
  2. Open the Serial Monitor; note the reading in dry air and in wet soil.
  3. Set `dryThreshold` between those two values.
  4. When the soil dries out past the threshold, the LED turns on.