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!
Jay PatelTyler BelmonteMichael York
Published © GPL3+

Soil Moisture Project Particle Argon

Ever forget when to water your plants??? Worry no more, we got the solution for you!!!! Know exactly when to water your plants.

IntermediateFull instructions provided10 hours1,790
Soil Moisture Project Particle Argon

Things used in this project

Hardware components

Argon
Particle Argon
×3
Jumper wires (generic)
Jumper wires (generic)
×3
Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Maker service
IFTTT Maker service
Google Sheets
Google Sheets
Link to Live graphs: https://docs.google.com/spreadsheets/d/1FmpJWwDeWeu7zhu90j0x8TXOyHkESLquWZoLICd29Sw/edit?usp=sharing

Story

Read more

Schematics

Data Collector Argon Schematic

Connect Data Pin A1 to the Argons A1 pin, connect negative pin from sensor to GND on Argon, and connect positive pin from sensor to VUSB on Argon.

Code

Data Collection Code

C/C++
//Set Moisture Sensor to Analog 0 Pin
int Moisture = A1;
int analogMoisture = 0;
int mVoltage = 0;
int i = 0;

void setup() {

    pinMode(D7, OUTPUT);
    Particle.subscribe("toggle-led", toggleLed, ALL_DEVICES);
    
    //Set pinmode as INPUT so that we read the data from the Moisture sensor
    pinMode(Moisture, INPUT);
    
}



void loop() {
    //Connect to Particle Clould check
    if (Particle.connected() == false) {
        Particle.connect();
    }
    
    //For single device testing, set pin D7 to HIGH : digitalWrite(D7, HIGH);
    //if (digitalRead(D7) == HIGH) {
        //While loop to run a specified number times when initialized
        while (i < 50 && digitalRead(D7) == HIGH) {
            //Read Moisture Sensor and send data to analogMoisture Variable, this data is in counts out of 4096, so it needs to be converted to voltage
            analogMoisture = analogRead(Moisture);
            mVoltage = (analogMoisture*3300)/4096;
            
            //Publish mVoltage variable which is the output voltage in mV of the moisture sensor
            Particle.variable("mVoltage", mVoltage);
            
            //Publish Voltage in millivolts
            Particle.publish("mvoltage_reading", String(mVoltage), PUBLIC);  // publish voltage values to cloud
            i++;
            
            //Wait 10 seconds
            delay(10000);
        }
    
}

//this function turns on LED
void toggleLed(const char *event, const char *data) {
    
    if (digitalRead(D7) == LOW && String(data).equals("on")) {
        digitalWrite(D7, HIGH);
    }
    else if (digitalRead(D7) == HIGH && String(data).equals("off")){
        digitalWrite(D7, LOW);
    }
}

Initiate Data Collection

C/C++
int i = 0;
void setup() {
    pinMode(D7, OUTPUT);
    Particle.subscribe("toggle-led", toggleLed, ALL_DEVICES);
    
    //Connect to a WiFi network check
    if (WiFi.ready() == false) {
        WiFi.setCredentials("Galaxy_Jay", "800989865");
        WiFi.on(); WiFi.connect();
    }
    
    //Connect to Particle Clould check
    if (Particle.connected() == false) {
        Particle.connect();
    }
    Particle.subscribe("water-plant", water, ALL_DEVICES);
}

void loop() {
    if (digitalRead(D7) == LOW && i < 1) {
        delay(10000);
        Particle.publish("toggle-led", "on", PUBLIC);
        delay(2000);
        i++;
    }

}

String water(const char *event, const char *data) {
    return String(data);
}

//this function turns on LED
void toggleLed(const char *event, const char *data) {
    
    if (digitalRead(D7) == LOW && String(data).equals("on")) {
        digitalWrite(D7, HIGH);
    }
    else if (digitalRead(D7) == HIGH && String(data).equals("off")){
        digitalWrite(D7, LOW);
    }
}

Data Processing Code

C/C++
int sum = 0;
int temp = 0;
String value;
int avg = 0;
int j = 1;

void setup() {
    pinMode(D7, OUTPUT);
    Particle.subscribe("mvoltage_reading", mVoltage, ALL_DEVICES);
    Particle.subscribe("toggle-led", toggleLed, ALL_DEVICES);
    
}

void loop() {
    //Connect to Particle Clould check
    if (Particle.connected() == false) {
        Particle.connect();
    }
    
    //For single device testing, set pin D7 to HIGH : digitalWrite(D7, HIGH);
    if (digitalRead(D7) == HIGH) {
        
        if (j > 20) {
            avg = sum / j;
            if (avg < 2000 && avg > 0) {
                    digitalWrite(D7, HIGH);
                    delay(1000);
                    digitalWrite(D7, LOW);
                    Particle.publish("avg_voltage_reading", String(avg));
                    Particle.publish("water-plant", "watered", PUBLIC);
                    Particle.publish("toggle-led", "off", PUBLIC);
                    avg = 0;
            }
            if (avg > 2000) {
                    digitalWrite(D7, HIGH);
                    delay(1000);
                    digitalWrite(D7, LOW);
                    Particle.publish("avg_voltage_reading", String(avg));
                    Particle.publish("water-plant", "not watered", PUBLIC);
                    Particle.publish("toggle-led", "off", PUBLIC);
                    avg = 0;
            }
            j = 0;
        }
       delay(10000);
    }
}
    
//this function sums the voltage values it recieves/collects
int mVoltage(const char *event, const char *data) {
    
    value = atoi(data);
    sum = sum + value.toInt();
    j++;
        
    return sum; 
}

//this function turns on LED
void toggleLed(const char *event, const char *data) {
    
    if (digitalRead(D7) == LOW && String(data).equals("on")) {
        digitalWrite(D7, HIGH);
    }
    else if (digitalRead(D7) == HIGH && String(data).equals("off")){
        digitalWrite(D7, LOW);
    }
}

Credits

Jay Patel
1 project • 2 followers
Tyler Belmonte
1 project • 1 follower
Michael York
1 project • 1 follower

Comments