Using the Simple Soil Moisture Sensor with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller and running the provided example code.
You can connect to the sensor with alligator clips or the JST-SH port.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the sensor 3V.
Here is an Adafruit Metro wired up to the sensor using alligator clips with jumper wires:
- Board 5V to sensor 3V (red wire)
- Board GND to sensor GND (black wire)
- Board A0 to sensor OUT (white wire)
Here is an Adafruit Metro wired up using a 3-pin JST-SH cable:
- Board 5V to sensor JST-SH 3V (red wire)
- Board GND to sensor JST-SH GND (black wire)
- Board A0 to sensor JST-SH OUT (white wire)
There are no additional libraries needed for the example code.
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT
/* Simple Soil Sensor Demo */
int sensorPin = A0;
int moisture = 0;
void setup() {
Serial.begin(115200);
while ( !Serial ) delay(10);
}
void loop() {
// read the value from the sensor:
moisture = analogRead(sensorPin);
Serial.println(moisture);
delay(2000);
}
Upload the sketch to your board and open up the Serial Plotter (Tools -> Serial Plotter) at 115200 baud. You'll see Every five seconds, the analog reading from the sensor will be written to the plotter.
Advanced Sensing
One disadvantage to the soil sensor is that the soil probes can oxidize over time. There is a "hack" you can do to prolong the life of the probes. You can connect the sensor 3V pad to a digital pad on the Arduino-compatible microcontroller and turn it "on" only when you're getting an analog reading.
Advanced Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the sensor 3V.
Here is an Adafruit Metro wired up to the sensor using alligator clips with jumper wires:
- Board D2 to sensor 3V (red wire)
- Board GND to sensor GND (black wire)
- Board A0 to sensor OUT (white wire)
Here is an Adafruit Metro wired up using a 3-pin JST-SH cable:
- Board D2 to sensor JST-SH 3V (red wire)
- Board GND to sensor JST-SH GND (black wire)
- Board A0 to sensor JST-SH OUT (white wire)
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT
/* Advanced Soil Sensor Demo */
int sensorPin = A0;
int onPin = 2;
int moisture = 0;
void setup() {
Serial.begin(115200);
while ( !Serial ) delay(10);
pinMode(onPin, OUTPUT);
}
void loop() {
digitalWrite(onPin, HIGH);
delay(1000);
// read the value from the sensor:
moisture = analogRead(sensorPin);
Serial.println(moisture);
digitalWrite(onPin, LOW);
delay(1000);
}
Upload the sketch to your board and open up the Serial Plotter (Tools -> Serial Plotter) at 115200 baud. Every five seconds, pin 2 will be set HIGH to power up the sensor. Then, the analog reading from the sensor will be written to the plotter. After the reading, pin 2 is set LOW to turn off power to the sensor.
Page last edited July 14, 2025
Text editor powered by tinymce.