#include <DHT.h>
#include <LiquidCrystal.h>
const int rs=12, en=11, d4=10, d5=9, d6=8, d7=7;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
#define MQ2_ANA A1
#define DHT_PIN 2
#define DHT_TYPE DHT22
DHT dht(DHT_PIN, DHT_TYPE);
int buzzerPin = 9;
const float TEMP_MIN = 18.0;
const float TEMP_MAX = 30.0;
const float HUMIDITY_MIN = 60.0;
const float HUMIDITY_MAX = 70.0;
const int CO2_THRESHOLD = 400;
void setup() {
Serial.begin(9600);
pinMode(MQ2_ANA, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
dht.begin();
lcd.begin(16,2);
lcd.print("Plant Monitoring");
lcd.setCursor(0,1);
lcd.print("System");
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int gasValue = analogRead(M_2_PI);
float co2 = map(gasValue, 0, 1023, 0, 2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Hum:");
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(8, 1);
lcd.print("CO2:");
lcd.print(co2);
if(temperature >= TEMP_MIN && temperature <= TEMP_MAX){
Serial.println("Temperature is optimal for the plant growth.");
}
else{
digitalWrite(LED_BUILTIN, HIGH);
buzzBuzzerTwice();
Serial.println("This temperature can cause stress and impact plant growth.");
if(temperature <= TEMP_MIN){
Serial.println("The temperature is below 18° Celcuis");
}
else{
Serial.println("The temperature is above 30° celcius");
}
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
}
if(humidity >= HUMIDITY_MIN && humidity <= HUMIDITY_MAX){
Serial.println("Humidty is optimal for the plant growth");
}
else{
digitalWrite(LED_BUILTIN, HIGH);
buzzBuzzerThrice();
Serial.println("This humidity can cause stress and impact plant growth.");
if(humidity >= HUMIDITY_MAX){
Serial.println("Humidity above 70% can increase the risk of fungal diseases such as blight and powdery mildew");
}
else{
Serial.println("Humidity below 60% can cause dehydration and increased susceptibility to pests.");
}
digitalWrite(LED_BUILTIN, LOW);
}
if(co2 < CO2_THRESHOLD){
Serial.println("This amount of CO2 is enough for good plant growth");
}
else{
Serial.println("Enriched level!!!! This will help our plants to grow faster and produce more!!!");
}
Serial.println("");
delay(5000);
}
void buzzBuzzerTwice() {
for (int i = 0; i < 2; i++) {
tone(buzzerPin, 1000, 500);
delay(1000); // Wait for 1 second
}
}
void buzzBuzzerThrice() {
for (int i = 0; i < 3; i++) {
tone(buzzerPin, 100, 500);
delay(1000); // Wait for 1 second
}
}