port: |
Grove: A1 (C16, C17) |
interface: | digital |
output values |
1/0, high/low |
Further information: | https://wiki.seeedstudio.com/Grove-PIR_Motion_Sensor/ |
Order: | https://www.amazon.de/Seeedstudio-Grove-PIR-Motion-Sensor/dp/B01AFKOO6K |
With the PIR (pyroelectric or passive infrared sensor) heat changes in the environment are measured. This can be used, for example, to create a motion detector or an alarm system that is activated when a person approaches the sensor. This is because the sensor reacts to the heat radiation of our body.
Makecode
There are two ways to address the sensor.
The first way is to read out the digital value of pin C16 and to check in an if/then branch whether the sensor values are 1 or 0.
The second variant can be realized with the block "if pin P0 pulsed high" which can be found under "Pin > more". For this, the pin must be set to C16, which means that any action can be performed, such as lighting the status LED.
Python
Die digitalen Werte des PIR-Sensor können z.B. über den Grove Pin pin_A1_RX über die Funktion digitalread() ausgelesen werden und in einer Variable pir_sensor gespeichert werden:
pir_sensor = pin_A1_RX.read_digital()
Anschließend kann der Zustand des Sensors in einer wenn/dann-Verzweigung abgefragt werden. Ist der Wert 1 wird eine Bewegung wahrgenommen, ansonsten (bei 0) wird keine Bewegung erkannt:
from calliopemini import *
while True:
pir_sensor = pin_A1_RX.read_digital()
if pir_sensor == 1:
display.show(Image.YES)
else:
display.show(Image.NO)