int status = 22; // Output pin (e.g., an LED)
int sensor = 21; // Input pin for the motion sensor
void setup()
{
Serial.begin(9600); // Start serial communication
pinMode(status , OUTPUT); // Set the status pin as an OUTPUT
pinMode(sensor, INPUT); // Set the sensor pin as an INPUT
}
void loop()
{
// Read the state of the motion sensor pin
int sensorState = digitalRead(sensor);
if(sensorState == HIGH) // If motion is detected (HIGH signal from sensor)
{
Serial.println("Motion detected");
digitalWrite(status, HIGH); // Turn on the status output (e.g., LED)
delay(1000); // Wait for 1 second
}
else // If no motion is detected (LOW signal from sensor)
{
Serial.println("Motion not detected");
digitalWrite(status, LOW); // Turn off the status output (e.g., LED)
delay(1000); // Wait for 1 second
}
}