pmod_grove_pir


PMOD Grove PIR Motion Sensor

This examples shows how to use the Grove PIR motion sensor.

This demo requires the Grove PIR motion sensor and PYNQ Grove Adapter.

1. Download overlay

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)

2. Detect motion

We can now start the motion detection loop.

When the cell below is executed, the LED will keep flashing until the PIR detects some movement.


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...")


Starting detection...
Detected a motion.
Ending detection...

3. Clean-up

Delete objects.


In [3]:
del pir
del led
del ol1