Soil Moisture Sensor & Smart Plant Hydration Monitor
Measure volumetric soil wetness with corrosion-saving pulsed excitation to automate indoor plant watering alerts.
Keep houseplants thriving by sensing soil moisture directly with an Arduino Uno. Wire the dual-prong soil probe and LM393 comparator module, convert raw ADC values into 0–100% moisture percentages, and power the probe only during brief 20ms readings to prevent galvanic electrode corrosion!
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerInstead of continuously energizing the copper soil forks from 5V (which electroplates them in days), we drive module VCC from Arduino pin D7 (<15mA) for just 20ms every 2 seconds. Powering the probe from digital pin D7 only during 20ms measurements extends probe lifespan by >50× by halting DC electrolysis!
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| Soil Moisture Sensor Probe + LM393 Module | Resistive dual-prong probe + analog/digital breakout | 1 | $1.80 |
| 5mm Blue/Red LED + 220Ω Resistor | Low-moisture plant alert indicator | 1 | $0.15 |
| Breadboard & Jumper Wires | 6× breadboard jumpers | 1 | $2.00 |
Electrical & System Architecture
Connect the 2-pin soil fork to the LM393 amplifier board. Wire amplifier VCC to D7 (switched power), GND to GND, AO to A0, and a Dry-Soil alert LED (+220Ω) to D8.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling Soil Moisture Fork Probe + LM393 Board acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Connect Soil Fork to LM393 Interface Board
Link the two-prong fork probe to the 2-pin side of the comparator module (non-polarized).
- Use two Female-to-Female jumpers to join the soil fork to the 2-pin header on the LM393 PCB.
- Never submerge the top white wire solder joints of the fork in water—insert only the lower plated prongs into soil.
- Identify the 4-pin Arduino side: VCC, GND, DO, AO.
Wire Switched Power (D7) & Analog Input (A0)
Power the sensor cleanly from D7 so firmware toggles it on only when measuring.
- Connect Soil Module VCC → D7, GND → GND, and AO → A0.
- Wire D8 → 220Ω resistor → Alert LED anode → cathode to GND.
- Connect USB power to the Arduino Uno.
Calibrate Dry vs. Wet ADC Endpoints
Record raw ADC in dry air and dipped in a cup of damp soil to tune DRY_ADC and WET_ADC.
- Upload the production sketch and open Serial Monitor.
- Note raw ADC in dry air (typically 980–1023).
- Insert prongs 3cm into damp potting soil and note raw ADC (typically 280–450).
Verify Anti-Corrosion Pulsed Operation
Watch the module's red power LED flash briefly once every 2 seconds as measurements occur.
- Observe the sensor's power LED pulsing briefly on each reading.
- Confirm Serial Monitor prints calibrated 0–100% Moisture cleanly.
- Verify D8 Alert LED lights when prongs sit in dry air/soil and turns off in moist soil.
Test Hydration Recovery
Pour a spoonful of water near the dry soil test pot and watch % moisture climb live.
- Insert probe into dry potting mix and verify Alert LED turns ON.
- Add a small amount of water and watch Moisture % jump above 50%.
- Confirm Alert LED extinguishes automatically.
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: Soil Moisture Fork Probe + LM393 Board Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for Soil Moisture Fork Probe + LM393 Board before running the full project firmware.
// Diagnostic: Pulsed Soil Raw ADC Check
void setup() { pinMode(7, OUTPUT); Serial.begin(115200); }
void loop() {
digitalWrite(7, HIGH); delay(20);
int raw = analogRead(A0);
digitalWrite(7, LOW);
Serial.print("Soil Raw ADC: "); Serial.println(raw);
delay(1500);
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 21: Anti-Corrosion Soil Moisture Hydration Monitor
* Board: Arduino Uno R3 | Pins: D7 (Switched VCC), A0 (AO), D8 (Dry Alert LED)
*/
const uint8_t PROBE_PWR_PIN = 7;
const uint8_t SOIL_AO_PIN = A0;
const uint8_t ALERT_LED = 8;
const int DRY_ADC = 1000; // Calibrated dry soil reading
const int WET_ADC = 300; // Calibrated saturated soil reading
const int THIRST_PCT = 35;
int readSoilRaw() {
digitalWrite(PROBE_PWR_PIN, HIGH);
delay(25); // Allow divider to settle
long sum = 0;
for (uint8_t i = 0; i < 4; i++) { sum += analogRead(SOIL_AO_PIN); delay(5); }
digitalWrite(PROBE_PWR_PIN, LOW); // Cut power to prevent electrolysis
return sum / 4;
}
void setup() {
pinMode(PROBE_PWR_PIN, OUTPUT);
digitalWrite(PROBE_PWR_PIN, LOW);
pinMode(ALERT_LED, OUTPUT);
Serial.begin(115200);
Serial.println(F("Smart Soil Hydration Monitor Ready"));
}
void loop() {
int raw = readSoilRaw();
int moisturePct = constrain(map(raw, DRY_ADC, WET_ADC, 0, 100), 0, 100);
bool needsWater = (moisturePct < THIRST_PCT);
digitalWrite(ALERT_LED, needsWater ? HIGH : LOW);
Serial.print(F("Raw ADC: ")); Serial.print(raw);
Serial.print(F(" | Moisture: ")); Serial.print(moisturePct);
Serial.print(F("% | Status: "));
Serial.println(needsWater ? F("DRY - WATER PLANT!") : F("HYDRATED"));
delay(2000);
}Firmware Architecture Explanation:
- Switches module power on D7 for just 45ms per 2-second cycle (<2.5% duty) to prevent fork corrosion.
- Maps inverted resistance readings (high=dry, low=wet) into intuitive 0–100% soil moisture.
- Illuminates D8 alert LED whenever soil hydration drops below 35%.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Moisture < 35% | A0 > 755 ADC | Dry Soil | D8 Alert LED ON (Water Plant) |
| Moisture ≥ 35% | A0 ≤ 755 ADC | Adequately Moist | D8 Alert LED OFF (Hydrated) |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Always reads 0% even in water | Soil fork jumpers unplugged from LM393 board or D7 power wire loose | Verify sensor power LED blinks every 2 seconds | Check both fork leads and confirm VCC connects to D7. |
| Readings fluctuate wildly | Loose soil air pockets around prongs | Press soil gently around the fork | Seat prongs firmly into uniform soil depth. |
| Probe forks turn dark/corroded quickly | Module wired permanently to 5V instead of pulsed D7 | Verify VCC wire lands on D7 | Use switched D7 excitation or upgrade to a capacitive soil sensor. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Show Red (<30% Dry), Green (30–75% Ideal), and Blue (>75% Overwatered).
Drive a 5V mini water pump via transistor/relay for 3 seconds whenever soil stays dry.
Render a happy or thirsty plant face on Project 4 OLED based on moisture %.