RaspberryPi shutdown button

Last Friday I got some spare time (finally!) and, with the help and tools of my friend Alfredo, we placed a button in the RaspberryPi case so, when I push it, a custom command its executed on the RaspberryPi, like for example, a clean system shutdown.

RaspberryPi shutdown button

We mainly followed this post, but used a different GPIO port, we soldered the components (once we tested the schematics on a protyping board) and modified the code to launch a custom command. This is the resulting code we used to do a system shutdown (I removed some comments from the original code of the post):

The line highlighted is the one you should modify to set your custom command. To test it, you have to execute it as root:

RaspberryPi shutdown button board+schematic

and press the button. Finally, to launch this code in the startup process, just add it to /etc/rc.local (just before the exit 0):

Easy peasy!


For more detail: RaspberryPi shutdown button

About The Author

Scroll to Top
Read previous post:
Voice– and SMS–Enabled Light Sensor Using Raspberry Pi and Twilio

Overview The Hacker School space for our batch had two restrooms: one attached to the main work area, and one...