Example Code for Arduino-Soil Moisture Sensing
This article guides you through setting up and coding an Arduino soil moisture sensor, offering hardware and software preparation, wiring diagrams, and sample code to accurately monitor moisture levels in soil.
Hardware Preparation
- Hardware
- DFRduino UNO R3 (or similar) x 1
- Analog Soil Moisture Sensor For Arduino x 1
Software Preparation
- Software
Wiring Diagram

Other Preparation Work
Connect the sensor to the A0(Analog 0) pin on the Arduino board.
Open the Arduino Serial Monitor, and choose its baud rate 57600 as set in the code.
Sample Code
/*
# Example code for the moisture sensor
# Editor : Lauren
# Date : 13.01.2012
# Version : 1.0
# Connect the sensor to the A0(Analog 0) pin on the Arduino board
# the sensor value description
# 0 ~300 dry soil
# 300~700 humid soil
# 700~950 in water
*/
void setup(){
Serial.begin(57600);
}
void loop(){
Serial.print("Moisture Sensor Value:");
Serial.println(analogRead(A0));
delay(100);
}
Result
Open the Arduino Serial Monitor, and choose its baud rate 57600 as set in the code.

Was this article helpful?

