#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define I2C LCD address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address if needed
// Define the analog pin for the temperature sensor
const int tempSensorPin = 34; // ESP32 analog pin
const int PIR = 25;
void setup() {
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Temp & Humid");
// Set the analog pin
pinMode(tempSensorPin, INPUT);
pinMode(PIR, INPUT);
delay(2000); // Display the welcome message
lcd.clear();
}
void loop() {
// Read the analog value from the sensor
int analogValue = analogRead(tempSensorPin);
// Convert the analog value to voltage
float voltage = analogValue * 3.3 / 4095.0;
// Convert voltage to temperature (LM35: 10mV per degree Celsius)
float temperatureC = voltage * 100.0;
// Clear and update the LCD display
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
// Add a delay for readability
delay(1000);
int Motion=digitalRead(PIR);
if (PIR == HIGH) {
lcd.setCursor(0, 0);
lcd.print("Motion: Detected");
}
else {
lcd.setCursor(0, 0);
lcd.print("NO MOTION");
}
}