Jordan WestDaniel Head
Published © GPL3+

Plant Saver

Don't you just hate when you buy a nice house plant, forget to water it and within a week or two it dies. We have a solution for you!

EasyShowcase (no instructions)2.5 hours1,756
Plant Saver

Things used in this project

Hardware components

Photon
Particle Photon
×2
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
Depending on how long of a connection you need, the amount of wires used can vary
×9

Software apps and online services

ThingSpeak API
ThingSpeak API
Maker service
IFTTT Maker service

Story

Read more

Schematics

Circuit Diagram and Schematics

Bb jdygkc5us4

Code

Soil Moisture Sensing Photon

C#
This code is for the Photon with the sensor.
int soilPin = A0;//read pin A0
int soilPower = 7;//gives power to D7 (has an LED on Photon - You can clearly see when it takes a value this way. Good for troubleshooting.)
int value = readSoil();//starts readSoil() function below
#define publish_delay 600000//publish every 10 minutes
unsigned int lastPublish = 0;//sets time since last publish to an initial value of 0
void setup() {
    pinMode(soilPower, OUTPUT);//sets D7 as an OUTPUT
    digitalWrite(soilPower, LOW);//turns D7 off
    //Spark.variable for particle
    //"Moisture" is the name you're looking out for when you're using IFTTT
    //&value is the variable you're using from your code to send using IFTTT
    Spark.variable("Moisture", &value, INT);//sets Spark.variable to Moisture, with the value from variable "value". For use with IFTTT applet
}
void loop() {
    unsigned long now = millis(); 
    if ((now - lastPublish) < publish_delay) {
        return;
    }
    int value = readSoil();//Calls function from below
    //Publishes the event "thingSpeakWrite_A0" to the Particle Cloud
    Particle.publish("thingSpeakWrite_A0", "{ \"1\": \"" + String(value) + "\", \"k\": \"EX4AMP13-REPLACE-WITH-YOUR-WRITE-KEY\" }", 60, PRIVATE);//publishes to ThingSpeak
    lastPublish = now;//resets lastPublish variable to now (resets timer)
}
int readSoil()
{
    digitalWrite(soilPower, HIGH);//turn D7 "On"
    delay(50);//wait 50 milliseconds 
    int val = analogRead(soilPin);//Read the SIG value form sensor 
    delay(50);//wait 50 milliseconds 
    digitalWrite(soilPower, LOW);//turns D7 off
    return val;//send current moisture value
}

Receiving and Notifying Photon

C#
This code is for the Photon that receives the code and notifies the user.
int num = Particle.subscribe("thingSpeakWrite_A0", MoistureNotify, "YOUR-DEVICE-ID#");
void setup() {
    Particle.subscribe("thingSpeakWrite_A0", MoistureNotify, "YOUR-DEVICE-ID#");
    Spark.variable("MoistureLvl", &num, INT);
}
void loop() {
}
void MoistureNotify(const char *event, const char *data)
{
    int num = atoi(data);
    if (num<=100) {
      digitalWrite(D7,HIGH);
    }else if (num>100 && num<200) {
      digitalWrite(D7,LOW);
    }else {
      digitalWrite(D7,LOW);
  }
}

Credits

Jordan West

Jordan West

1 project • 0 followers
I'm a mechanical engineering major at UNC Charlotte.
Daniel Head

Daniel Head

1 project • 0 followers
I'm a junior mechanical engineering student at UNC Charlotte.
Thanks to Ingo Lohs.

Comments

Add projectSign up / Login