#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LDR_PIN A0 // Change LDR_PIN to the appropriate analog pin for your LDR
#define NTC_PIN A1 // Change NTC_PIN to the appropriate analog pin for your NTC temperature sensor
#define LED_PIN 13 // Define the pin number for the first LED
#define SECOND_LED_PIN 11 // Define the pin number for the second LED
#define BUZZER_PIN 8 // Define the pin number for the buzzer
// Define the predefined light threshold value
const int predefinedLightValue = 200; // Change this value to your predefined light level
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
pinMode(LDR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT); // Set first LED pin as an output
pinMode(SECOND_LED_PIN, OUTPUT); // Set second LED pin as an output
pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as an output
lcd.init();
lcd.backlight();
lcd.begin(20, 4); // Initialize LCD screen for 20x4 display
}
void loop() {
int ldrValue = analogRead(LDR_PIN); // Read LDR value
ldrValue = constrain(ldrValue, 0, 300); // Limit LDR value to maximum 300
int ntcValue = analogRead(NTC_PIN); // Read NTC temperature sensor value
lcd.clear(); // Clear the LCD display before printing new values
lcd.setCursor(0, 0);
lcd.print("LDR Value: ");
lcd.print(ldrValue);
lcd.setCursor(0, 1);
lcd.print("Room: ");
if (ldrValue < predefinedLightValue) { // Compare with predefined value
lcd.print("Dark ");
digitalWrite(LED_PIN, HIGH); // Turn on first LED when it's dark
lcd.setCursor(0, 2);
lcd.print("AL: ON");
} else {
lcd.print("Light!");
digitalWrite(LED_PIN, LOW); // Turn off first LED when it's light
lcd.setCursor(0, 2);
lcd.print("AL: OFF");
}
lcd.setCursor(0, 3);
lcd.print("NTC Temp: ");
float temperature = map(ntcValue, 0, 1023, 0, 100); // Convert analog value to temperature (0-100°C)
// Ensure temperature doesn't go below indicated degrees
temperature = max(temperature, 70);
lcd.print(temperature);
lcd.print(" C");
// Check if temperature is below 75 degrees and turn on the second LED
if (temperature < 75) {
digitalWrite(SECOND_LED_PIN, HIGH); // Turn on second LED
} else {
digitalWrite(SECOND_LED_PIN, LOW); // Turn off second LED
}
// Check if temperature is below 80 degrees and beep the buzzer
if (temperature < 80) {
tone(BUZZER_PIN, 1000); // Generate a beep sound
delay(100); // Beep duration
noTone(BUZZER_PIN); // Stop the beep
}
delay(5000); // Adjust delay as necessary
}