Smart Irrigation System

by TechnoFrost in Circuits > Arduino

379 Views, 1 Favorites, 0 Comments

Smart Irrigation System

Screenshot 2021-12-10 222707.png

Drip irrigation, sprinkler irrigation, wells, tubewells etc etc. After my geography exam I was fed up with this. So I decided to make my own system which irrigates the plant based on humidity, moisture and temperature. Before building this project at home, I used Tinkercad to simulate the circuit from the comfort of my chair. Thanks to Tinkercad for making such a cool tool! Also here is the link to my project on Tinkercad Circuits

Supplies

Tinkercad circuits

Arduino Uno

Motor/pump

LCD display

2 x Resisters(1kΩ each)

Temperature Sensor(TMP36)

2 x Potentiometer

Making a New Circuit

Screenshot 2021-12-10 223632.png

Head over to Tinkercad circuits and click on the create new circuit option. Boom! That's it

Adding Components and Coding

Screenshot 2021-12-10 224040.png
Screenshot 2021-12-10 224103.png

Well here, from the right section, add the component you want, and connect it however you want. If you want, you can follow the diagram given by me or make your own wiring. After that head over to the code section and paste this

#include <LiquidCrystal.h>








//Define Pins to LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define _HumidityReaderPin A0
#define _EngineWritePin 7
#define _MinSensorValue A1
#define _MaxSensorValue A2
#define _IntervalHumidityRead A3


int _CurrentHumidityValue = 0; // Current Humidity Value
int _LastHumidityValue = 0;    // The humidity value on the last reading
int _IrrigationWorking = 0;    // Indicates if irrigation is working or not 0=Off, 1=On
unsigned int _StartIrrigationPercent = 0;
int _StopIrrigationPercent = 0;
int _OldStartIrrigationPercent = 0;
int _OldStopIrrigationPercent = 0;


char _RowOneContent;
char _RowTwoContent;
unsigned long _StartMillis;     //some global variables available anywhere in the program
unsigned long _CurrentMillis;


void IrrigationEngine(int _Status) 
{
  if (_Status == 0 ) {
    digitalWrite(_EngineWritePin,LOW);
    _IrrigationWorking = 0;
  } else {
    digitalWrite(_EngineWritePin,HIGH);
    _IrrigationWorking = 0;    
  }  
}


void setup() {
   
      Serial.begin(9600);           
      lcd.begin(16, 2);      
      lcd.setCursor(0,0);     
      _RowOneContent = 'WELCOME';
      _RowTwoContent = 'JUSTO ELC';     
      lcd.print("WELCOME");    
      lcd.setCursor(1,1);     
      lcd.print("Water go wee woo");
      pinMode(7, OUTPUT);
      IrrigationEngine(0);
      delay(2000);  
      _StartMillis = millis();  //initial start time
}


void loop() {
  
  _StartIrrigationPercent = int(float(analogRead(_MinSensorValue))*1/(1023)/0.01);
  if ( _StartIrrigationPercent != _OldStartIrrigationPercent ) {
       _OldStartIrrigationPercent = _StartIrrigationPercent;
       lcd.clear();
  	   lcd.setCursor(0,0);
       lcd.print("Low Set To");
       lcd.setCursor(1,1);
       lcd.print(_OldStartIrrigationPercent);  
       delay(2000);
       lcd.clear();
  	   lcd.setCursor(0,0);
       lcd.print("Humidity");
       lcd.setCursor(1,1);
       lcd.print(_CurrentHumidityValue);    
  }
  Serial.print(_StartIrrigationPercent);
  _StopIrrigationPercent = int(float(analogRead(_MaxSensorValue))*1/(1023)/0.01);
  
  if ( _StopIrrigationPercent != _OldStopIrrigationPercent ) {
       _OldStopIrrigationPercent = _StopIrrigationPercent;
       lcd.clear();
  	   lcd.setCursor(0,0);
       lcd.print("High Set To");
       lcd.setCursor(1,1);
       lcd.print(_OldStopIrrigationPercent);  
       delay(2000);
       lcd.clear();
  	   lcd.setCursor(0,0);
       lcd.print("Humidity");
       lcd.setCursor(1,1);
       lcd.print(_CurrentHumidityValue);    
  }
  _CurrentHumidityValue = int((float(analogRead(_HumidityReaderPin))*5/(1023))/0.01) - 49;
  if ( _LastHumidityValue != _CurrentHumidityValue ) {
      _LastHumidityValue = _CurrentHumidityValue;
      lcd.clear();
  	  lcd.setCursor(0,0);
      lcd.print("Humidity");
      lcd.setCursor(1,1);
      lcd.print(_CurrentHumidityValue);    
  }
  if ( _StartIrrigationPercent == 0 ) {
      IrrigationEngine(0);    
  } else {
    if ( _CurrentHumidityValue < _StartIrrigationPercent ) {
    	IrrigationEngine(1);
    } 
    if ( _CurrentHumidityValue > _StartIrrigationPercent  && _CurrentHumidityValue < _StopIrrigationPercent) {
    	IrrigationEngine(1);
    }
    if ( _CurrentHumidityValue > _StopIrrigationPercent ) {
      	IrrigationEngine(0);
    }
    
  }     
  delay(1000);


}

After this you should be good to go and ready to run your first simulation.

Running It

Now all you have to do is click the start simulation button, note the errors(There shouldn't be any if you have followed what I have done) and enjoy the output. Now we can work on making this into a real life project, which should be easy enough given that we made a digital replica