Projects / Soil moisture traffic light

Soil moisture traffic light

Beginner1.7 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the probe

    VCC to 5V, GND to GND, AOUT to A0.

  2. NANO12.0 mA

    Wire the three LEDs

    Each through 220 ohm, D2 green, D3 yellow, D4 red.

  3. NANO

    Upload the sketch

    Serial monitor shows raw values.

  4. NANO

    Hold the probe in dry air

    Note the raw value and set AIR_VALUE.

  5. NANO

    Put the sensing area in water

    Note the raw value and set WATER_VALUE.

  6. NANOCAPACITIsoil 37%

    Upload again

    Moisture percentage follows the probe.

  7. NANOCAPACITIsoil 37%

    Push the probe into damp soil

    Green or yellow lights.

  8. NANOCAPACITIsoil 37%

    Leave it in dry soil

    The red LED lights.

In short

How do you build a soil moisture traffic light?

A capacitive probe lights green, yellow or red LEDs so you know when a pot needs water. You need Arduino Nano, Capacitive Soil Moisture Module, LED 5 mm red, LED 5 mm yellow, LED 5 mm green, Resistor 220 Ω × 3, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 100 minutes.

Level
Beginner
Time
About 100 min
Parts
8

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Probe VCCNano 5VPower
Probe GNDNano GNDGround
Probe AOUTNano A0Analog reading
Red LED through 220 ohmNano D4 to GNDDry
Yellow LED through 220 ohmNano D3 to GNDGetting dry
Green LED through 220 ohmNano D2 to GNDMoist

Code

A capacitive soil probe measures how the soil changes the capacitance of a printed sensor, which is why it does not corrode like the older two-prong resistive probes. Its output voltage falls as the soil gets wetter, so a dry probe in air reads high and a probe in water reads low. Because every probe is a little different, you calibrate it: note the reading in air and the reading with the sensing area in water, and put those numbers in the sketch. The map() call turns the reading into a moisture percentage, and two thresholds choose which LED lights. Averaging sixteen readings steadies the value. Keep the electronics above the line marked on the probe out of the soil and water, and seal the top edge with a little nail varnish or heat shrink if you leave it in a pot. The thresholds of 30 and 60 percent are starting points; different plants like different levels, so adjust them for your plant.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const int PROBE = A0;
const int LED_GREEN = 2, LED_YELLOW = 3, LED_RED = 4;

// Calibrate these two numbers with your own probe:
// AIR_VALUE   = reading with the probe held in dry air (high number)
// WATER_VALUE = reading with the sensing part in a glass of water (low number)
const int AIR_VALUE = 620;
const int WATER_VALUE = 300;

int readSmooth() {
  long sum = 0;
  for (int i = 0; i < 16; i++) { sum += analogRead(PROBE); delay(5); }
  return sum / 16;
}

void setup() {
  pinMode(LED_GREEN, OUTPUT); pinMode(LED_YELLOW, OUTPUT); pinMode(LED_RED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int raw = readSmooth();
  int pct = map(raw, AIR_VALUE, WATER_VALUE, 0, 100);   // 0 = dry, 100 = wet
  pct = constrain(pct, 0, 100);

  digitalWrite(LED_RED,    pct < 30);
  digitalWrite(LED_YELLOW, pct >= 30 && pct < 60);
  digitalWrite(LED_GREEN,  pct >= 60);

  Serial.print("raw "); Serial.print(raw);
  Serial.print("  moisture "); Serial.print(pct); Serial.println(" %");
  delay(1000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

raw 511  moisture 34 %
raw 512  moisture 33 %
raw 511  moisture 34 %

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Probe in air0 percent and red LED
Probe in water100 percent and green LED
Probe in damp soilYellow or green LED
Dry soilRed LED
Swap AIR_VALUE and WATER_VALUEReadings invert, put them back

If it does not work

Percentage stuck at 0 or 100

Re-measure AIR_VALUE and WATER_VALUE.

Readings noisy

Keep wires short and away from motors.

Wrong LED lights

Check the LED legs and the pin numbers.

Probe gives odd readings

Check it is a capacitive probe and not a resistive one.

Readings drift over days

Soil temperature and packing change readings, recheck now and then.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the soil moisture traffic light?

Arduino Nano, Capacitive Soil Moisture Module, LED 5 mm red, LED 5 mm yellow, LED 5 mm green, Resistor 220 Ω × 3, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the soil moisture traffic light take to build?

About 100 minutes for a beginner maker, in 8 steps.

How do I know the soil moisture traffic light works?

Probe in air: 0 percent and red LED. Probe in water: 100 percent and green LED. Probe in damp soil: Yellow or green LED.

Percentage stuck at 0 or 100: what should I check?

Re-measure AIR_VALUE and WATER_VALUE.

Readings noisy: what should I check?

Keep wires short and away from motors.

Wrong LED lights: what should I check?

Check the LED legs and the pin numbers.

Probe gives odd readings: what should I check?

Check it is a capacitive probe and not a resistive one.