Braden WalkerVictor Rolim Gruba SilvaDarrick Romana
Published

MEGR 3171 IOT Project: Plant Moisture

Have you ever wondered if your plant needs more water? We will show you how to measure your soil for proper plant hydration treatment!

BeginnerWork in progress33
MEGR 3171 IOT Project: Plant Moisture

Things used in this project

Hardware components

Argon
Particle Argon
×3
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×3
Gravity: Analog Soil Moisture Sensor For Arduino
DFRobot Gravity: Analog Soil Moisture Sensor For Arduino
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Moisture Circuit Diagram

Moisture Level Graph

Code

Argon 1

C/C++
int i = 0;
void setup() {
    
pinMode(D7, OUTPUT);
Particle.subscribe("LED", toggleLed, ALL_DEVICES);

if (Particle.connected() == false) {
Particle.connect();
}
Particle.subscribe("need-water", water, ALL_DEVICES);
}
void loop() {
if (digitalRead(D7) == LOW && i < 1) {
delay(5000);
Particle.publish("LED", "on", PUBLIC);
delay(1000);
}
}
String water(const char *event, const char *data) {
return String(data);
}
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);
}
}

Argon 2

C/C++
int Moisture = A1;
int analogMoisture = 0;
int mVoltage = 0;
int i = 0;

void setup() {

pinMode(D7, OUTPUT);
Particle.subscribe("LED", toggleLed, ALL_DEVICES);
pinMode(Moisture, INPUT);
}
void loop() {
if (Particle.connected() == false) {
Particle.connect();
}
    
 while (i < 100 && digitalRead(D7) == HIGH) {
   
analogMoistureSoil = analogReadSoil(Moisture);
MSVoltage = (analogMoistureSoil*3000)/3798;
Particle.variable("MSVoltage", mVoltage);
Particle.publish("MSvoltage_reading", String(mVoltage), PUBLIC);
delay(5000);
}

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);
}
}

Argon 3

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

void setup() {
pinMode(D7, OUTPUT);
Particle.subscribe("MSvoltage_reading", mVoltage, ALL_DEVICES);
Particle.subscribe("LED", toggleLed, ALL_DEVICES);
    
}

void loop() {

if (Particle.connected() == false) {
Particle.connect();
}
if (digitalRead(D7) == HIGH) {
if (j > 40) {
avg = sum / j;
if (avg < 2400 && avg > 0) {
digitalWrite(D7, HIGH);
delay(500);
digitalWrite(D7, LOW);
Particle.publish("average_voltage_reading", String(avg));
Particle.publish("need-water", "watered", PUBLIC);
Particle.publish("LED", "off", PUBLIC);
avg = 0;
}
if (avg > 2400) {
digitalWrite(D7, HIGH);
delay(500);
digitalWrite(D7, LOW);
Particle.publish("average_voltage_reading", String(avg));
Particle.publish("need-water", "not watered", PUBLIC);
Particle.publish("LED", "off", PUBLIC);
avg = 0;
}
delay(5000);
}

int mVoltage(const char*event, const char*data) {
value = atoi(data);
sum = sum + value.toInt();
return sum; 
}
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

Braden Walker

Braden Walker

1 project • 1 follower
Victor Rolim Gruba Silva

Victor Rolim Gruba Silva

1 project • 2 followers
Darrick Romana

Darrick Romana

1 project • 1 follower

Comments

Add projectSign up / Login