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.
Things used in this project
Hardware components
Story
In this project, we use a moisture sensor, a temperature/humidity sensor, and an RGB light to detect moisture and temperature levels. If the soil moisture is too low, the RBG light will blink red. If the temperature is too high, since a higher temperature will dry out the soil quicker, the RGB light will blink green.
This solves the problem of people not knowing when to water their plants, and prevents the problem of overwatering plants. This device is useful because it will remind you automatically, instead of having to remember yourself. Somebody would want this because it will help keep their plants watered and help prevent overwatering their plants. This project is novel because it combines the moisture and temperature sensors instead of them being on their own, along with an alert, so it is quite a lot in one device. Our newly acquired IOT skills allow us to program the sensor to do all of the things that it does. Without them, the sensors would only work by themselves, and not work in unison to create this unique device.
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
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() {
}
The article was first published in hackster, April 22, 2021
cr: https://www.hackster.io/group-31/temperature-and-moisture-sensors-with-alert-42d2af
author: Team Group 31: Zachary Bellflower, Xavier, Ash Rai