#include <LiquidCrystal_I2C.h>
// Initialize the library with the I2C address, columns, and rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600); // Start the Serial communication
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(3, OUTPUT); // Set pin 3 as an output
}
void loop() {
int ldrVal = analogRead(A3); // Read the LDR value from analog pin A3
Serial.println(ldrVal); // Print the LDR value to the Serial monitor
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set the cursor to the first column, first row
lcd.print("LDR value"); // Print "LDR value" on the LCD
lcd.setCursor(0, 1); // Set the cursor to the first column, second row
lcd.print(ldrVal); // Print the LDR value on the LCD
if (ldrVal < 80) {
analogWrite(3, 200); // Write a value of 200 to pin 3 if the LDR value is less than 80
} else {
analogWrite(3, LOW); // Turn off the output to pin 3 if the LDR value is 80 or more
}
delay(200); // Delay for 200 milliseconds
}