Matthew MarslenderMljenkinsvnaguirre
Published

UNCC IOT Project (3171 Group 23)

Have you ever had a problem keeping your plant at home healthy? Check out this monitoring system to ensure a healthy plant life.

IntermediateWork in progress220
UNCC IOT Project (3171 Group 23)

Things used in this project

Hardware components

Argon
Particle Argon
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
×1
Photo resistor
Photo resistor
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Resistor 220 ohm
Resistor 220 ohm
×2
LED (generic)
LED (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

TinyUSB Library by Adafruit
TinyUSB Library by Adafruit

Story

Read more

Schematics

Temperature Sensor

Photo-resistor

Capacitive Soil Sensor

Code

Data collection

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);
    Particle.subscribe("hook-response/mvoltage_reading ", myHandler, MY_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) {
  //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);
  // 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);
        }
    
}
void myHandler(const char *event, const char *data) {
  // integration response
}

//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 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(10000);
  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

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

///Photo
int led1 = A5;
int led2 = D7;
int photoresistor = A0;
int analogValue;

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(10000);
                    digitalWrite(D7, LOW);
                
                    Particle.publish("toggle-led", "on", PUBLIC);
                    avg = 0;
            }
            if (avg > 2000) {
                    digitalWrite(D7, HIGH);
                    delay(10000);
                    digitalWrite(D7, LOW);
                    
                    Particle.publish("toggle-led", "off", PUBLIC);
                    avg = 0;
            }
            j = 0;
        }
       delay(60000);
    }
}
    
//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);
    }
}

Photo-resistor

C/C++
//LED light connected to A5 and ground 
int led1 = A5; 

//LED on the Argon 
int led2 = D7; 

//Photoresistor connected to A0 pin that detects light 
int photoresistor = A0;
int analogValue;

void setup() {

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(photoresistor, INPUT);

}

//Loop constructed to read analog value of the photoresistor and digital 
//write to the LEDs in the circuit. Particle.publish is used twice to publish 
//an event both when light is detected and when it is not. 
void loop() {
    analogValue = analogRead(photoresistor);
    
//if statement below can be changed to adjust how sensitive the photoresistor is to light
    if (analogValue > 15) {
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        Particle.publish("SUNNY", "0", PUBLIC);
        delay(7000);
    } else {
        digitalWrite(led1, HIGH);
        digitalWrite(led2, HIGH);
        Particle.publish("NOT-SUNNY", "1", PUBLIC);
        delay(7000);
    }
}

Temperature and Humidity

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <PietteTech_DHT.h>
#define DHTTYPE  DHT22
#define DHTPIN   D4

PietteTech_DHT DHT(DHTPIN, DHTTYPE);

double serverTempMax = 81;
double serverHumidityMax = 60;
double serverTemp;
double serverHumidity;
bool overheatDetected = false;
bool tooHumid = false;

void setup ()
{
    Particle.variable("serverTemp", &serverTemp, DOUBLE);
Particle.variable("serverHumidity", &serverHumidity, DOUBLE);

}

void loop()
{
     int result = DHT.acquireAndWait(2000);
  
  serverTemp = DHT.getFahrenheit();
  serverHumidity = DHT.getHumidity();
  
  if(serverTemp>=serverTempMax && !overheatDetected){
      Particle.publish("server_temp", "HOT");
      overheatDetected = true;
  }
  else if(serverTemp<serverTempMax && overheatDetected){
      Particle.publish("server_temp", "normal");
      overheatDetected = false;
  }
  
  if(serverHumidity>=serverHumidityMax && !tooHumid){
      Particle.publish("server_humidity", "HUMID");
      tooHumid = true;
  }
  else if(serverHumidity<serverHumidityMax && tooHumid){
      Particle.publish("server_humidity", "normal");
      tooHumid = false;
  }
  
  delay(10000);
}

Credits

Matthew Marslender

Matthew Marslender

1 project • 0 followers
Mljenkins

Mljenkins

1 project • 0 followers
vnaguirre

vnaguirre

1 project • 1 follower

Comments