Intelligent Watering System With Arduino...





Introduction: 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...



    • Microcontroller Contest

      Microcontroller Contest
    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest

    We have a be nice policy.
    Please be positive and constructive.




    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");





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

    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!!!

    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

    Read my previous reply:

    "try to add #include <servo.h> at the beginning of sketch"

    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


    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.

    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....