Automatic Plant Watering System with Arduino

In this tutorial, we will learn how to create an automatic plant watering system using an Arduino.

What you will need

  • Arduino board
  • Soil moisture sensor
  • Water pump
  • Relay module
  • Jumper wires
  • Water container or reservoir

Circuit setup

Connect the soil moisture sensor and water pump to the Arduino using jumper wires. Use the relay module to control the water pump.


// Define pin numbers
                const int soilMoisturePin = A0; // Analog pin for moisture sensor
                const int relayPin = 4; // Digital pin for relay module
                const int moistureThreshold = 500; // Adjust this value based on your sensor readings

                void setup() {
                    pinMode(relayPin, OUTPUT); // Set relay pin as output

                void loop() {
                    int soilMoistureValue = analogRead(soilMoisturePin); // Read soil moisture value

                    if (soilMoistureValue < moistureThreshold) {
                        digitalWrite(relayPin, HIGH); // Turn on water pump
                        delay(5000); // Water for 5 seconds
                        digitalWrite(relayPin, LOW); // Turn off water pump

                    delay(1000); // Wait for 1 second before taking the next reading


We start by defining the pin numbers for our components, including the soil moisture sensor pin, relay module pin, and moisture threshold value. In the setup function, we set the relay pin as an output. The loop function continuously reads the soil moisture value using the analogRead function. If the soil moisture value is below the threshold, the relay pin is set to HIGH to turn on the water pump for 5 seconds. After that, it is set to LOW to turn off the water pump. This process is repeated every second.


With this simple Arduino project, you can automate the watering of your plants based on their moisture levels. This ensures they receive the right amount of water, preventing under or overwatering. Happy gardening!

Leave a Reply

Your email address will not be published. Required fields are marked *