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.


Step 1:

<p>how do you restart it ? </p>
<p>If you pull pin05 (GPIO03 SCL,I2C) to ground, it will restart.</p>
New Raspberry Pi user question: Would this work on the Pi Model 2 B+?
<p>yes, it will</p>

About This Instructable




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