This is taken from the show #76 for reference. This allows you to add in a Shutdown and or Reboot button to the Raspberry Pi’s GPIO port. I take no credit about it, just wanting to spread the word as I could find nothing on this while searching till I watched the AmateurLogit.TV Web-Show # 76. I do suggest you watch the Show at AmateurLogic.TV # 76 before starting this.

First let us take a look at the GPIO PINOUT s for the various PI’s not the PI 2 Quad core; although, it may be similar. Using pins 1-26 and they appear the same if not similar across the various PI’s. If you have one that is different then please check your pinouts please.

For this example Tommy Martin  (N5ZNO) used Header Pins 16 (SIGNAL – GPIO-23) & 14(GND) and  Pins 22 (SIGNAL –  GPIO-25) & 20 (GND ). The software calls it by the GPIO pin number, but the number is different on the actual Header;



GPIO-23      =   16

GPIO-25      =    22






import RPi.GPIO as gpio

import time

import os






gpio.setup(SHUTDOWN_PIN, gpio.IN, pull_up_down = gpio.PUD_UP)

gpio.setup(REBOOT_PIN, gpio.IN, pull_up_down = gpio.PUD_UP)

def Shutdown(channel):

os.system(“sudo shutdown -h now”)

def Reboot(channel):

os.system(“sudo reboot”)


gpio.add_event_detect(SHUTDOWN_PIN, gpio.FALLING, callback = Shutdown, bouncetime = 500)

gpio.add_event_detect(REBOOT_PIN, gpio.FALLING, callback = Reboot, bouncetime = 500)

while 1:



FIGURE 2 (Sort of)

 I used some of the jumper wires I have for my Arduino and two Radio Shack (Normally Open) N/O  Momentary  push button, buttons. If you choose to add this to a DVAP or something, you may want to use other buttons that will be recessed somewhat into the case so as not to easily bump them and reboot/shutdown your PI inadvertently. I took 4 of the jumper wires below in figure 3 and just physically pulled off one end of then so as to solder the four wires (in two pairs) to the Reboot and Shutdown Buttons. One side of the button goes to GND (Ground) and the other to the GPIO Pin on the header pinout.


FIGURE 3 (Shows the jumper wires I used, but only 4 of them.

 Figure 4 shows how that I first had to drill the holes for the buttons and after I soldered the four wires this shows how the wiring is placed into the case.



 Then finally assembled the Figure 5 shows how the unit appears and does function quite nicely.



  I have saved the hard work for last. The good thing is there isn’t a lot of it. Now we need to add in the software monitors for the buttons. I will place everything between asterisks again to show what could be used and just copied to your command window,

Add watchdog to reboot or shutdown Add this if you want to later add the Reboot/Shutdown buttons.


# verifies it is there.

echo “bcm2708_wdog” | sudo tee -a /etc/modules

sudo modprobe bcm2708_wdog

sudo cat /etc/modules


sudo apt-get install watchdog chkconfig -Y

sudo chkconfig watchdog on

sudo /etc/init.d/watchdog start


#get just incase

sudo apt-get install watchdog

sudo /etc/init.d/watchdog start


#make sure it runs on every boot

sudo update-rc.d watchdog defaults


This next part you must edit:

sudo nano /etc/watchdog.conf


Change the following to look similar or exactly the same:

make sure to  uncomment “#watchdog-device”



Make sure uncomment “#max-load-1          = 24”

max-load-1              = 24


Then save your work. And execute the following in your command window. (what is between the asterisks again.)

sudo chkconfig watchdog on


sudo systemctl start watchdog.service


Well folks tthis about sums it up and if you have any troubles, you can watch the show at AmateurLogic.TV, which I recommend before doing this anyway; or, contact me here.


Ben ARS w4qed

P.S. my PI does duty here as a low powered webserver at also working on it to do duty as a Home Automation System using MisterHouse; but, that is another article (maybe).