This is my first post, so apologies if it’s in the wrong place…!
OFF OFF, not standby off!
Because I wanted to build a Pi-based system that completely switches off from the mains, I needed to monitor the GPIO pins to establish when the Pi was truly OFF…! (There are many clever devices already on the market that will manage the Pi’s power, but none I could find that would completely and utterly switch the Pi and its power supply off.)
Using a hand-held oscilloscope I discovered that, uniquely; GPIO 14 (pin 8) drops from a pulsed high of 3.4 V down to just a few millivolts when the Pi shuts down:
Annotated GPIO pin-out diagram, showing pins that hint at the Pi’s power status.
Using this fact, a simple indicator can be built (using a PNP transistor, resistors and LED) which gives the ‘OK’ to pull the power:
Simple circuit diagram for indicating when a pin has gone low, in this case GPIO 14 on the RaspberryPi. This is handy, when combined with a shutdown button (see the links at the end!), for headless Pi units.
Shutting the power off
Now, there are many examples of code which instruct the Pi to shutdown cleanly, but now I need something that monitors the shutdown, and then ‘pulls the plug’ automatically: All that is needed is a simple microcontroller to monitor GPIO 14 (with a slight delay to cater for the pulsed output), wait for a second of so to ensure complete shutdown, then turn off the relay. I used a PICAXE for this, but any µC can be used. (I can supply the PICAXE code to anyone interested)
I won’t provide any details regarding mains electricity: This is not something to be meddled / dabbled / fiddled with!
There are ways to do this safely with wireless remote mains sockets, for example.