Skip to content

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

Cart

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.

  1. Connect the moisture sensor's GND pin to Arduino GND.
  2. Connect the moisture sensor's VCC pin to Arduino 5V.
  3. 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.

  1. Connect the LCD GND pin to Arduino GND.
  2. Connect the LCD VCC pin to Arduino 5V.
  3. Connect the LCD SDA pin to Arduino A4.
  4. 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.

  1. Open Arduino IDE and create a new sketch.
  2. Copy the complete sketch below into your IDE.
  3. If you're using a different LCD library or pin configuration, adjust the LiquidCrystal initialization line.
  4. Connect your Arduino via USB.
  5. Under Tools, select Arduino Uno as the board and the correct port.
  6. Click Upload.
cpp
#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.

  1. Insert the moisture sensor probes into dry soil and note the reading on the LCD.
  2. Water the soil and watch the reading increase.
  3. Remove the sensor and dry it, then test in a glass of water for the maximum reading.
  4. 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

Stuck? Contact Vilros Support with your board model and what you see on screen.