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 https://github.com/embeddedhacks/physicalShutdown" ---> without quote "" else you can find the code bottom of this article.

give executable permission to both the file by chmod +x filename.py

2. Open the lunchshutdown.sh file,

and give the path of the shutdown.py 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/lunchShutdown.sh"

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

Now Power on you RPI. The lunchshutdown.sh 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.

www.embbsys.blogspot.in

Step 1:

Comments

author
Superlugol made it! (author)2015-05-04

how do you restart it ?

author
CraigMarston made it! (author)CraigMarston2015-09-03

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

author
TannerKHax made it! (author)2015-04-27

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

author
Austinthemighty made it! (author)Austinthemighty2015-04-29

yes, it will

About This Instructable

6,835views

62favorites

License:

Bio: Blogger, Hacker, Embedded Product Designer :)
More by satyasankar09:ESP8266 OTA Tutorial - Over the Air UpdatePlay Music using Arduino and Buzzer Raspberry PI GPIO Control Using C
Add instructable to: