Andrew Fukawa
Published

Home Automation: Plant Health Notifier

Updates soil status of connected plant every morning, and notifies whenever soil moisture falls below a threshold via a Discord webhook.

BeginnerWork in progress3 hours4
Home Automation: Plant Health Notifier

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Breadboard (generic)
Breadboard (generic)
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Discord

Story

Read more

Schematics

screenshot_2025-11-09_11_58_28_pm_8SERGsEgww.png

Code

Home Automation: Plant Health Notifier

C#
At a set time every day, the user is notified of the status of their plant. Using the analog value retrieved by a soil moisture sensor that is inserted in the soil of a plant, my code maps gets the percent value (out of 100) of the moisture in the plants' soil. After that, it determines the status of the plant soil by assigning a status (Overwatered, Healthy, Needs water soon, and Needs water now) to the plant based on the percent moisture.

Additionally, when the moisture level drops below a healthy range, the user is automatically notified and is told to water their plant.

Finally, the final section of code allows me to send the notifier messages into discord with the press of a button, allowing me to test changes in my code without having to wait for the schedules sending times or for the moisture to dip below a threshold.
#include <stdio.h>

int analogPin = A5; // potentiometer connected to analog pin A5
int val = 0; // value
int button = 5; // button digital pin
int count = 0; // for button tracking
int color = 0;
String status;
bool warningSent = false;
bool statusSent = false;

void setup()
{
    pinMode(button, INPUT_PULLUP);
    Serial.begin(9600);
    Time.zone(-6);
    
}


void loop()
{
    // tell time
    int hour = Time.hour();
    int minute = Time.minute();
    
    //get moisture reading
	val = analogRead(analogPin);
	val = map(val, 0, 4095, 0, 100);
	
	// determine status
	if ( val >= 50 ){
	    status = "Overwatered";
	    color = 739491;
	} else if ( val >= 30) {
	    status = "Healthy";
	    color = 4518529;
	} else if ( val >= 20) {
	    status = "Needs water soon";
	    color = 28671;
	} else {
	    status = "Needs water now";
	    color = 664575;
	}
    
    String dmData = String::format(
    "{\"val\":%d,\"status\":\"%s\",\"color\":%d}", val, status.c_str(), color);
    String tooLowData = String::format("{\"val\":\"%d\",\"status\":\"%s\",\"color\":%d}",val, status.c_str(), color);

    // sending if moisture too low
    if ( val < 30 && warningSent == false ){
        Particle.publish("tooLow", tooLowData, PRIVATE);
        warningSent = true;
    }
    
    // resetting warningSent
    if ( val >= 30 ){
        warningSent = false;
    }
    
    // 8AM status code
    if ( (hour == 23 && minute == 17) && statusSent == false )
    {
        Particle.publish("discordMessage", dmData, PRIVATE);
        statusSent = true;
    }
    
    if ( hour == 0 && minute == 0 )
    {
        statusSent = false;
    }
    
  	// Testing webhooks with button
  	int btnState = digitalRead(button);
	if ( btnState == LOW && count == 0)
	{
        Particle.publish("discordMessage", dmData, PRIVATE);
        delay(1000);
        count++;
	} else if ( btnState == LOW && count == 1 )
	{
        Particle.publish("tooLow", tooLowData, PRIVATE);
        delay(1000);
        count--;
	}
}

Credits

Andrew Fukawa
1 project • 0 followers

Comments