From 5522a8bf275fae0ba5d5d6a9e3319e26833c565d Mon Sep 17 00:00:00 2001 From: Mubaraq Olayinka Date: Tue, 30 Jul 2024 11:53:13 +0100 Subject: [PATCH] event detection --- sensor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sensor.py b/sensor.py index ad208f4..02995c5 100644 --- a/sensor.py +++ b/sensor.py @@ -21,3 +21,13 @@ def on_motion_detected(channel): print("Motion Detected!") client.publish(MQTT_TOPIC, "Motion Detected") + +# Add event detection on the PIR pin +GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=on_motion_detected) + +try: + print("PIR Module Test (CTRL+C to exit)") + time.sleep(2) # to stabilize sensor + print("Ready") + +