Build it step by step
0 of 8 doneWire the probe
VCC to 5V, GND to GND, AOUT to A0.
Wire the three LEDs
Each through 220 ohm, D2 green, D3 yellow, D4 red.
Upload the sketch
Serial monitor shows raw values.
Hold the probe in dry air
Note the raw value and set AIR_VALUE.
Put the sensing area in water
Note the raw value and set WATER_VALUE.
Upload again
Moisture percentage follows the probe.
Push the probe into damp soil
Green or yellow lights.
Leave it in dry soil
The red LED lights.
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
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm yellow × 1
- SemiconductorsBuyLED 5 mm green × 1
- PassivesBuyResistor 220 Ω × 3
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Probe VCC | Nano 5V | Power |
| Probe GND | Nano GND | Ground |
| Probe AOUT | Nano A0 | Analog reading |
| Red LED through 220 ohm | Nano D4 to GND | Dry |
| Yellow LED through 220 ohm | Nano D3 to GND | Getting dry |
| Green LED through 220 ohm | Nano D2 to GND | Moist |
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.
| Check | Expected |
|---|---|
| Probe in air | 0 percent and red LED |
| Probe in water | 100 percent and green LED |
| Probe in damp soil | Yellow or green LED |
| Dry soil | Red LED |
| Swap AIR_VALUE and WATER_VALUE | Readings 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 →
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.
