A soil moisture sensor, as the name implies, allows measuring the moisture level of soil. This can be particularly helpful if you want to accurately determine when plants need to be watered or assess how fast water is draining at a specific location.
Sensor Components
The Soil Moisture Sensor has two main components:
- Soil probe.
- Sensor circuit board.
The soil probe is what will make contact with the soil to assess the water level, while the sensor circuit board will process the soil probe’s signal and output it through the analog output pin. The circuit board will also generate a digital output which generates a HIGH or LOW depending on the potentiometer setting.

Soil Moisture Sensor Length
The probe has an overall measuring range of 1.6 inches (~41mm).

Click to enlarge
Sensor Pins
VCC – Connected to Arduino UNO 5V output.
GND – Connected to Arduino GND.
DO – Digital Output
AO – Analog Output
Connection pins from probe to sensor circuit board

Connection to Arduino
The sensor can be used through use of the analog output or the digital output. Both options shown below:
Arduino Code – Analog Output Option
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//Arduino Code - Soil Moisture int Moisture_signal = A0; //Define the Analog pin# on the Arduino for the soil moisture sensor signal void setup() { Serial.begin(9600); // Start the serial communication } void loop() { int Moisture = analogRead(Moisture_signal); Serial.print("Soil Moisture Level: "); Serial.println(Moisture); delay(200); } |
Arduino Code – Digital Output Option
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//Arduino Code - Soil Moisture int Moisture__dig_signal = 4; //Define the Digital Input on the Arduino for the sensor signal int Sensor_State = 1; void setup() { pinMode(Moisture__dig_signal, INPUT); //Step pin as input Serial.begin(9600); // Start the serial communication } void loop() { Serial.print("Soil Moisture Level: "); Sensor_State = digitalRead(Moisture__dig_signal); if (Sensor_State == 1) { Serial.println("Wet"); } else { Serial.println("Dry"); } delay(200); } |
Run Arduino Code – Testing Soil Moisture Sensor
All you need to do now is run the code that was provided above, in either configuration, and open the Serial Monitor.

Alternate Connection Method to Extend Soil Moisture Sensor Life
One thing to note is, if you plan on using this sensor for an extended period of time, note that the probe will corrode over time. One way to slow the corrosion rate is to only power the sensor when you need to take readings. To do this, you will need to connect the sensor by powering VCC with a digital output from the Arduino UNO. In this case, simply set the pin as an output, and set it to HIGH whenever you need to take readings. Once done, set the IO pin to LOW, which will set VCC in the sensor to zero, turning the sensor off. Something to consider when doing this is, can the IO pin supply the required current to the sensor? Below we will confirm this for the Arduino UNO.
Sensor working current
The setup about requires powering the sensor through an IO port. The Arduino UNO’s maximum current per IO pin of 20mA. Luckily this sensor doesn’t pull that much current. After setting up a multimeter, the current flowing through VCC was measured to be 4.08mA, so there should be no issues powering the sensor through an Arduino UNO IO port.

Components used in this example
*As an Amazon & Ebay Associate I earn from qualifying purchases.
Component | Link |
Arduino UNO | https://amzn.to/3uYVAMC https://ebay.us/veZdKX |
Soil Moisture Sensor | https://amzn.to/3dqsAYp https://ebay.us/w4O3zI |
Amprobe AM-510 Multimeter | https://amzn.to/32mV4Mf https://ebay.us/uwo7sC |
Amprobe TL35B Test Leads with Alligator Clips | https://amzn.to/3dp5m4M https://ebay.us/OM4r4B |