Things used in this project

Hardware components:
Photon new
Particle Photon
×2
13637 01
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
12002 04
Breadboard (generic)
×2
11026 02
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:
Hackster
ThingSpeak API
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service

Schematics

Circuit Diagram and Schematics
Bb jdygkc5us4

Code

Soil Moisture Sensing PhotonC#
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 PhotonC#
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

Megr2156 rm7id9ahgc
Jordan West
1 project • 0 followers
I'm a mechanical engineering major at UNC Charlotte.
Contact
13697143 1264060730294265 1047035151165227350 n
Daniel Head
1 project • 0 followers
I'm a junior mechanical engineering student at UNC Charlotte.
Contact
Thanks to Ingo Lohs.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login