📚 Course contents

Projects Hub, build 64 of 81

Building a Smart Plant Watering System with Soil Moisture Sensor

intermediate7 min read

Smart plant watering systems equipped with soil moisture sensors are a boon for modern gardeners and plant enthusiasts. These systems enable automated and efficient watering, ensuring that plants receive the right amount of moisture for optimal growth. In this article, we'll explore how to create a smart plant watering system using a soil moisture sensor and Arduino.

Introduction

Water is a critical element for the growth and health of plants. However, over-watering or under-watering can be detrimental to plants. A smart plant watering system helps in maintaining the appropriate moisture level in the soil by automating the watering process based on real-time data from a soil moisture sensor. This ensures that plants receive the right amount of water, promoting healthy growth.

Working Principle

The working principle of the smart plant watering system involves monitoring the moisture level in the soil using a soil moisture sensor. When the moisture level falls below a certain threshold, the system triggers a water pump to irrigate the plants until the desired moisture level is reached.

Things We Need

To build this system, you'll need the following components:

  1. Arduino board (e.g., Arduino Uno)
  2. Soil moisture sensor
  3. Water pump
  4. Transistor (e.g., NPN transistor like 2N3904)
  5. Diode
  6. Resistor
  7. Connecting wires
  8. Power supply
  9. Breadboard

Circuit Diagram

To assemble the smart plant watering system, follow this circuit diagram:

                        Soil Moisture Sensor
                               |
    +--------------------------+-------------------------+
    |                                                      |
    |                                                      |
   +++                                                     |
   | |                                                     |
   | |                                                     |
   | |                    +---------+                     |
   | |                    |         |                     |
   | |                    |   NPN   |    Diode            |
   | |                    | Trans.  |----|>|---|---o  Water Pump
   | |                    |         |    |               |
   | |                    |         |    |               |
   | |                    +---------+    |               |
   | |                                   |               |
   | |                                   |               |
   | |                                   |               |
   | |                                   |               |
   | |                                  +++              |
   | |                                  | |              |
   | |                                  | |              |
   | |                                  | |              |
   | |                                  | |              |
   | |                                 ++++              |
   | |                                 | |               |
   | |                                 | |               |
   | |                                 | |               |
   | |                                 | |               |
   | |                                ++++               |
   | |                                | |                |
   | |                                | |                |
   | |                                | |                |
   | |                                | |                |
   | |                               ++++                |
   | |                               | |                 |
   | |                               | |                 |
   | |                               | |                 |
   | |                               | |                 |
   | |                              ++++                 |
   | |                              | |                  |
   | |                              | |                  |
   | |                              | |                  |
   | |                              | |                  |
   | |                             ++++                  |
   | |                             | |                   |
   | |                             | |                   |
   | |                             | |                   |
   | |                             | |                   |
   | |                            ++++                   |
   | |                            | |                    |
   | |                            | |                    |
   | |                            | |                    |
   | |                            | |                    |
   | |                           ++++                    |
   | |                           | |                     |
   | |                           | |                     |
   | |                           | |                     |
   | |                           | |                     |
   | |                          ++++                     |
   | |                          | |                      |
   | |                          | |                      |
   | |                          | |                      |
   | |                          | |                      |
   | |                         ++++                      |
   | |                         | |                       |
   | |                         | |                       |
   | |                         | |                       |
   | |                         | |                       |
   | |                        ++++                       |
   | |                        | |                        |
   | |                        | |                        |
   | |                        | |                        |
   | |                        | |                        |
   | |                       ++++                        |
   | |                       | |                         |
   | |                       | |                         |
   | |                       | |                         |
   | |                       | |                         |
   | |                      ++++                         |
   | |                      | |                          |
   | |                      | |                          |
   | |                      | |                          |
   | |                      | |                          |
   | |                     ++++                          |
   | |                     | |                           |
   | |                     | |                           |
   | |                     | |                           |
   | |                     | |                           |
   | |                    ++++                           |
   | |                    | |                            |
   | |                    | |                            |
   | |                    | |                            |
   | |                    | |                            |
   | |                   ++++                            |
   | |                   | |                             |
   | |                   | |                             |
   | |                   | |                             |
   | |                   | |                             |
   | |                  ++++                             |
   | |                  | |                              |
   | |                  | |                              |
   | |                  | |                              |
   | |                  | |                              |
   | |                 ++++                              |
   | |                 | |                               |
   | |                 | |                               |
   | |                 | |                               |
   | |                 | |                               |
   | |                ++++                               |
   | |                | |                                |
   | |                | |                                |
   | |                | |                                |
   | |                | |                                |
   | |               ++++                                |
   | |               | |                                 |
   | |               | |                                 |
   | |               | |                                 |
   | |               | |                                 |
   | |              ++++                                 |
   | |              | |                                  |
   | |              | |                                  |
   | |              | |                                  |
   | |              | |                                  |
   | |             ++++                                  |
   | |             | |                                   |
   | |             | |                                   |
   | |             | |                                   |
   | |             | |                                   |
   | |            ++++                                   |
   | |            | |                                    |
   | |            | |                                    |
   | |            | |                                    |
   | |            | |                                    |
   | |           ++++                                    |
   | |           | |                                     |
   | |           | |                                     |
   | |           | |                                     |
   | |           | |                                     |
   | |          ++++                                     |
   | |          | |                                      |
   | |          | |                                      |
   | |          | |                                      |
   | |          | |                                      |
   | |         ++++                                      |
   | |         | |                                       |
   | |         | |                                       |
   | |         | |                                       |
   | |         | |                                       |
   | |        ++++                                       |
   | |        | |                                        |
   | |        | |                                        |
   | |        | |                                        |
 
   | |        | |                                        |
   | |       ++++                                        |
   | |       | |                                         |
   | |       | |                                         |
   | |       | |                                         |
   | |       | |                                         |
   | |      ++++                                         |
   | |      | |                                          |
   | |      | |                                          |
   | |      | |                                          |
   | |      | |                                          |
   | |     ++++                                          |
   | |     | |                                           |
   | |     | |                                           |
   | |     | |                                           |
   | |     | |                                           |
   | |    ++++                                           |
   | |    | |                                            |
   | |    | |                                            |
   | |    | |                                            |
   | |    | |                                            |
   | |   ++++                                            |
   | |   | |                                             |
   | |   | |                                             |
   | |   | |                                             |
   | |   | |                                             |
   | |  ++++                                             |
   | |  | |                                              |
   | |  | |                                              |
   | |  | |                                              |
   | |  | |                                              |
   | | ++++                                              |
   | | | |                                               |
   | | | |                                               |
   | | | |                                               |
   | | | |                                               |
   | ++++                                               |
   |  | |                                                |
   |  | |                                                |
   |  | |                                                |
   |  | |                                                |
   ++++                                                ++++
    | |                                                | |
     |                                                  |
     |                                                  |
     +--------------------------------------------------+
                    GND (Arduino)                  VCC (Arduino)

This circuit connects the soil moisture sensor to the Arduino board, with the soil moisture sensor's analog output connected to one of the analog pins on the Arduino.

Working of the System with Arduino

The smart plant watering system operates in the following steps:

  1. The soil moisture sensor continuously measures the moisture level in the soil.
  2. The Arduino reads the sensor data through one of its analog pins.
  3. The Arduino compares the sensor reading to a threshold. A reading above the threshold means the soil is too dry (the sensor gives a higher number for drier soil).
  4. When the soil is too dry, the Arduino activates the water pump to deliver water to the plants.
  5. The pump continues to operate until the soil moisture level reaches the desired level.
  6. Once the desired moisture level is achieved, the Arduino turns off the water pump.

This process ensures that the soil moisture is consistently maintained at the desired level, preventing both over-watering and under-watering.

Loading the circuit…Arduino Uno
Press Run to upload the code to the Arduino.

Arduino Code

Here's a simple Arduino code snippet to make the system work:

const int sensorPin = A0;   // Analog input pin for the sensor
const int pumpPin = 7;      // Digital output pin for the water pump
const int moistureThreshold = 400;  // Set your desired threshold
 
void setup() {
  pinMode(pumpPin, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {
  int moistureLevel = analogRead(sensorPin);
 
  Serial.print("Moisture Level: ");
  Serial.println(moistureLevel);
 
  if (moistureLevel > moistureThreshold) {  // a higher number means drier soil
    digitalWrite(pumpPin, HIGH);  // Turn on the water pump
  } else {
    digitalWrite(pumpPin, LOW);   // Turn off the water pump
  }
 
  delay(1000);  // Adjust the delay as needed
}

Check your sensor first: with the common soil moisture sensors (the two-pronged probe with a small blue board, and the black capacitive one), the number goes up as the soil gets drier. In dry air it is near the top (1023 on an Arduino Uno), and in wet soil it is much lower. That is why the pump turns on when the reading is above the threshold. Print the reading with Serial.println(), note it with the probe in dry soil and in just-watered soil, and set the threshold between the two. If your sensor gives a higher number for wet soil, change > back to <.

Conclusion

A smart plant watering system with a soil moisture sensor and Arduino provides an efficient and automated way to ensure your plants receive the right amount of water. It not only conserves water but also promotes healthy plant growth. With the right components and code, you can set up a system that takes care of your plants, making gardening easier and more enjoyable. So, go ahead and build your own smart plant watering system and watch your garden thrive.