Soil Moisture Sensor for Arduino
Use Arduino UNO to measure soil moisture and display readings on an LCD, so you always know when your plants need water.
- Arduino
- Beginner
- 30–45 minutes
- 4 steps
Shop this project
CartYou'll need
Prices from vilros.com. Tax and shipping at checkout.
Before you start, you'll need
- Arduino Uno
- Soil moisture sensor (with screw terminals)
- 16×2 LCD display (I2C interface recommended)
- Breadboard
- Jumper wires
Connect the moisture sensor
About 5 minutes
Wire the moisture sensor to Arduino.
- Connect the moisture sensor's GND pin to Arduino GND.
- Connect the moisture sensor's VCC pin to Arduino 5V.
- Connect the moisture sensor's SIG (signal) pin to Arduino analog pin A3.
You should see
All three sensor wires are connected to the Arduino.
Connect the LCD display
About 5 minutes
Wire the LCD to Arduino.
- Connect the LCD GND pin to Arduino GND.
- Connect the LCD VCC pin to Arduino 5V.
- Connect the LCD SDA pin to Arduino A4.
- Connect the LCD SCL pin to Arduino A5.
You should see
All four LCD wires are connected. The LCD should power on (backlight visible).
Upload the sketch
About 15 minutes
Program the Arduino to read moisture and display it.
- Open Arduino IDE and create a new sketch.
- Copy the complete sketch below into your IDE.
- If you're using a different LCD library or pin configuration, adjust the LiquidCrystal initialization line.
- Connect your Arduino via USB.
- Under Tools, select Arduino Uno as the board and the correct port.
- Click Upload.
#include <LiquidCrystal.h>
// Initialize LCD with pins (RS, E)
LiquidCrystal lcd(5, 4);
const int analogInPin = A3;
int sensorValue = 0;
void setup() {
lcd.begin(16, 2);
delay(100);
}
void loop() {
lcd.clear();
lcd.print("Soil Moisture:");
sensorValue = analogRead(analogInPin);
lcd.setCursor(0, 1);
lcd.print(sensorValue);
delay(300);
}This sketch uses a simple 2-wire LCD initialization. If you have a standard 16-pin LCD (not I2C), you'll need to adjust the wiring and initialization.
You should see
The sketch uploads without errors. The LCD displays 'Soil Moisture:' on the first line and a number on the second line.
It didn't work
LCD shows garbled text or no text.
Check the LCD wiring (GND, VCC, SDA, SCL). If using a standard 16-pin LCD instead of I2C, you need different initialization and more wiring. Adjust the contrast potentiometer on the LCD if available.
Moisture reading doesn't change.
Verify the sensor's signal wire is connected to A3. Test the sensor by putting the probes in water (reading should increase) or in dry soil (reading should decrease).
Test with soil and water
About 10 minutes
Verify the sensor responds to moisture changes.
- Insert the moisture sensor probes into dry soil and note the reading on the LCD.
- Water the soil and watch the reading increase.
- Remove the sensor and dry it, then test in a glass of water for the maximum reading.
- Use these readings to determine your plant's ideal moisture range.
You should see
The LCD reading increases when the sensor is in wet soil or water, and decreases in dry soil.
It didn't work
Reading stays at 0 or doesn't change.
The sensor may be faulty or the probes aren't making good contact. Clean the probes and ensure they're fully inserted into the soil. Check the wiring to A3.
What to do next
- Arduino Blinds ControlBuild another Arduino sensor project with a servo motor.
- More Arduino projectsExplore beginner and intermediate Arduino builds.
Stuck? Contact Vilros Support with your board model and what you see on screen.