Components Required
- Arduino Uno (or any other compatible board)
- Soil moisture sensor (capacitive is recommended over resistive for durability)
- I2C LCD module (16×2)
- Breadboard and jumper wires
- Power source (USB or 9V battery with adapter)
- Different soil samples (e.g., clay, loam, sandy soil)
Wiring Connections
Soil Moisture Sensor:
- VCC → 5V on Arduino
- GND → GND on Arduino
- A0 → A0 on Arduino (Analog input)
I2C LCD Module:
- VCC → 5V on Arduino
- GND → GND on Arduino
- SDA → A4 on Arduino
- SCL → A5 on Arduino
For Arduino Mega: SDA = Pin 20, SCL = Pin 21
Ensure your I2C LCD uses the0x27
or0x3F
I2C address (you can scan with I2C scanner sketch if needed)
Arduino Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Use the correct I2C address: 0x27 or 0x3F
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int soilPin = A0;
void setup() {
lcd.init(); // Correct for libraries using lcd.init()
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Soil Moisture");
delay(2000);
}
void loop() {
int moistureValue = analogRead(soilPin);
// Adjust these values based on your sensor calibration
int dryValue = 1023; // Value when sensor is dry
int wetValue = 300; // Value when sensor is in water
int moisturePercent = map(moistureValue, dryValue, wetValue, 0, 100);
moisturePercent = constrain(moisturePercent, 0, 100); // Ensure within bounds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Moisture:");
lcd.setCursor(0, 1);
lcd.print(moisturePercent);
lcd.print(" %");
delay(2000);
}
Top 3 Enhancements for Better Accuracy
- Use a Capacitive Soil Moisture Sensor
- More accurate and less prone to corrosion than resistive sensors.
- Calibrate Your Sensor Properly
- Measure values in dry soil, moist soil, and wet soil to improve reading accuracy.
- Take Multiple Readings and Average Them
- Smooth out noise by averaging several sensor readings before displaying.