Soil Moisture Sensor
Auto Irrigation System
Build a smart watering system that reads soil moisture and automatically turns a pump on or off — your first step into real-world IoT automation.
What Are We Building?
This project automatically waters your plants based on how dry the soil is. A soil moisture sensor reads the water content and sends a value to the Arduino UNO. If the soil is too dry, the Arduino switches on a DC motor (water pump) and an LED indicator. Once the soil reaches the right moisture level, everything turns off — saving water and effort.
Efficient Water Use
Water only when the soil actually needs it — no guesswork.
Real Automation
Experience a complete sense-decide-act loop in a physical system.
Analog Sensing
Learn to read real-world analog values using analogRead().
Motor Control
Use digital output pins to switch a DC motor on and off safely.
What You Need
| # | Component | Qty | Role |
|---|---|---|---|
| 1 | Arduino UNO | ×1 | The brain — reads sensor & controls outputs |
| 2 | Soil Moisture Sensor | ×1 | Detects water content in soil (0–1023) |
| 3 | DC Motor (Water Pump) | ×1 | Pumps water when soil is dry |
| 4 | 1 kΩ Resistor | ×1 | Current limiter for the LED |
| 5 | LED | ×1 | Visual indicator — ON when pump is running |
| 6 | Breadboard | ×1 | Prototyping platform |
| 7 | Jumper Wires | ×~10 | Connections between components |
💡 Real hardware tip: When using an actual motor, always add a transistor (e.g. BC547) and a flyback diode (1N4007) to protect the Arduino from voltage spikes.
Wiring It All Together
🌿 Soil Moisture Sensor
⚙️ DC Motor (Water Pump)
💡 LED Indicator
The Logic Behind It
Sensor Reads Soil
Two metal probes are inserted into the soil. A small current passes between them — drier soil means higher resistance and a higher analog reading.
Arduino Reads the Value
The analogRead(A0) function reads a value from 0 to 1023. Lower values = wet soil. Higher values = dry soil.
Compare Against Threshold
The code checks the reading against a preset threshold (default: 500). Tune this after calibrating your sensor in actual soil.
Act on the Result
Repeat Every Second
A delay(1000) at the end of the loop means the sensor is checked once every second — continuously monitoring the soil.
The Program
Copy this into the Arduino IDE or paste directly in Tinkercad's code editor.
// ── Pin Definitions ─────────────────────────── int sensorPin = A0; // Soil moisture sensor output int motorPin = 8; // DC motor / water pump int ledPin = 9; // LED indicator // ── Variables ───────────────────────────────── int moistureValue; int threshold = 500; // Adjust after calibration void setup() { pinMode(motorPin, OUTPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); // Open Serial Monitor to see values } void loop() { moistureValue = analogRead(sensorPin); Serial.println(moistureValue); if (moistureValue < threshold) { // Soil is DRY → turn pump and LED ON digitalWrite(motorPin, HIGH); digitalWrite(ledPin, HIGH); } else { // Soil is WET → turn pump and LED OFF digitalWrite(motorPin, LOW); digitalWrite(ledPin, LOW); } delay(1000); // Check every 1 second }
Values vary by soil type and sensor model. Calibrate by testing bone-dry soil (note value) and fully wet soil (note value), then set threshold in between.
Simulate Before You Build
No components on hand? Use Tinkercad to run the full simulation in your browser — drag the moisture slider and watch the motor and LED respond in real time.
Open in Tinkercad Simulator
The complete circuit is already wired and code is pre-loaded. Hit Start Simulation, open the Serial Monitor, and move the moisture sensor slider to test your logic.
- Start the simulation and open the Serial Monitor to see live moisture values.
- Click the sensor and drag to a low value (dry) — watch the motor and LED turn ON.
- Drag to a high value (wet) — watch them turn OFF.
- Change the
thresholdfrom 500 to 300 in the code and observe the difference. - Challenge: Add a second LED on pin 10 that glows when soil is WET — modify the code!
Quick Quiz
Tap an option to check your answer instantly.
Q1. The soil moisture sensor output is connected to which Arduino pin?
Q2. What happens when the moisture reading is BELOW the threshold?
Q3. A sensor reading of 850 means the soil is...
Q4. Why is a 1 kΩ resistor used with the LED?
Where Can You Use This?
- Display the moisture value on a 16×2 LCD screen
- Add a buzzer alert when soil is critically dry
- Use an L293D motor driver to control a real pump safely
- Log data over time using the Serial Plotter
- Connect an ESP8266 Wi-Fi module to monitor remotely
Comments
Post a Comment