Zachary BellflowerXavierAsh Rai
Published

Temperature and Moisture Sensors with Alert

We used temperature and moisture sensors on a plant. If the temperature is too high or the moisture is too low, the light will alert you.

IntermediateFull instructions provided15 hours288
Temperature and Moisture Sensors with Alert

Things used in this project

Story

Read more

Schematics

Assembled Project Picture

Temperature Sensor Picture

Moisture Sensor Picture

RGB Light Picture

Project Flow Chart

Temperature Sensor Circuit Diagram

Moisture Sensor Circuit Diagram

RBG Circuit Diagram

Code

Moisture Data Collection

C/C++
This code is collecting the moisture data from the plant and publishing it to the particle cloud. It also compares the moisture percentage do a threshold value to determine whether the moisture is too, and if it is publishes an alert called "MoistureAlert". This code goes on the Argon with the moisture sensor.
int boardLed = D7; 

int moisture_pin = A1; 

const static float moisture_threshold = 25.00;



void setup() {
  pinMode(boardLed,OUTPUT); 
  pinMode(moisture_pin,INPUT);  


  
  digitalWrite(boardLed,HIGH);
  delay(200);
  digitalWrite(boardLed,LOW);
  delay(200);

}




void loop() {
    

    digitalWrite(boardLed,HIGH);
   
    int moisture_analog = analogRead(moisture_pin); // read capacitive sensor
    float moisture_percentage = (100 - ( (moisture_analog/4095.00) * 100 ) );
    if(BATT > 1){
        float voltage = analogRead(BATT) * 0.0011224;
        Particle.publish("plantStatus_voltage", String(voltage),60,PUBLIC);
    }
   
    Particle.publish("plantStatus_analog", String(moisture_analog),60,PUBLIC);
    Particle.publish("plantStatus_percentage", String(moisture_percentage),60,PUBLIC);
    digitalWrite(boardLed,LOW);
    
    delay(30000);
    
    
  String data = String(10);
  // Trigger the integration
  Particle.publish("plantStatus_percentage", data, PRIVATE);
  // Wait 30 seconds
  delay(30000);
  
   if (moisture_percentage < moisture_threshold){
        Particle.publish("MoistureAlert");
    }
    
}

Temperature Data Collection

C/C++
This is the code for collecting temperature data in the area around the plant. If the temperature or humidity gets to high, an event is published to the cloud called "TempAlert". This code goes on the Argon with the temperature sensor.
// This #include statement was automatically added by the Particle IDE.
#include <DHT.h>

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

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

// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>
//int rs=D0;
//int en=D1;
//int d4=D2;
//int d5=D3;
//int d6=D4;
//int d7=D5;
LiquidCrystal lcd (D0,D1,D2,D3,D4,D5);

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

//2-Colours LED Pins
int led1 = D8; //Connect the D8 pins on particle argon to R-pin on RGB LED. Red-LED
int sensepin=6;
DHT HT(sensepin, DHT11);
float humidity;
float tempC;
float tmepF;
int setTime = 1000;
int dt=2000;
const static float temp_threshold = 8.00;

void setup() {
    Serial.begin(9600);
    HT.begin();
    delay(setTime);
lcd.begin (16,2);
pinMode(led1, OUTPUT);
}

void loop() {

humidity=HT.readHumidity();
tempC=HT.readTemperature ();
tmepF=HT.readTemperature(true);




lcd.setCursor(0,0);
lcd.print("Temp F=");
lcd.print(String(tmepF));

lcd.setCursor(0,1);
lcd.print("humidity = ");
lcd.print(String(humidity));
lcd.print("%");



Serial.print ("Humidity:  ");
Serial.print (humidity);
Serial.print ("Temperature C ");
Serial.print (tempC);
Serial.print ("C");
Serial.print (tmepF);
Serial.print ("F");

  // Get some data
  String data = String((10));
  // Trigger the integration
  Particle.publish("Temp/humidity", data, PRIVATE);
  // Wait 30 seconds
  delay(5000);
  
  if(tempC > temp_threshold){
      Particle.publish("TempAlert");
}
}

      

LED Response

C/C++
This is the code that triggers the LED's to light up. If the 'MoistureAlert' event is published the red LED turns on on. If the "TempAlert" event is published the green LED is turned on. This code goes on the Argon that is connected to the LED.
int redled = D8;
int yellowled = D7;
void setup() {
    
    pinMode(redled, OUTPUT);
    pinMode(yellowled, OUTPUT);
    digitalWrite(redled, LOW);
    digitalWrite(yellowled, LOW);
    
    Particle.subscribe("MoistureAlert", blinkred);
    Particle.subscribe("TempAlert", blinkyellow);
}


void blinkred(const char *event, const char *data){ 
    digitalWrite(redled, HIGH);
    delay(2000);
    digitalWrite(redled,LOW);
}

void blinkyellow(const char *event, const char *data){ 
    digitalWrite(yellowled, HIGH);
    delay(2000);
    digitalWrite(yellowled, LOW);
}

void loop() {
    
}

Credits

Zachary Bellflower

Zachary Bellflower

1 project • 0 followers
Xavier

Xavier

1 project • 0 followers
Ash Rai

Ash Rai

0 projects • 0 followers

Comments