BeginnerArduino about 90 min

Automatic Plant Watering

A soil-moisture sensor switches a relay to run a small pump whenever the soil gets dry.

Steps

  1. Wire the sensor

    Soil sensor AO to A0, VCC to 5V, GND to GND.

  2. Wire the relay

    Relay IN to D7, VCC to 5V, GND to GND. Run the pump supply through the relay COM and NO terminals.

  3. Calibrate

    Print analogRead(A0) to the Serial Monitor with the probe in dry and wet soil and set DRY between the two readings.

Code

const int SOIL = A0, RELAY = 7;
const int DRY = 600;                 // calibrate: higher reading = drier soil (typical resistive probe)

void setup() {
  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, HIGH);         // HIGH = relay OFF on most active-LOW relay boards
}

void loop() {
  if (analogRead(SOIL) > DRY) {
    digitalWrite(RELAY, LOW);  delay(5000);    // pump on for 5 s
    digitalWrite(RELAY, HIGH); delay(60000);   // let the water soak in
  } else {
    delay(1000);
  }
}
Notes. A small 5V/12V submersible pump, tubing and a power supply for the pump are not part of the listed parts. Never touch mains wiring - use a low-voltage pump.