Physical Shutdown Button for Raspberry Pi





Introduction: Physical Shutdown Button for Raspberry Pi

Sometimes I wondered, there should be a physical shutdown button on raspberry pi, to safely down the device, because direct shutdown of raspberry pi could damage the SD card or File system. SO i added of my own. Here is how.

Circuit Dig-

added a push button to BCM GPIO 23. Another end of Push button to the 3.3V that is Pin Number One.

write two code, one is python to read continuously the Gpio 23, and other shell script to run the python file. and

put the shell sctipt to the crontab to start on system reboot.

To install software on Your RPI board.

1. Download the code, By typing bellow command on your shell window.

"git clone" ---> without quote "" else you can find the code bottom of this article.

give executable permission to both the file by chmod +x

2. Open the file,

and give the path of the file, and save it.

3. Crontab is a demon which starts when RPI boot, it runs in background. we have to add our code to crontab to run continuous in background. Open crontab, By following command

"sudo crontab -e4"

Add the following line at bottom of the crontab

"@reboot sh /home/pi/Your/filePath/"

Then save the crontab by ctrl+x5.Then Simply reboot the system.

Now Power on you RPI. The will run in background automatically.

Once you will press your button. It will Shutdown Your device safely.

Here is a video , which i am running on my device.

If You have doubt regarding installation and code, You can comment bellow. Thanks. Happy Learning.

Step 1:



    • Epilog Challenge 9

      Epilog Challenge 9
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.




    how do you restart it ?

    If you pull pin05 (GPIO03 SCL,I2C) to ground, it will restart.

    New Raspberry Pi user question: Would this work on the Pi Model 2 B+?