Abigail L.
Published © GPL3+

Conserving Water by Preventing Over Irrigation

This project uses a soil moisture sensor to sense when your yard or plants need watering, and then turns on your sprinklers accordingly.

IntermediateFull instructions provided2 hours1,442
Conserving Water by Preventing Over Irrigation

Things used in this project

Hardware components

Photon
Particle Photon
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Sprinkler Valve
×1

Software apps and online services

Maker service
IFTTT Maker service

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

The Code

C/C++
Copy and paste this into Particle Build (Web IDE) and flash it to your device
/*   To view full project vist
     https://www.hackster.io/abigail131/conserving-water-by-preventing-over-irrigation-9b0b34
*/

#define WetSoilValue        3200 //sets the wet soil value to 3200 this is different for each sensor make sure to find your value, more info at https://learn.sparkfun.com/tutorials/soil-moisture-sensor-hookup-guide?_ga=2.219475673.1522345871.1522631550-971193973.1489890773
#define Sensor_PIN          A0 //makes A0 the pin for the sensor
#define Sprinkler_PIN       6 //makes D6 the pin for the sprinkler valve
#define LED_PIN             5 //makes D5 the LED pin
#define TEXTING_INTERVAL    1800000 // makes the texting interval 30 minutes (1000ms * 60s * 30mins)

int WetSoilValueReached = false; //defines the variable  WetSoilValueReached to false 
unsigned long LastTextTime = 0; //sets last text time to 0

void setup() {
    pinMode(Sensor_PIN, INPUT); //makes the sensor pin an input
    pinMode(Sprinkler_PIN, OUTPUT); //makes the sprinkler pin an output
    pinMode(LED_PIN, OUTPUT); //makes the LED pin an output
}

void loop() {
    if (analogRead(Sensor_PIN) < WetSoilValue) { //If the moisture reading is low and reaches the wet soil value amount then:
        WetSoilValueReached = true; //wet soil value reached becomes true
        digitalWrite(Sprinkler_PIN, HIGH); //turns Sprinkler pin to high
        digitalWrite(LED_PIN, HIGH); //turns LED pin to high
        
        unsigned long now = millis();
        
        if (now - LastTextTime >= TEXTING_INTERVAL) { //If a text has not been sent in the last 30 minutes then:
            Particle.publish("Soil moisture low, turning on sprinklers!"); //publishes an event which send the text
        }
    }
    
    else {
        WetSoilValueReached = false; //If the moisture reading is higher than wet soil value amount
        digitalWrite(Sprinkler_PIN, LOW);//turns the Sprinkler pin low
        digitalWrite(LED_PIN, LOW);//turns the LED pin low
    }
}

Credits

Abigail L.

Abigail L.

1 project • 0 followers
I am in 9th grade from Charlotte, NC. I hope to be an Electrical Engineer in the future!!

Comments