Waleed Sawan
Published © GPL3+

Drip - Low-Cost Precision Irrigation for Developing Nations

Drip is a low-cost, efficient precision irrigation system that was designed to service the needs of farmers in developing nations.

AdvancedShowcase (no instructions)Over 4 days2,054

Things used in this project

Hardware components

Photon
Particle Photon
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
Used for prototyping.
×3
Electron
Particle Electron
Not used in the final build, but in multiple iterations.
×1
Nordic Semiconductor NRF24L01+
×3
SparkFun Logic Level Converter - Bi-Directional
SparkFun Logic Level Converter - Bi-Directional
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×2
Adafruit Solenoid Valve
×1
Temperature Sensor
Temperature Sensor
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
RobotGeek Tilt Sensor
RobotGeek Tilt Sensor
×1
LED (generic)
LED (generic)
×3

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Field Probe

The Field Probe, equipped with moisture and sun exposure sensors, continually monitors the crop irrigation conditions - relaying it to the central Communication Hub via the Mesh Network.
Probeschematic yfgxp7nmov

Communication Hub

The Communication Hub Internet of Things (IoT) Module is responsible for all interaction between the Field Probes/Valves and the Cloud Drip Database.
Comhubschematic hbxge8yk3h

Field Valve

The Field Valve allows the farmer to control crucial machinery, such as sprinklers, in their field through the advanced online-Drip dashboard.
Valveschematic qgdrds7qlj

Code

ComHubGateway.ino

Arduino
Source Code for Communication Hub Gateway.
/*
Created by Waleed Sawan (Waleed101.github.io)

Copyright 2018 Waleed Sawan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
int curMode = 0;
int esData = 0;
int info = 0;

const int numLEDs = 3;
int redPin = 6;
int greenPin = 5;
int bluePin = 3;
int redValue = 0, greenValue = 0, blueValue = 0;
int cycle = 0;
int prevSend = 0;

unsigned long previousMillis = 0, previousMillisSerial = 0; 
const long interval = 1000;

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.openWritingPipe(addresses[1]); // 00001
  radio.openReadingPipe(1, addresses[0]); // 00002

  delay(1000);
  boolean on = true;
  unsigned long currentMillis = millis();
  int flashSpeed = 250;
  while(info != 1)
  {
      currentMillis = millis();
      
      if(currentMillis - previousMillis >= flashSpeed)
      {  
        previousMillis = currentMillis;
        if(on)
        {
          if(currentMillis%15000 <= 2000 && currentMillis > 2000)
          {
            redValue = 255; greenValue = 0; blueValue = 0;
            flashSpeed = 100;
          }
          else
          {
            redValue = 0; greenValue = 255; blueValue = 0;
            flashSpeed = 250;  
          }  
          on = false;
        }
        else
        {
          if(currentMillis%15000 <= 2000 && currentMillis > 2000)
          {
            redValue = 0; greenValue = 0; blueValue = 0; 
            flashSpeed = 100;
          } 
          else
          {
            redValue = 0; greenValue = 0; blueValue = 0; 
            flashSpeed = 250;  
          } 
          on = true;
        }
      }
      setColor(redValue, greenValue, blueValue);
      info = Serial.read();         
  }
}

// THIS WILL BE THE HUB
void loop() {

   unsigned long currentMillis = millis();
  if(prevSend < 2500 && (currentMillis - previousMillisSerial >= 6000))
  {
    previousMillisSerial = currentMillis;
    radio.startListening();
    if (radio.available())
    {
      radio.read(&esData, sizeof(esData));
      esData = esData / 10;
      Serial.write(esData);
    }
  }
  curMode = Serial.read();
  
  if(curMode != -1)
  {
    prevSend = 0;
    radio.stopListening();
    radio.write(&curMode, sizeof(curMode));
  }
  
  if(currentMillis - previousMillis >= 10)
  {
    prevSend++;
    previousMillis = currentMillis;
    if(prevSend >= 2500)
      setColor((sin(cycle * 0.0174533) + 1) * 127, 0, (sin(cycle * 0.0174533) + 1) * 127);
    else         
      setColor(0, (sin(cycle * 0.0174533) + 1) * 127, (sin(cycle * 0.0174533) + 1) * 127);
    cycle++;
  }
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);
}

Probe.ino

Arduino
Source Code for Field Probe.
/*
Created by Waleed Sawan (Waleed101.github.io)

Copyright 2018 Waleed Sawan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int mstrSens = A0;
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
int myData = 0;

void setup() {
  Serial.begin(9600);
  pinMode(mstrSens, INPUT);
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.openWritingPipe(addresses[0]); // 00002
  //radio.openReadingPipe(1, addresses[1]); // 00001
}

// THIS WILL BE THE VALVE
void loop() {
  delay(5);
  myData = analogRead(mstrSens);
  radio.write(&myData, sizeof(myData));
  Serial.println(myData);
}

ComHubUplink.ino

Arduino
Source Code for Communication Hub Uplink
/*
Created by Waleed Sawan (Waleed101.github.io)

Copyright 2018 Waleed Sawan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

int led1 = D7;
char publishString[60];
unsigned long lastTime = 0UL;
int valveStatus = 0;

void setup()
{
    Serial1.begin(9600); // Initialize Serial
    for(int i = 0; i < 11; i++)
    {   
        Serial1.write(1); // Send to Communication Hub Gateway
        Serial1.flush(); // Wait for Serial to finish sending
    }
    Particle.publish("Wrote", "Yes!");
    Particle.publish("Something", "Yes!");
    Particle.subscribe("hook-response/valve", TokenHandler, MY_DEVICES);
}

void loop() {
    unsigned long now = millis();
    if (now - lastTime > 6000UL) 
    {
      sprintf(publishString, "%i", 298);
      Particle.publish("valve", publishString);
      lastTime=millis();
      sprintf(publishString, "%i", valveStatus);
      Particle.publish("value", publishString);
    }
    Serial1.write(valveStatus);
    delay(10);
}

void TokenHandler(const char *name, const char *data) {
    valveStatus = atoi(String(data));
}

valve.ino

Arduino
Source Code for Field Valve.
/*
Created by Waleed Sawan (Waleed101.github.io)

Copyright 2018 Waleed Sawan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define button 4
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

int solenoidPin = 10;    //This is the output pin on the Arduino we are using
int valveOff = 9;
int curMode = 0;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.openReadingPipe(1, addresses[1]);
  setValve(false);
}

void loop() {
  delay(5);
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {
      radio.read(&curMode, sizeof(curMode));
      setValve(curMode);
      Serial.println("Radio Available");
    }
    delay(5);
  }
}

void setValve (int state)
{
  if(state == 1)
  {
    digitalWrite(solenoidPin, HIGH);
    digitalWrite(valveOff, LOW);   
  }
  else if(state == 0)
  {
    digitalWrite(solenoidPin, LOW);
    digitalWrite(valveOff, HIGH);  
  }
}

Credits

Waleed Sawan

Waleed Sawan

1 project • 2 followers
A 16-year-old innovator from Canada. Fluent in many object-oriented languages, including Java and C. Grand winner @ Particle's IoSP.

Comments