int LDR_PIN = A0;
int LAMP_PIN = 3;
int BELL_PIN = 4;
int MOTION_PIN = 2;
void setup() {
pinMode(LDR_PIN, INPUT);
pinMode(MOTION_PIN, INPUT);
pinMode(LAMP_PIN, OUTPUT);
pinMode(BELL_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int lightLevel = analogRead(LDR_PIN);
// Read the light level
int motionDetected = digitalRead(MOTION_PIN);
// Check for motion
if (lightLevel < 512 && motionDetected == HIGH) {
digitalWrite(LAMP_PIN, HIGH);
digitalWrite(BELL_PIN, HIGH);
tone(4,262,250);
} else if (lightLevel >= 512 && motionDetected == HIGH) {
digitalWrite(LAMP_PIN, LOW);
digitalWrite(BELL_PIN, HIGH);
tone(4,262,250);
} else {
digitalWrite(LAMP_PIN, LOW);
digitalWrite(BELL_PIN, LOW);
}
delay(100);
}