Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
William PottsTyler Pierson
Published

Help my plant is dying!

House plants are not tough like driveway weeds. House plants need lots of water and sunlight to thrive which people consistently forget.

BeginnerFull instructions provided168
Help my plant is dying!

Things used in this project

Story

Read more

Schematics

Argon1

Argon2

Code

Single Device Option

C/C++
This code is used with one device and uses the Particle.subscribe to flash the LEDs.
int lightVal;
int waterVal;
int lightP=A0;
int waterP=A1;
int lightLEDP=D3;
int waterLEDP=D2;
int lightCrit=2000;
int waterCrit=3000;


void setup() {

pinMode(lightP,INPUT);
pinMode(waterP,INPUT);
pinMode(waterLEDP,OUTPUT);
pinMode(lightLEDP,OUTPUT);

Particle.variable("Light Value",&lightVal,INT);
Particle.variable("Water Value",&waterVal,INT);

Particle.subscribe("Light Event",lightHandle);
Particle.subscribe("Water Event",waterHandle);

}

void loop() {

lightVal=analogRead(lightP);
waterVal=analogRead(waterP);

String waterValstring = String(lightVal);
String lightValstring = String(waterVal);

if(lightVal>lightCrit){
    
    Particle.publish("Light Event","Got enough light!");
    delay(1000);
    Particle.publish("Light Status",lightValstring,PRIVATE);
    delay(1000);
    
}

if(lightVal<=lightCrit){
    
    Particle.publish("Light Event","Im blind!");
    delay(1000);
    Particle.publish("Light Status",lightValstring,PRIVATE);
    delay(1000);
    
}

if(waterVal<=waterCrit){
    
    Particle.publish("Water Event","Got enough water!");
    delay(1000);
    Particle.publish("Water Status",waterValstring,PRIVATE);
    delay(1000);
}

if(waterVal>waterCrit){
    
    Particle.publish("Water Event","Im partched!");
    delay(1000);
    Particle.publish("Water Status",waterValstring,PRIVATE);
    delay(1000);
    
}

delay(10000);

}

void lightHandle(const char *event, const char *data){
    
    if(strcmp(data,"Got enough light!")==0){
        
        digitalWrite(lightLEDP,LOW);
        //delay(5000);
        
    }
    
    else if(strcmp(data,"Im blind!")==0){
        
        digitalWrite(lightLEDP,HIGH);
        //delay(5000);
        
    }
    
    else{}
    
}

void waterHandle(const char *event, const char *data){
    
    if(strcmp(data,"Got enough water!")==0){
        
        digitalWrite(waterLEDP,LOW);
        
    }
    
    else if(strcmp(data,"Im partched!")==0){
        
        digitalWrite(waterLEDP,HIGH);
        
    }
    
    else{}
    
}

Photoresistor Argon (Argon2)

C/C++
This code is used for Argon2 which only has the photoresistor connected to it
int lightVal;
int lightP=A0;
int lightLEDP=D3;
int waterLEDP=D2;
int lightCrit=2000;



void setup() {

pinMode(lightP,INPUT);

pinMode(waterLEDP,OUTPUT);
pinMode(lightLEDP,OUTPUT);

Particle.variable("Light Value",&lightVal,INT);


Particle.subscribe("Light Event",lightHandle,ALL_DEVICES);
Particle.subscribe("BeWater",waterHandle,ALL_DEVICES);

}

void loop() {

lightVal=analogRead(lightP);



if(lightVal>lightCrit){
    
    Particle.publish("Light Event","Got enough light!",ALL_DEVICES);
    delay(1000);
    
}

if(lightVal<=lightCrit){
    
    Particle.publish("Light Event","Im blind!",ALL_DEVICES);
    delay(1000);
    
}

delay(10000);

}

void lightHandle(const char *event, const char *data){
    
    if(strcmp(data,"Got enough light!")==0){
        
        digitalWrite(lightLEDP,LOW);
        
    }
    
    else if(strcmp(data,"Im blind!")==0){
        
        digitalWrite(lightLEDP,HIGH);
        
    }
    
    else{}
    
}

void waterHandle(const char *event, const char *data){
    
    if(strcmp(data,"Waters Good")==0){
        
        digitalWrite(waterLEDP,LOW);
        
    }
    
    else if(strcmp(data,"Low Water Level")==0){
        
        digitalWrite(waterLEDP,HIGH);
        
    }
    
    else{}
    
}

Water Sensor Argon (Argon1)

C/C++
This code is used for the Argon with only the water sensor connected to it (Argon1)
int waterVal; //define variable 

int waterP=A1;//define pin

int LEDwaterP=D2;
int LEDlightP=D3;

int waterPercent;


int critWater=3500;


void setup() {

pinMode(waterP,INPUT);//define inputs and outputs for the pins

pinMode(LEDwaterP,OUTPUT);
pinMode(LEDlightP,OUTPUT);

Particle.variable("Water Value",&waterVal,INT);

Serial.begin(230400);//begin serial monitor for checking values via the serial monitor

Particle.subscribe("Light Event", lightsCheck, MY_DEVICES);
Particle.subscribe("BeWater", waterCheck, MY_DEVICES);

}

void loop() {

waterVal=analogRead(waterP);

if(waterVal<critWater){

    //digitalWrite(LEDwaterP,LOW);
    Particle.publish("BeWater","Waters Good", ALL_DEVICES);
}

if(waterVal>=critWater){

    //digitalWrite(LEDwaterP,HIGH);
    Particle.publish("BeWater","Low Water Level", ALL_DEVICES);
    delay(1000);
}

waterPercent = -0.0493 * (waterVal) + 201.32;

Particle.publish("thingSpeakWaterLevel", String(waterPercent), PRIVATE);

delay(1000);

}

void lightsCheck(const char event, const chardata) {
        //When lightsCheck runs, sees which message was recieved and turns on or off LED accordingly

    if (strcmp(data,"Got enough light!")==0) {
        digitalWrite(LEDlightP,LOW);
    }
    else if (strcmp(data, "Im blind!")==0) {
        digitalWrite(LEDlightP,HIGH);
    }
    else{
    }
}

void waterCheck(const char event, const chardata) {
    //When waterCheck runs, sees which message was recieved and turns on or off LED accordingly

    if (strcmp(data,"Waters Good")==0) {
        digitalWrite(LEDwaterP,LOW);
    }
    else if (strcmp(data, "Low Water Level")==0) {
        digitalWrite(LEDwaterP,HIGH);
    }
    else{
    }
}

Credits

William Potts
1 project • 0 followers
Tyler Pierson
1 project • 0 followers

Comments