/ Raspberry_Pi_Power_Control / Raspberry_Pi_Power_Control.py
Raspberry_Pi_Power_Control.py
 1  # SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  import board
 7  from digitalio import DigitalInOut, Direction
 8  
 9  pir_pin = board.D24
10  power_pin = board.D23
11  
12  pir = DigitalInOut(pir_pin)
13  pir.direction = Direction.INPUT
14  
15  power = DigitalInOut(power_pin)
16  power.direction = Direction.OUTPUT
17  power.value = False
18  
19  while True:
20      if pir.value:
21          print("POWER ON")
22          power.value = True
23          time.sleep(20)
24          print("POWER OFF")
25          power.value = False
26          time.sleep(5)
27      time.sleep(1)