DIY Soil Moisture Monitoring Project with Arduino

Fahiz
4 min readSep 30, 2024

--

Monitoring soil moisture content is crucial for maintaining healthy plants, especially if you’re trying to optimize water usage for a garden or a potted plant setup. With Arduino, you can easily build a DIY project to check soil moisture levels and automate your watering system. In this tutorial, we’ll walk through how to set up a simple soil moisture monitoring system using an Arduino board and a few inexpensive components.

What You’ll Learn

  • How to use an Arduino to measure soil moisture
  • How to display moisture readings on an LCD
  • How to automate plant watering based on soil moisture levels

Materials Required

Here’s what you need for this project:

  1. Arduino Uno — You can also use other Arduino boards, but the Uno is beginner-friendly.
  2. Soil Moisture Sensor — This sensor will detect moisture levels in the soil.
  3. 16x2 LCD Display — To visually display the moisture level readings.
  4. Breadboard and Jumper Wires — For connecting components.
  5. Potentiometer (10K Ohms) — For adjusting the contrast of the LCD.
  6. 5V Water Pump (optional) — If you want to automate watering.
  7. Relay Module (optional) — To control the water pump.

Step 1: Wiring the Components

Connecting the Soil Moisture Sensor

The soil moisture sensor has two parts: the probes that go into the soil, and the sensor module that connects to the Arduino. The wiring for the soil moisture sensor is straightforward:

  • VCC → 5V pin on the Arduino
  • GND → GND pin on the Arduino
  • A0 (Analog Out) → A0 pin on the Arduino (for moisture data)

Connecting the LCD Display

The LCD requires several pins to display information. Connect the 16x2 LCD screen to the Arduino as follows:

  • VSS → GND
  • VDD → 5V
  • V0 (Contrast Control) → Potentiometer middle pin
  • RS → Pin 12 on Arduino
  • RW → GND
  • E → Pin 11 on Arduino
  • D4, D5, D6, D7 → Pins 5, 4, 3, 2 on Arduino
  • A (Backlight Anode) → 5V
  • K (Backlight Cathode) → GND

Optional: Connecting the Relay and Water Pump

To automate the watering process, connect the relay to the Arduino:

  • VCC → 5V
  • GND → GND
  • Signal → Pin 8 on Arduino

The relay will control the 5V water pump, which will be powered by an external power source.

Step 2: Uploading the Code

Now that the components are connected, we can upload the code to the Arduino. Below is a simple sketch that reads soil moisture data and displays it on the LCD:

#include <LiquidCrystal.h>

// Initialize the library with the LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Set up the sensor pin
const int sensorPin = A0;
int sensorValue = 0;
int moisturePercent = 0;

void setup() {
lcd.begin(16, 2); // Set up the LCD's columns and rows
lcd.print("Soil Moisture:"); // Print a message to the LCD
pinMode(sensorPin, INPUT);
}

void loop() {
// Read the moisture level from the sensor
sensorValue = analogRead(sensorPin);

// Convert the sensor value to a percentage
moisturePercent = map(sensorValue, 0, 1023, 0, 100);

// Clear the second row and print the moisture percentage
lcd.setCursor(0, 1);
lcd.print(moisturePercent);
lcd.print("%");

// Delay for a second before the next reading
delay(1000);
}

Explanation:

  • analogRead(sensorPin): This reads the value from the soil moisture sensor.
  • map(): This function maps the sensor value (which ranges from 0 to 1023) to a percentage (0% to 100%).
  • lcd.print(): This displays the data on the 16x2 LCD.

Step 3: Automating Watering (Optional)

If you want to automate the watering process, you can modify the code to activate the water pump when the soil moisture drops below a certain threshold. Here’s an example of how to do it:

const int relayPin = 8;  // Pin to control the relay
const int moistureThreshold = 30; // Minimum acceptable moisture level (30%)

void setup() {
lcd.begin(16, 2);
lcd.print("Soil Moisture:");
pinMode(sensorPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Start with the water pump off
}

void loop() {
sensorValue = analogRead(sensorPin);
moisturePercent = map(sensorValue, 0, 1023, 0, 100);

lcd.setCursor(0, 1);
lcd.print(moisturePercent);
lcd.print("%");

// Check if the soil moisture is below the threshold
if (moisturePercent < moistureThreshold) {
digitalWrite(relayPin, LOW); // Turn on the water pump
} else {
digitalWrite(relayPin, HIGH); // Turn off the water pump
}

delay(1000);
}

In this code, we added a check for the moisture level. If it drops below 30%, the water pump will be activated by the relay.

Step 4: Testing and Adjustments

Before putting the sensor in real soil, test the system with some water and dry soil to ensure that the sensor is correctly reading moisture levels. Adjust the moisture threshold as needed based on the specific requirements of your plants.

Conclusion

You can create a simple yet effective soil moisture monitoring system using Arduino with just a few components. This project helps you better care for your plants and introduces you to the world of electronics and programming. As a bonus, you can expand this project by connecting it to the Internet for remote monitoring or by adding more sensors for a complete garden automation system.

Happy building!

--

--

Fahiz
Fahiz

No responses yet