const int led = 7; // LED connected to digital pin 7
const int sensor = 5; // PIR sensor connected to digital pin 5
const int button = 9; // Push button connected to digital pin 9
int sensorVal = 0; // Variable to store sensor value
int buttonVal = 0; // Variable to store button value
void setup() {
pinMode(led, OUTPUT); // Set the LED as an output
pinMode(sensor, INPUT); // Set the PIR motion sensor as an input
pinMode(button, INPUT); // Set the push button as an input
Serial.begin(9600); // Initialize serial communication at 9600 baud rate
}
void loop() {
sensorVal = digitalRead(sensor); // Read the sensor value
buttonVal = digitalRead(button); // Read the button state
if (sensorVal == HIGH || buttonVal == HIGH) { // If motion detected or button pressed
digitalWrite(led, HIGH); // Turn the LED on
Serial.println("Motion detected or button pressed"); // Print message
}
else {
digitalWrite(led, LOW); // Turn the LED off
Serial.println("No motion and button not pressed"); // Print no action message
}
delay(500); // Delay for 500 milliseconds
}