Irrigation System

An Automated Irrigation system that monitors moisture, water flow and water level.

IntermediateFull instructions provided6 hours347
Irrigation System

Things used in this project

Hardware components

JSN SR-04T Waterproof Ultrasonic Sensor
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
arduino Maker UNO: Simplifying Arduino for {Education} Maker UNO: Simplifying Arduino for {Education} Maker UNO: Simplifying Arduino for {Education} Maker UNO: Simplifying Arduino for {Education} Maker UNO: Simplifying Arduino for {Education}
×1
Light Pipe, 9.5 mm
Light Pipe, 9.5 mm
×1
G1/2" Half Effect Water Flow Sensor - YF-S201
×2
3M 2090 Blue Tape 48mmx55M 3M 2090 Blue Tape 48mmx55M 3M 2090 Blue Tape 48mmx55M
×1
4-CHANNEL RELAY CONTROLLER FOR I2C
ControlEverything.com 4-CHANNEL RELAY CONTROLLER FOR I2C
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Micro Submersible Water Pump DC 3V-5V
×1
4xAA battery holder
4xAA battery holder
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
HC-06 Bluetooth Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Moisture Level

Water Level

Water Leakage Detector

Water Quality Monitoring

Code

Moisture level

Arduino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

int motorPin = 3; // pin that turns on the motor
int blinkPin = 13; // pin that turns on the LED
int watertime = 5; // how long it will be watering (in seconds)
int waittime = 1; // how long to wait between watering (in minutes)

void setup()
{
  pinMode(motorPin, OUTPUT); // set Pin 3 to an output
  pinMode(blinkPin, OUTPUT); // set pin 13 to an output
  Serial.begin(9600);

  //initialise lcd
  lcd.init();
  lcd.backlight();
  //Print stagnant message to LCD
  lcd.print("Water moisture level: ");
}

void loop()
{
  int moisturePin = analogRead(A0); //read analog value of moisture sensor
  int moisture = ( 100 - ( (moisturePin / 1023.00) * 100 ) ); //convert analog value to percentage
  Serial.println(moisture);
  lcd.setCursor(0, 1);
  lcd.println(moisture);
  if (moisture < 40) { //change the moisture threshold level based on your calibration values
    digitalWrite(motorPin, HIGH); // turn on the motor
    digitalWrite(blinkPin, HIGH); // turn on the LED
    delay(watertime * 1000);      // multiply by 1000 to translate seconds to milliseconds
  }
  else {
    digitalWrite(motorPin, LOW);  // turn off the motor
    digitalWrite(blinkPin, LOW);  // turn off the LED
    delay(waittime * 60000);      // multiply by 60000 to translate minutes to milliseconds
  }

}

Water Level

Arduino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

#define ECHOPIN 3
#define TRIGPIN 2

void setup() {
  Serial.begin(9600);
  //initialise lcd
  lcd.init();
  lcd.backlight();
  //Print stagnant message to LCD
  lcd.print("Water Level: ");
  pinMode(ECHOPIN, INPUT_PULLUP);
  pinMode(TRIGPIN, OUTPUT);
  digitalWrite(ECHOPIN, HIGH);
}

void loop() {

  lcd.clear();
  digitalWrite(TRIGPIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);
  delayMicroseconds(15);
  digitalWrite(TRIGPIN, LOW);
  int distance1 = pulseIn(ECHOPIN, HIGH, 26000);
  int distance = distance1 / 58;
  Serial.print(distance);
  Serial.println("   cm");
  lcd.setCursor(0, 1);       //sets the cursor at row 0 column 0
  lcd.print("Water Level");  // prints 16x2 LCD MODULE
  lcd.setCursor(0, 1);
  lcd.print(distance);
  delay(500);
}

Water Leakage Detector

Arduino
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

byte statusLed = 13;
int led = 7;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin = 2;
byte sensorInterrupt1 = 1;  // 1 = digital pin 3
byte sensorPin1 = 3;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;

volatile byte pulseCount;
volatile byte pulseCount1;

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
float flowRate1;
unsigned int flowMilliLitres1;
unsigned long totalMilliLitres1;
float difference;

unsigned long oldTime;
unsigned long oldTime1;

void setup() {

  // Initialize a serial connection for reporting values to the host
  Serial.begin(9600);

  //initialise lcd
  lcd.init();
  lcd.backlight();

  //Print stagnant message to LCD
  lcd.print("Water flow rate: ");

  // Set up the status LED line as an output
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, HIGH);  // We have an active-low LED attached
  pinMode(led, OUTPUT);
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pinMode(sensorPin1, INPUT);
  digitalWrite(sensorPin1, HIGH);

  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  oldTime = 0;
  pulseCount1 = 0;
  flowRate1 = 0.0;
  flowMilliLitres1 = 0;
  totalMilliLitres1 = 0;
  oldTime1 = 0;
  difference = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
}

/**
 * Main program loop
 */
void loop() {

  delay(100);

  if ((millis() - oldTime) > 1000)  // Only process counters once per second
  {
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensorInterrupt);
    detachInterrupt(sensorInterrupt1);

    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    flowRate1 = ((1000.0 / (millis() - oldTime)) * pulseCount1) / calibrationFactor;
    difference = flowRate - flowRate1;
    if (difference > 2) {
      digitalWrite(led, HIGH);  // turn the LED on (HIGH is the voltage level)
      delay(1000);              // wait for a second
      digitalWrite(led, LOW);
    }

    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();

    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;

    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;

    unsigned int frac;

    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate: ");
    Serial.print(int(flowRate));  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\t");  // Print tab space
    Serial.print("Flow rate: ");
    Serial.print(int(flowRate1));  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\n");
    Serial.print("Difference: ");
    Serial.print(int(difference));  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\n");
    //Set cursor of LCD to next row
    lcd.setCursor(0, 1);
    lcd.println(int(difference));

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    pulseCount1 = 0;

    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
    attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
  }
}

/*
Insterrupt Service Routine
 */
void pulseCounter() {
  // Increment the pulse counter
  pulseCount++;
}
void pulseCounter1() {
  // Increment the pulse counter
  pulseCount1++;
}

Water Quality Monitoring

Arduino
//include libraries
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

//for  bluetooth - create an object called BTserial, with RX pin at 3 and TX pin at 2
SoftwareSerial BTserial(0, 1);  // RX | TX

//decraration of all our variables

float reads;
int pin = A0;

float vOut = 0;  //voltage drop across 2 points
float vIn = 5;
float R1 = 1000;
float R2 = 0;
float buffer = 0;
float TDS;

float R = 0;          //resistance between the 2 wires
float r = 0;          //resistivity
float L = 0.06;       //distance between the wires in m
double A = 0.000154;  //area of cross  section of wire in m^2

float C = 0;   //conductivity in S/m
float Cm = 0;  //conductivity  in mS/cm

int rPin = 9;
int bPin = 5;
int gPin = 6;
int rVal = 255;
int bVal = 255;
int gVal = 255;

//we will use this formula to get the resistivity  after using ohm's law -> R = r L/A => r = R A/L



void setup() {
  //initialise BT serial and   serial monitor
  Serial.begin(9600);
  BTserial.begin(9600);

  //initialise lcd
  lcd.init();
  lcd.backlight();

  //set rgb led pins (all to be pwm pins on Arduino) as output
  pinMode(rPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(pin, INPUT);
  //Print stagnant message to LCD
  lcd.print("Conductivity: ");
}

void loop() {
  reads = analogRead(A0);

  vOut = reads * 5 / 1023;
  Serial.println(reads);
  //  Serial.println(vOut);
  buffer = (vIn / vOut) - 1;
  R2 = R1 * buffer;
  Serial.println(R2);
  delay(500);
  //convert voltage to resistance
  //Apply formula mentioned  above
  r = R2 * A / L;  //R=rL/A
  //convert resistivity to condictivity
  C = 1 / r;
  Cm = C * 10;
  //convert conductivity in mS/cm to TDS
  TDS = Cm * 700;
  //Set cursor of LCD to next row
  lcd.setCursor(0, 1);
  lcd.println(C);

  //display corresponding colours on rgb led according  to the analog read
  if (reads < 600) {
    if (reads <= 300) {
      setColor(255, 0, 255);
    }
    if (reads > 200) {
      setColor(200, 0, 255);
    }
  } else {
    if (reads <= 900) {
      setColor(0, 0, 255);
    }
    if (reads > 700) {
      setColor(0, 255, 255);
    }
  }

  //send data to Ardutooth app on mobile phone  through bluetooth
  BTserial.print(C);
  BTserial.print(",");
  BTserial.print(TDS);
  BTserial.print(";");
  delay(500);
}


void setColor(int red, int green, int blue) {
  analogWrite(rPin, 255 - red);
  analogWrite(gPin, 255 - green);
  analogWrite(bPin, 255 - blue);
}

Credits

Adeel khan

Adeel khan

1 project • 2 followers
amer esam

amer esam

1 project • 1 follower
Nabiha Tasfia (062046)

Nabiha Tasfia (062046)

1 project • 0 followers
NARENDRAN

NARENDRAN

19 projects • 22 followers
Syed Omar - TP062141

Syed Omar - TP062141

1 project • 1 follower

Comments