Intelligent Watering System With Arduino...




In this instructable i wanted to share my automatic irrigation system using arduino, soil humidity sensor and a simple aquarium valve attached to a servo... Humidity sensor takes constant readings of the soil moisture and transfers to Arduino which controls a mini servo attached to a tiny valve. you can tell the system amount of moisture needed simply turning the potentiometer... then the system opens and closes the water valve if the soil is below your specified level of moisture... 
Parts needed:
- Soil humidity sensor   ( dealextreme $3)
- Arduino of any kind      (dealextreme $10)
- mini servo of any kind    ( 9gm ~$5)
- aquarium valve
- 10K potentiometer
- water pipe (thin aquarium type)

First dip the fork of the humidity sensor to soil completely... connect sensor to A0 and 10K pot to A1 pins of Arduino. connect servo to D9 pin. power up the system with anything you like... (Wall adapter or battery )... Upload the sketch to arduino, adjust the pot and there you go... you can adjust the level of watering needed anytime by the potentiometer... thats all... You can put the system in a small waterproof project box of any kind... you can make a battery operated handheld system and add a16x2 lcd display to show moisture and watering status... please dont hesitate to contact me for any help and don't forget to vote for me if you like it... :) My other projects are on my web site... 
Here is the program, copy and paste it to Arduino IDE and upload:

/*  Dincer Hepguler 2013
*  Read analog values from humidity sensor over the serial port
*  Command a servo controlled watering system

const int numReadings = 20;     //number of readings for smoothing

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
//int val = 0;                // the average

  Servo myservo;        //create servo object to control a servo
  int sensorPin = A0;    //humidity sensor at A0 (analog0)
  int pos = 90;         //variable to store servo position and set servo to center
  int thresholdPin = A1;  //threshold pot at A1
  int val = analogRead(sensorPin);
  int threshold = analogRead(thresholdPin);
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;

void loop() {
  // subtract the last reading:
  total= total - readings[index];        
  // read from the sensor: 
  readings[index] = analogRead(sensorPin);
  // add the reading to the total:
  total= total + readings[index];      
  // advance to the next position in the array: 
  index = index + 1;                   

  // if we're at the end of the array...
  if (index >= numReadings)             
    // ...wrap around to the beginning:
    index = 0; 
  int threshold = analogRead(thresholdPin);
  val = total / numReadings;             // calculate the average 
  if ( val > threshold)   { pos = 180; }   //open valve if dry
  else { pos = 60 ;}                         //keep valve closed otherwise
  myservo.write(pos);                 // sets the servo position according to the scaled value
  delay(15);           // waits for the servo to get there
  Serial.print(" ");
  Serial.print(" ");
  delay(10);       // delay in between reads for stability

NOTE: I couldn't manage to add include statement, it dissappears during copy and paste... so don't forget to add an #include servo library...



    • Classroom Science Contest

      Classroom Science Contest
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest
    • Sensors Contest

      Sensors Contest

    23 Discussions


    2 years ago

    in this the sms recicved code is doesnt working pls correct it


    #define PINNUMBER "8991725073481090680"

    GSM gsmAccess;

    GSM_SMS sms;

    LiquidCrystal lcd(0, 1, 8, 9, 10, 11);

    int sens2 = A0;

    #define sens1 13

    #define relay 24

    int a, value, cel, mv, val;

    char c[10]="ON";

    void setup()


    pinMode(sens1, OUTPUT);

    pinMode(sens2, OUTPUT);

    pinMode(relay, OUTPUT);

    lcd.begin(16, 2);





    lcd.setCursor(0, 1);


    lcd.print("WATER IRRIGATION");




    void loop()


    lcd.print("GSM INITIALISING");


    lcd.setCursor(0, 1);

    lcd.print("WAITING FOR MESSEGE");


    if (sms.available())


    lcd.print("MESSEGE RECIEVED");


    sms.remoteNumber(+918921063271, 20);

    if (c ==


    lcd.print("CHECKING THE DETAILS");


    value = analogRead(sens1);

    val = analogRead(sens2);

    float mv = ( (val * 500) / 1024);

    float cel = mv;

    lcd.setCursor(0, 0);

    lcd.print("MOISTURE = ");



    lcd.setCursor(0, 1);

    lcd.print("TEMPERATURE IN 0C = ");



    if ((value && val) == HIGH)


    digitalWrite(relay, HIGH);

    lcd.print("MOTOR ON");



    digitalWrite(relay, LOW);

    lcd.print("MOTOR OFF");






    3 years ago

    Hey I am making this project in my college can you please help me out more for details thankyou waiting for quick reply


    4 years ago on Introduction

    Hi, there. I am very interested in making DIY projects. I love yours but I have a little problem as I am a student of Class-12 I can't make just by reading small descriptions . I kindly request you to try to post a detailed plan. Can you help me out?

    Hoping for an early reply!!

    thank you for creating the sketch for a auto watering system! i have already ordered the parts from Ebay. i just finished copying the sketch and pasting it into my arduino IDE. i get back this "error compiling" message.

    Arduino: 1.6.3 (Mac OS X), Board: "Arduino Uno"

    auto_irrigation_sketch.ino:14:9: error: #include expects "FILENAME" or <FILENAME>

    auto_irrigation_sketch.ino:15:3: error: 'Servo' does not name a type

    auto_irrigation_sketch.ino: In function 'void setup()':

    auto_irrigation_sketch.ino:24:3: error: 'myservo' was not declared in this scope

    auto_irrigation_sketch.ino: In function 'void loop()':

    auto_irrigation_sketch.ino:49:3: error: 'myservo' was not declared in this scope

    Error compiling.

    This report would have more information with

    "Show verbose output during compilation"

    enabled in File > Preferences.

    I have only been playing with my arduino for less than a week. i am not a programer, I am more of a builder. PLEASE let me know if you have an updated version that I can copy and paste.


    THANK YOU!!!

    3 replies

    The errors you are getting is mostly because of your Arduino IDE version... Things have changed a lot with V 1.6.0... If you are not using DUE then I advice you to use version 1.0.6 which is very stable... Indeed the first error you get is because you did not include servo library... try to add #include <servo.h> at the beginning of sketch...

    i have included servo and downloaded version 1.0.6, and now I'm getting this error message.

    auto_irrigation_sketch.ino:16:9: error: #include expects "FILENAME" or

    hello sir!!!! v r doing automation of greenhouse using sensors... to automate irrigation v need an idea... since v ve built a small house v dont ve where to fit in d pipe... pls suggest some methods... my mail id


    4 years ago on Introduction

    hi Dinçer!

    May I ask for your help in advising how to adapt the code and connections for a set of, say, 10 simultaneous sensors? Each manages its own pump.

    I have plenty of flowers and would like to irrigate them all (on custom
    separate humidity level each) by a single Arduino board.

    The idea is to add also a photosensor to irrigate only when the Sun is down.

    1 reply

    Reply 4 years ago on Introduction

    It should not be a problem as long as you have enough pins on your microprocessor... a small Arduino will not be capable but an Arduino mega has plenty of pins and will definitely do the job... I also have many plants on my terrace garden and irrigate some of them with a simple timer... some in my small greenhouse and are irrigated by another controller... the smart irrigateion in my instructable is for selected special care plants... So you must group your plants for smart irrigation....


    im electrical engneering student.

    Im interested to do this project as my final project.

    please send me information, complete project detail and programming details.

    Akin Yildiz

    4 years ago on Introduction

    sir, you are a brilliant minded man..! this is the coolest watering system ever created. I have seen you personal webpage and you have an old project under your facebook account. it is a plant machine made of an old record player, that keeps the plant alive. I have just seen it and my mind exploded. you should definitely put that on here !


    but the reason why I'm reaching out to you is that I have a similar project that I am sure you will be very interested in personally. I see that you love plants so, check it out ! I am sure I will be messaging with you again soon enough, thank you for sharing your amazing skills !

    2 replies
    dhepgulerAkin Yildiz

    Reply 4 years ago on Introduction


    Thx for your kind words... I checked out your cool project too... Also sent you a comment on google+ too... cheers,


    5 years ago on Introduction

    I'm trying to establish this project, I wonder if I can replace the servo motor with a water pump, and how the program code will change? I need your help.

    Thank you!

    3 replies

    Reply 5 years ago on Introduction


    You can use a mini pump instead of servo. The advantage of the servo is to adjust the amount of water passing through the valve. however it is a bit noisy to keep the servo always on in both ways. Audible noise and EMI noise on the circuit... Indeed I used a pump in my implementation of this system on my plantoid robot, Mechaphytum Animus, which you can take a look at details on her page... There is an example code there too. While using a pump you must limit the amount of watering by keeping the pump on for some seconds... It is as easy as digitally keeping the pump pin high for a while...


    Reply 5 years ago on Introduction

    Thank you for your help! I wonder if you can give me the link of the valve, because i'm finding difficlties finding the appropriate valve.


    5 years ago on Introduction

    Interesting. I think I have that same sensor board and I found it gives a high when the humidity is high :-) which is too bad, coz if that was reverse, one could just use the sensor board to directly trigger a relay.

    I understand that you are using its analog out, which is sensible, but it makes the sensor board itself superfluous because one could hook up the sensor directly to the analog input of the Arduino as a voltage divider.

    I find your solution with the servo quite nifty

    1 reply

    Reply 5 years ago on Introduction

    Yes you are right... sensor drops from high to low when soil humidity drops below your set level... but I didnot have any issues using this sensor that way... You are also right about the fact that the reverse would be nice to drive a relay without the help of a microprocessor... the working of this sensor on my Plantoid robot can be seen on my site...