#include <PID_v1_bc.h>
const int ldrPin = A0; // Analog pin for LDR
const int buzzerPin = 5; // Digital pin for buzzer
double setpoint = 0; // Desired light intensity value
double input, output; // Variables for PID controller
PID myPID(&input, &output, &setpoint, 1, 0.1, 0.1, DIRECT);
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
myPID.SetMode(AUTOMATIC);
}
void loop() {
input = analogRead(ldrPin); // Read LDR value
setpoint = map(input, 0, 1023, 1023, 0); // Map LDR value to inverse range for light intensity (adjust as needed)
myPID.Compute(); // Compute PID control
analogWrite(buzzerPin, output); // Set buzzer sound
}