#include <LiquidCrystal.h>
#include "DHT.h"
// Define pins for the LCD
const int rs = 23, en = 22, d4 = 21, d5 = 19, d6 = 18, d7 = 5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Define DHT sensor
#define DHTPIN 15 // Pin connected to the DHT22
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
// Define LDR pins
const int ldrAnalogPin = 34; // LDR analog pin (A0)
const int ldrDigitalPin = 26; // LDR digital pin (D0)
// Define other sensors' pins if needed (example for MQ-135, change pins accordingly)
const int mq135Pin = 36; // Example pin for MQ-135
void setup() {
// Initialize the LCD
lcd.begin(16, 2);
// Initialize the DHT sensor
dht.begin();
// Set up the LDR digital pin
pinMode(ldrDigitalPin, INPUT);
// Set up MQ-135 analog pin
pinMode(mq135Pin, INPUT);
// Print an initial message to the LCD
lcd.print("Initializing...");
delay(2000);
}
void loop() {
// Read temperature and humidity from DHT22
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read LDR values
int ldrAnalogValue = analogRead(ldrAnalogPin);
int ldrDigitalValue = digitalRead(ldrDigitalPin);
// Example reading from MQ-135 (replace with actual logic if needed)
int mq135Value = analogRead(mq135Pin);
// Clear the LCD for fresh output
lcd.clear();
// Display temperature and humidity
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
// Display LDR analog value
lcd.setCursor(0, 0);
lcd.print("LDR: ");
lcd.print(ldrAnalogValue);
// Check if light threshold is crossed based on LDR digital pin
if (ldrDigitalValue == HIGH) {
lcd.setCursor(0, 1);
lcd.print("Light detected");
} else {
lcd.setCursor(0, 1);
lcd.print("Low light");
}
// If using MQ-135, display the value as well
lcd.setCursor(0, 0);
lcd.print("MQ-135: ");
lcd.print(mq135Value);
// Delay before next reading
delay(2000);
}