I've been searching for some examples of using a PIR and waking up the ESP32 (NodeMCU ESP32S v1.1) when the PIR detects motion, but I'm yet to find anything that works.
MicroPython v1.10-227-g696549d2e on 2019-03-17
My code is very simple and would appreciate suggestions where to put the ESP in deepsleep and wakeup when the PIR detects motion.
Code: Select all
>>> import machine as m
>>> pir = m.Pin(13, Pin.IN)
>>>
>>> def handle_interrupt(pin):
... global motion
... motion = True
... global interrupt_pin
... interrupt_pin = pin
...
...
...
>>> pir.irq(handle_interrupt,(m.Pin.IRQ_RISING))
<IRQ>
>>> while 1:
... if motion:
... print('Motion detected on: {}'.format(interrupt_pin))
... sleep(10)
... print('Motion stopped')
... motion = False
...
...
...
Motion detected on: Pin(13)
Motion stopped
Motion detected on: Pin(13)
Motion stopped