Green Robot Machinery
Published © LGPL

Smart Irrigation

Continuously monitors the soil moisture level and based on the reading turns ON/OFF the submersible pump to maintain the water level.

BeginnerWork in progress3,907
Smart Irrigation

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
Motor Driver
×1
Soil Moisture Sensor
×1
Water pump
Submersible Pump
×1

Story

Read more

Schematics

Wiring Diagram

Code

Smart Irrigation Code

C/C++
/*      
 * SMART IRRIGATION
 * 
 * SPARK CORE based soil moisture monitoring and irrigation
 * 
 * Version 1.1 May, 2015
 * 
 */

const int motor =0;  // motor connection pin D0
int rangemax = 3976;     // Default maximum range
int rangemin = 3600;    // Default minimum range
int val;
int motorDelay = 1000; //Default motor delay
char publishstr[30]; 
int motormon = 0;        //motor activation variable

void setup()
{
  pinMode(motor,OUTPUT); //make motor drive pin as output
  pinMode(A0,INPUT);     //make A0 input to read the moisture data
  Serial.begin(9600);     
  Spark.variable("moisture", &val, INT);  //expose the moisture data variable
  Spark.function("motordrive", motordrive); //expose the motor drive function
  Spark.function("motorlDelay", setmotorlDelay); // set delay for motors over the internet
  Spark.function("MinRange", setMinRange); // set min range for moisture data over the internet
  Spark.function("MaxRange", setMaxRange); //set max range for the moisture data over the internet
}


void loop()
{

  val= getmoist();   //get moisture data
  Serial.println("moisture reading = ");
  Serial.println(val);
  delay(2000);
  while(!motormon)
  {
    if(val<rangemax  &&  val> rangemin)
     {   
       sprintf(publishstr,"%d",val);
       Spark.publish("moisturereading", publishstr);
       // motordrive("ON");  //turn on the motor
       digitalWrite(motor, HIGH); //turn on the motor
       delay(motorDelay);
       digitalWrite(motor,LOW);
       delay(motorDelay);
      }
  }
}
 
 /*function to turn on the motor*/
int motordrive(String cmd)
 {
     if(cmd=="ON")
     {
      digitalWrite(motor,HIGH); //turn on the motor
      delay(motorDelay);
      digitalWrite(motor,LOW);
      delay(motorDelay);
     }
     else if(cmd=="OFF") 
     {
     digitalWrite(motor,LOW); //turn off
      delay(motorDelay);
     }
     else if(cmd=="monoff")
     {
         motormon=1;  //deactivate motors
     }
     
    
     return 0;
 }
 
 /*Moisture reading from sensor*/
 int getmoist()
   {
    int sensorval=analogRead(A0);
    //int sensorval = sensor*3.3/1024;
    return(sensorval);
   }
   
   
   
 /*set delay function*/  
 int setmotorlDelay(String strmotorDelay)
  {
   motorDelay = strmotorDelay.toInt();
   return motorDelay;
  }



/*set min range over the internet*/
int  setMinRange(String strDistance)
{
   rangemax = strDistance.toInt();
   return rangemax;
}


/*set max range over the internet*/
int  setMaxRange(String strDistance)
{
   rangemin = strDistance.toInt();
   return rangemin;
}

Credits

Green Robot Machinery

Green Robot Machinery

7 projects • 41 followers
Green Robot Machinery Private Limited

Comments