#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define PIR_PIN 25
#define LED_PIN 23
#define NTC_PIN 34
#define LCD_PIN 21
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C LCD(0x27, 20, 4); // Adjust address if necessary
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
LCD.begin(20,4);
LCD.backlight();
}
void loop() {
int motionDetected = digitalRead(PIR_PIN);
if (motionDetected == HIGH) {
float temperature = readTemperature();
LCD.setCursor(0, 0);
LCD.print("Temp: ");
LCD.print(temperature);
LCD.print(" C");
if (temperature < 10) {
digitalWrite(LED_PIN, HIGH);
LCD.setCursor(0, 1);
LCD.print("LED On ");
}
delay(5000); // Wait for 5 seconds for the PIR sensor to reset
} else {
digitalWrite(LED_PIN, LOW);
LCD.clear();
}
}
float readTemperature() {
int rawValue = analogRead(NTC_PIN);
float voltage = (rawValue / 4095.0) * 3.3; // Assuming 3.3V reference
float resistance = (3.3 / voltage) - 1; // Calculate the resistance of the NTC
float temperature = 1.0 / (0.001129148 + 0.000234125 * log(resistance) + 0.0000000876741 * log(resistance) * log(resistance) * log(resistance)); // Steinhart-Hart equation
return temperature - 273.15; // Convert from Kelvin to Celsius
}