int button = 2; // Push button connected to pin 2
int relay = 6; // Relay module connected to pin 8
int buzzer = 7; // Active buzzer connected to pin 7
int buttonState = 0;
void setup() {
pinMode(button, INPUT); // Internal pull-up resistor
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(button);
Serial.print("Button State: ");
Serial.println(buttonState);
if (buttonState == HIGH) { // Button pressed
// Faraacha lights ON
digitalWrite(relay, HIGH);
digitalWrite(buzzer, HIGH);
delay(200);
// Faraacha lights OFF
digitalWrite(relay, LOW);
digitalWrite(buzzer, LOW);
delay(200);
}
else {
// All off when button not pressed
digitalWrite(relay, LOW);
digitalWrite(buzzer, LOW);
}
}