Arduino Soil Moisture Sensor
How the Soil Moisture Sensor Works
Resistive Sensor
Uses two metal probes to measure electrical resistance. Wet soil has lower resistance, while dry soil has higher resistance.
Capacitive Sensor
Measures changes in soil capacitance and has no exposed metal parts. It provides more stable and long-lasting performance.
Both sensors provide an analog output that Arduino reads.
Wiring the Soil Moisture Sensor
Soil Sensor → Arduino VCC → 5V GND → GND AO → A0
The digital output (DO) pin is optional and can be used with a preset threshold.
Arduino Code (Basic Reading)
int soilPin = A0;
int soilValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
soilValue = analogRead(soilPin);
Serial.print("Soil Moisture Value: ");
Serial.println(soilValue);
delay(1000);
}
Understanding Soil Moisture Values
| Sensor Value | Soil Condition |
|---|---|
| 0 – 300 | Very Wet |
| 300 – 600 | Moist |
| 600 – 900 | Dry |
| 900 – 1023 | Very Dry |
Values may vary depending on soil type. Always calibrate with dry and wet soil.
Improved Code with Moisture Status
int soilPin = A0;
int soilValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
soilValue = analogRead(soilPin);
Serial.print("Soil Moisture: ");
Serial.print(soilValue);
if (soilValue < 300) {
Serial.println(" - WET");
}
else if (soilValue < 600) {
Serial.println(" - MOIST");
}
else {
Serial.println(" - DRY");
}
delay(1000);
}
Testing the Sensor
- Upload the code to Arduino
- Open the Serial Monitor
- Set baud rate to 9600
- Insert the sensor into soil
- Add water and observe changes
Wet soil produces lower values, while dry soil produces higher values.
Troubleshooting
- Always reads 1023: Sensor not properly inserted
- No value change: Loose wiring or faulty sensor
- Unstable readings: Electrical noise or dry air
- Corrosion: Use capacitive sensor instead of resistive
Optional Upgrades
- Add relay and water pump for automatic irrigation
- Add LCD or OLED display
- Use ESP8266/ESP32 for IoT monitoring
- Log data to SD card for analysis.
