Project 05 · Soil · Relay · Pump

Automation with consequences.

Capacitive moisture, a threshold, and a pump that only runs when the soil is dry. Biology, electronics, and water discipline in one capstone.

3 × 45 minTeacher-supervised pumpActive-low relays varyCapstone
Pump, hose, relay, soil sensor kit
Typical kit: pump, silicone hose, relay, battery box, capacitive probe.
Soil moisture sensor on A0
Exercise 1: sensor VCC, GND, AOUT → A0. Dry ≈ 1023, wet ≈ 300.
Relay and pump with battery pack
Relay IN to a digital pin, COM/NO in the pump’s high-side supply.
Full automatic irrigation schematic
Full system: sensor + relay + pump + battery from the source document.

Three climbs

  1. Read moisture, draw a bar.
  2. Manual pump from Processing keys 1 / 0.
  3. Automatic: moisture > threshold turns the relay.
auto_irrigation.ino
#define RELAY_PIN 8
#define SENSOR_PIN A0
#define THRESHOLD 600

void setup() {
  Serial.begin(9600);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
}

void loop() {
  int moisture = analogRead(SENSOR_PIN);
  Serial.println(moisture);
  if (moisture > THRESHOLD) {
    digitalWrite(RELAY_PIN, HIGH); // dry → water
  } else {
    digitalWrite(RELAY_PIN, LOW);
  }
  delay(1000);
}
moisture_status.pde
import processing.serial.*;

Serial myPort;
int moisture = 0;

void setup() {
  size(440, 220);
  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
  background(255);
  fill(20);
  textSize(20);
  text("Soil moisture: " + moisture, 40, 70);
  if (moisture > 600) {
    fill(220, 40, 40);
    text("Status: DRY — watering", 40, 120);
  } else {
    fill(20, 140, 70);
    text("Status: WET — idle", 40, 120);
  }
  fill(40, 110, 230);
  rect(40, 150, map(moisture, 1023, 300, 0, 340), 28);
}

void serialEvent(Serial p) {
  String val = p.readStringUntil('\n');
  if (val != null) {
    val = trim(val);
    if (val.matches("\\d+")) moisture = int(val);
  }
}
Basic Number + DRY/WET text.
Intermediate Color bar (blue wet, red dry).
Advanced Manual override button in Processing.
Challenge Timestamped CSV, or skip-watering if you later add a rain API.
Hackathon challenges