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

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top