• EUR€
  • £GBP
  • $USD
PROJECTS ArduinoGravity

How to make a Plant Monitor

DFRobot Apr 22 2019 395

Moisture sensor tells an LED to blink and uses IFTTT to send an message to your phone when your plant needs water.

Things used in this project

Hardware components

Particle Photon
Particle Electron
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant

Software apps and online services
IFTTT Maker service
ThingSpeak API


Most people have one or more potted plants in their house that they need to water on a regular basis. The problem is that unless your a professional florist, you don't really know when each plant needs to be watered. To fix this problem we developed a system that sends you a notification on your phone when your plant is getting thirsty.

First, the moisture sensor was wired to the Photon and placed in the potted plant. The Photon was then programmed to publish an event called “moisturePercentage” when the sensor read a moisture level that was less than 20. Meanwhile, the Electron would subscribe to this event, and when it was published and would publish its own events called "plantStatus" and "handshake"; as well as change the value of a variable called thirsty from true to false. IFTTT would subscribe to “plantStatus” and send a notification to the user’s IFTTT app, while the Photon would subscribe to the "handshake" event and would stop publishing “moisturePercentage” when it heard it. In the electron code, there was a while loop that would cause its LED to start blinking while the variable thirsty=true. This provided another form of notification for the user in case they did not have their cell phone with them. When the plant was water, the moisture level would rise above 45 causing the Photon to publish another event called "plantWatered", which the Electron would subscribe to. This would cause the thirsty variable to be set to false, stopping the electron LED from flashing. After some time, the plant would absorb the water and the process would start all over again.

We decided that it would be interesting to see how the moisture level changed as the plant absorbed the water. So we used things speak to plot the moisture level every time the Photon recorded it. We found out that the blood-root plant we had chosen drank the water we gave it very quickly and would have to be watered at least once every other day.



Photon Code

int boardLed = D7; //LED D7 for testing purposes

int moisture_pin = A1; //connection point for moisture sensor

bool messageSent = false; //variable for checking if notification has been sent to phone

String plantWatered = "Your plant has been watered and is moist";

void setup() {
    pinMode(boardLed,OUTPUT); //output to turn on LED for setup
    pinMode(moisture_pin,INPUT); //Input from moisture sensor
    //Flashes LED to indicate that flash is successful.

void loop() {
    // Now we'll take some readings...
    int moisture_analog = analogRead(moisture_pin); // read capacitive sensor
    float moisture_percentage = (100 - ((moisture_analog/4095.00) * 100 ));
    Particle.subscribe("handshake", handShake, "34002f000a47373336373936"); //Subscribe command to listen to other device
    if (moisture_percentage <= 22 && messageSent == false){ //Checks if moisture percentage is below threshold and also checks if the water message has been sent
      Particle.publish("moisturePercentage", String(moisture_percentage),60,PUBLIC); //Publishes for message to be sent
    if (moisture_percentage > 40 && messageSent == true){ //Checks if moisture levels have gone back up and also checks if message has been sent
        Particle.publish("plantWatered", plantWatered, 60, PUBLIC);
        messageSent = false; //If message sent, and plant watered, it resets the program so that the function above will run
    Particle.publish("plantStatus_percentage", String(moisture_percentage),60,PUBLIC); //Publish command for logging data and sending it to thingspeak

void handShake( const char *event, const char *data){ //If the message has been sent, it sets messageSent to true
    messageSent = true;

Electron Code

int led=D7;//led that indicates the plant needs water
bool sent=false;// has the notification to water the plant been sent
bool thirsty=false;//whether or not the plant needs water

void setup() 


void loop() 
    {//while the plant needs water the LED flashes and the electron listens for when the water level goes up
    Particle.subscribe("plantWatered",breakloop,"3c0026001747373335333438");// checks for when the plant has been waterd.

    delay(5000);// this loop every five minutes
void waterPlant( const char *event, const char*data)
        Particle.publish("plantStatus","thirsty",60,PUBLIC);//sends a message to IFTTT to notify me to water my plants.
        Particle.publish("handshake","sent",60,PUBLIC);// notifies the photon that the message has been sent
 void breakloop( const char *event, const char*data)// changes thirsty to false to break the while loop and stop the led from flashing