#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 4 // DHT22 data pin connected to GPIO4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address based on your setup
const int potPin = 34; // Potentiometer connected to GPIO34
void setup() {
Serial.begin(115200);
dht.begin();
LiquidCrystal_I2C begin();
lcd.backlight();
pinMode(potPin, INPUT);
}
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
int potValue = analogRead(potPin);
// Convert potentiometer value to a range (example: threshold setting)
int threshold = map(potValue, 0, 4095, 0, 100);
if (isnan(temp) || isnan(hum)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Display values on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Hum: ");
lcd.print(hum);
lcd.print(" %");
// Additional logic based on threshold and sensor values
if (temp > threshold) {
// Take some action
}
delay(2000); // Wait a few seconds between readings
}