from machine import deepsleep
from machine import Pin
from time import sleep
import esp32
from machine import reset_cause
from machine import DEEPSLEEP_RESET
# check if the device woke from a deep sleep

wake1 = Pin(13, mode = Pin.IN)
#level parameter can be: esp32.WAKEUP_ANY_HIGH or esp32.WAKEUP_ALL_LOW
esp32.wake_on_ext0(pin = wake1, level = esp32.WAKEUP_ALL_LOW)
# check if the device woke from a deep sleep

if reset_cause() == DEEPSLEEP_RESET:
  print('woke up from a deep sleep')

motion = False
def handle_interrupt(pin):
  global motion
  motion = True
  global interrupt_pin
  interrupt_pin = pin
led = Pin(4, Pin.OUT)
pir = Pin(13, Pin.IN)
pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
while True:
    print('scanning..........')
    if motion:
        print('MOTION DETECTED')
        led.value(1)
        sleep(10)
        led.value(0)
        print('MOTION STOPPED')
        motion = False
        sleep(10)
        print('Going to deepsleep')
        deepsleep()
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
NOCOMNCVCCGNDINLED1PWRRelay Module
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
pir1:VCC
pir1:OUT
pir1:GND