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!
ZenaAmanda ShawKennedi
Published

Plant Health Monitoring System (Spring 23 IOT Group 14)

Never mourn a dead, dried-out plant again when you use this Plant Health Monitoring System

IntermediateFull instructions provided1,031
Plant Health Monitoring System (Spring 23 IOT Group 14)

Things used in this project

Hardware components

Argon
Particle Argon
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×3
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Photo resistor
Photo resistor
×1
Resistor 220 ohm
Resistor 220 ohm
×2
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
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Photo-resistor Cluster circuit

Temperature Sensor Circuit

Soil Moisture Sensor Circuit

Code

Photoresistor

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

TCPClient client;

unsigned long myChannelNumber = 2113664;
const char * myWriteAPIKey = "9DR7CR40K7C54NHT";


int led1 = A5; // White LED (+ to A5, - to GND), lights when sensor is below light threshold

int photoresistor = A0; // Photoresistor connected to A0 pin
int analogValue;

void setup() {

  ThingSpeak.begin(client);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(photoresistor, INPUT);

}

void loop() {
    analogValue = analogRead(photoresistor); // Loop reads analog value of photo resistor
    ThingSpeak.writeField(myChannelNumber, 1, analogValue, myWriteAPIKey);
    if (analogValue > 75) { //If over threshold, digital write LOW to LEDs
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        Particle.publish("Bright Light", "0", PUBLIC); //Publish to Particle console
        delay(15000);

    } else { //If over threshold, digital write HIGH to LEDs
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        Particle.publish("Low or No Light", "1", PUBLIC); //Publish to Particle console
        delay(15000);
    }
}

DHT Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Grove_Temperature_And_Humidity_Sensor.h>

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

#define DHTPIN  D2     // set pin

TCPClient client;

unsigned long myChannelNumber = 2113664;    // change this to your channel number
const char * myWriteAPIKey = "9DR7CR40K7C54NHT"; // change this to your channels write API key

unsigned long previousMillis = 0;

DHT dht1(DHTPIN);

// Initialize Grove Button on digital pin D4
const int BUTTON_PIN = D4;

// Initialize variables to track the state of the button
bool buttonState = LOW;
bool lastButtonState = LOW;
bool isOn = false;

// Set the interval for taking readings
const unsigned long INTERVAL = 500; // in milliseconds

// Set the interval for printing readings
const unsigned long PRINT_INTERVAL = 5000; // in milliseconds
unsigned long lastPrintTime = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 Begin!!!");
  ThingSpeak.begin(client);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(D7, OUTPUT);
}


void loop() {
  // Read the button state
  buttonState = digitalRead(BUTTON_PIN);
  // Check if the button state has changed
  if (buttonState != lastButtonState) {
    // If the button is pressed, toggle the state of isOn
    if (buttonState == LOW) {
      isOn = !isOn;
    }
    // Delay for debounce
    delay(50);
  
   digitalWrite(D7, HIGH);
    Particle.publish("toggle-led", PUBLIC);
    delay(1000);
    digitalWrite(D7, LOW);
    delay(5000);
    
    
  }

  // Save the current button state for comparison
  lastButtonState = buttonState;

  // If the code is on, take and print readings
  if (isOn) {
    // Check if it's time to take a reading
    if (millis() - lastPrintTime >= INTERVAL) {
      //Read Humidity
      float h = dht1.getHumidity();
      // Read temperature as Celsius
      float t = dht1.getTempCelcius();
      // Read temperature as Farenheit
      float f = dht1.getTempFarenheit();

      Serial.print("Humid: ");
      Serial.print(h);
      Serial.println("%  ");
      Serial.print("Temp: ");
      Serial.print(t);
      Serial.println("*C ");
      Serial.print("Temp: ");
      Serial.print(f);
      Serial.println("*F ");
      Serial.println();

      String Humidity = "{" + String(h) + "}";

      String Temp = "{" + String(f) + "}";

      Particle.publish("Temp", Temp);

      Particle.publish("Humidity", Humidity);

      ThingSpeak.setField(1,String(h));
      ThingSpeak.setField(2,String(f));

      // Update the last print time
      lastPrintTime = millis();

      // Write to ThingSpeak, field 1, immediately
      ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

      delay(15000); // ThingSpeak will only accept updates every 15 seconds.
    }
  }
  else {
    // If the code is off, reset the last print time
    lastPrintTime = millis();
  }
}

Soil Moisture Sensor

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();
    }
    
  //While loop to run a specified number times when initialized
  while (i < 50 && digitalRead(D7) == LOW) {
  //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);
  // data is in counts out of 4096, so it needs to be converted to voltage
  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
  String data = String(mVoltage);
  //Trigger the integration
  Particle.publish("mvoltage_reading ", data, PRIVATE);
            i++;
            
  //Wait 10 seconds
  delay(10000);
        }
    
}


//this function turns on LED
void toggleLed(const char *event, const char *data) {
    
    digitalWrite(D7, HIGH);
    delay(1000);
    digitalWrite(D7,LOW);
    delay(1000);
}

Credits

Zena
1 project • 2 followers
Mechanical Engineering Student, studying at the University of North Carolina at Charlotte
Amanda Shaw
1 project • 3 followers
UNC Charlotte Mechanical Engineering senior
Kennedi
1 project • 1 follower

Comments