#include <LiquidCrystal.h>
#include <Servo.h>
const int LDR_PIN = A0; // Analog pin connected to LDR
const int POT_PIN = A1; // Analog pin connected to potentiometer
const int RS_PIN = 12; // Register select pin of LCD
const int EN_PIN = 11; // Enable pin of LCD
const int D4_PIN = 5; // Data pin 4 of LCD
const int D5_PIN = 4; // Data pin 5 of LCD
const int D6_PIN = 3; // Data pin 6 of LCD
const int D7_PIN = 2; // Data pin 7 of LCD
const int SERVO_PIN = 9; // Digital pin connected to servo motor
LiquidCrystal lcd(RS_PIN, EN_PIN, D4_PIN, D5_PIN, D6_PIN, D7_PIN);
Servo servoMotor;
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
servoMotor.attach(SERVO_PIN);
}
void loop() {
int lightIntensity = analogRead(LDR_PIN); // Read the analog value from LDR
int stabilityValue = analogRead(POT_PIN) / 4; // Read the analog value from the potentiometer and divide by 4 for stability adjustment
lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
lcd.print("Light Intensity:");
lcd.setCursor(0, 1); // Set the cursor to the first column of the second row
lcd.print(lightIntensity);
if (lightIntensity < 250 + stabilityValue) {
servoMotor.write(90); // Move the servo motor to 90 degrees
} else {
servoMotor.write(0); // Move the servo motor to 0 degrees
}
delay(1000); // Wait for 1 second
}