Soil probe powered only when reading
Build it step by step
0 of 8 doneWire the probe
VCC to D7, GND to GND, AO to A0.
Wire the OLED
SDA to A4, SCL to A5, power from 5V and GND.
Install the libraries
Adafruit SSD1306 and Adafruit GFX.
Calibrate dry
Probe in air, note the raw value.
Calibrate wet
Prongs in water, note the raw value.
Enter the values
Put them in DRY_RAW and WET_RAW.
Push the prongs into the soil
Watch the percentage.
Water the pot
The percentage rises within a minute.
How do you build a soil probe powered only when reading?
A resistive soil probe corrodes fast if it is powered all the time, so a pin switches it on only for a quick reading. You need Arduino Nano, Soil moisture sensor (resistive, YL-69), SSD1306 OLED Display, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.
- Level
- Beginner
- Time
- About 75 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Soil module VCC | Nano D7 | Power only while measuring |
| Soil module GND | Nano GND | Common ground |
| Soil module AO | Nano A0 | Analog moisture value |
| OLED VCC and GND | Nano 5V and GND | Power |
| OLED SDA | Nano A4 | I2C data |
| OLED SCL | Nano A5 | I2C clock |
Code
A resistive soil probe measures moisture by passing a small current between two metal prongs through the soil. If that current flows all day, electrolysis eats the prongs and the readings drift within weeks. The fix is simple: power the module from an output pin instead of from 5 volts, switch it on only for a short reading, and switch it off again. The Nano pin can safely supply a module of this kind, which draws only some milliamps. The sketch turns the probe on, waits 200 milliseconds for the reading to settle, averages eight samples, and turns it off, so the prongs are powered for well under a second out of every ten. On this probe a lower raw number means wetter soil. Measure the probe in dry air and in a glass of water, write those two numbers into DRY_RAW and WET_RAW, and the percentage then makes sense for your probe. Readings still depend on the soil type, how tightly it is packed and the temperature, so treat the percentage as a guide rather than an exact measure. Keep the electronics board and the OLED dry and push only the prongs into the pot. For a week long test, power a spare probe in a second pot all the time and compare how the two prongs look afterwards.
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).
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int PROBE_POWER = 7, PROBE_PIN = A0;
const int DRY_RAW = 950; // reading with the probe in dry air, measure yours
const int WET_RAW = 400; // reading with the prongs in a glass of water
const unsigned long EVERY = 10000; // one reading every 10 seconds
unsigned long last = 0;
int readProbe() {
digitalWrite(PROBE_POWER, HIGH); // power the probe
delay(200); // let the reading settle
long sum = 0;
for (int i = 0; i < 8; i++) { sum += analogRead(PROBE_PIN); delay(5); }
digitalWrite(PROBE_POWER, LOW); // and switch it off again
return sum / 8;
}
void setup() {
pinMode(PROBE_POWER, OUTPUT);
digitalWrite(PROBE_POWER, LOW);
Serial.begin(9600);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); // try 0x3D if the screen stays blank
oled.clearDisplay(); oled.display();
last = millis() - EVERY; // read at once
}
void loop() {
if (millis() - last >= EVERY) {
last = millis();
int raw = readProbe();
int pct = constrain(map(raw, DRY_RAW, WET_RAW, 0, 100), 0, 100);
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(2);
oled.setCursor(0, 4); oled.print("Soil "); oled.print(pct); oled.print("%");
oled.setTextSize(1);
oled.setCursor(0, 40); oled.print("Raw: "); oled.print(raw);
oled.display();
Serial.print(millis() / 1000); Serial.print(" s, raw "); Serial.print(raw);
Serial.print(", "); Serial.print(pct); Serial.println(" %");
}
}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.
0 s, raw 512, 79 %
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 dry air | About 0 percent |
| Prongs in water | About 100 percent |
| Damp soil | Somewhere in between |
| Between readings | Probe is unpowered |
| Water the pot | Percentage climbs on the next readings |
If it does not work
Screen blank
Try address 0x3D and check SDA and SCL.
Reading never changes
Check AO is on A0 and the probe is powered from D7.
Percentage backwards
Swap DRY_RAW and WET_RAW values you measured.
Readings jump
Increase the delay before reading or press the prongs deeper.
Probe is green or crusty
It was powered too long, replace it and keep the on-demand power.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the soil probe powered only when reading?
Arduino Nano, Soil moisture sensor (resistive, YL-69), SSD1306 OLED Display, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the soil probe powered only when reading take to build?
About 75 minutes for a beginner maker, in 8 steps.
How do I know the soil probe powered only when reading works?
Probe in dry air: About 0 percent. Prongs in water: About 100 percent. Damp soil: Somewhere in between.
Screen blank: what should I check?
Try address 0x3D and check SDA and SCL.
Reading never changes: what should I check?
Check AO is on A0 and the probe is powered from D7.
Percentage backwards: what should I check?
Swap DRY_RAW and WET_RAW values you measured.
Readings jump: what should I check?
Increase the delay before reading or press the prongs deeper.
