How i manage power on my PI. I also use a timer relay to cut power completly after 30min but this works really nice as a complement. I thought something this simple and cheap can be usefull to someone!
Parts list:
BC547 Transistor
2x 1kohm Resistors
1x 12v to 5v regulator
Regulator at amazon (Listing is for 5x regulators, but you could always use 1 for your backup camera trigger)
Total cost for components is like under 5$ excluding a timer relay, i guess its caveman style but heck who wants to pay 100 euro for a hat that does basicly the same thing
Wakes PI from sleep if ignition goes live. Gracefully shut down PI if ignition goes off. Cancels shutdown if ignition goes on before 15min. I have a more complex script wich shutdown power to the LCD and USB devices when ignition goes off as well but ill release it together with the complete Volvo P1 package on github a bit later
Wiring (ps the components are not in scale, more realisticly they all fit tightly together on your thumb):
![[Image: pi-power-switch.png]](https://i.ibb.co/QXSd8c3/pi-power-switch.png)
Script:
Make it executable
sudo chmod +x /home/pi/power_monitor.py
Make it start on boot:
sudo nano /etc/rc.local
Add this line: sudo python /home/pi/power_monitor.py &
power_monitor.py
Parts list:
BC547 Transistor
2x 1kohm Resistors
1x 12v to 5v regulator
Regulator at amazon (Listing is for 5x regulators, but you could always use 1 for your backup camera trigger)
Total cost for components is like under 5$ excluding a timer relay, i guess its caveman style but heck who wants to pay 100 euro for a hat that does basicly the same thing
Wakes PI from sleep if ignition goes live. Gracefully shut down PI if ignition goes off. Cancels shutdown if ignition goes on before 15min. I have a more complex script wich shutdown power to the LCD and USB devices when ignition goes off as well but ill release it together with the complete Volvo P1 package on github a bit later

Wiring (ps the components are not in scale, more realisticly they all fit tightly together on your thumb):
![[Image: pi-power-switch.png]](https://i.ibb.co/QXSd8c3/pi-power-switch.png)
Script:
Make it executable
sudo chmod +x /home/pi/power_monitor.py
Make it start on boot:
sudo nano /etc/rc.local
Add this line: sudo python /home/pi/power_monitor.py &
power_monitor.py
#! /usr/bin/env python
import time
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pin = 3 // pin 5 is gpio 3
GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)
while True:
button_state = GPIO.input(pin)
if button_state == GPIO.HIGH:
subprocess.call(['shutdown', '-h', '15'], shell=False) // change 15 to whatever delay you want or to "now" if you do not want any.
print ("Ignition off")
else:
subprocess.call(['shutdown', '-c'], shell=False)
print ("Ignition on")
time.sleep(5)