Files
AsiaBackend/proximity_default.py
Justin Eckenweber dc442f29bc switched to gitea
2026-05-20 10:29:00 +02:00

27 lines
561 B
Python

import RPi.GPIO as GPIO
import time
sensor_pin = 22
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor_pin, GPIO.IN)
state = 0
try:
while True:
val = GPIO.input(sensor_pin)
if val == 1:
#GPIO.output(led_pin, GPIO.HIGH)
if state == 0:
print("Motion detected!")
state = 1
else:
#GPIO.output(led_pin, GPIO.LOW)
if state == 1:
print("Motion stopped!")
state = 0
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()