Le code pour utiliser le capteur de mouvement PIR est le suivant:
#
from machine import Pin
from time import sleep
from network import WLAN
#Stop wifi
wifi = WLAN()
wifi.active(False)
#print(wifi.active())
motion = False
def handle_interrupt(pin):
global motion
motion = True
global interrupt_pin
interrupt_pin = pin
pir = Pin(14, Pin.IN) #D7
pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
i=0
while True:
if motion:
print(i,'MOTION DETECTED')
sleep(5)
i+=1
print('MOTION STOPPED')
motion = False