This example shows how to use the Grove PIR motion sensor.
This demo requires the Grove PIR motion sensor and PYNQ Grove Adapter.
Download the overlay. Instantiate Grove PIR object.
In this example, the Grove PIR sensor is assumed to be connected to G1 on the PYNQ Grove Adapter. The Grove Adapter is connected to PMODA interface on board.
In [1]:
from time import sleep
from pynq import Overlay
from pynq.board import LED
from pynq.iop import Grove_PIR
from pynq.iop import PMODA
from pynq.iop import PMOD_GROVE_G1
ol1 = Overlay("base.bit")
ol1.download()
pir = Grove_PIR(PMODA,PMOD_GROVE_G1)
In [2]:
led = LED(0)
led.on()
if pir.read()==0:
print("Starting detection...")
while True:
led.on()
sleep(0.1)
led.off()
sleep(0.1)
if pir.read()==1:
print("Detected a motion.")
break
print("Ending detection...")
In [3]:
del pir
del led
del ol1