I have a Raspberry Pi that I want to mount in an enclosure. The enclosure already has a couple external buttons on it. I'm trying to find some sort of circuit that I could by that I could wire the buttons to, in order to properly shutdown and turn on the Raspberry Pi. By properly, I don't mean "cut the power" to shutdown. I mean an actual Linux shutdown command. I have found the following products:

But what is the deal with the buttons that these companies put on their circuit boards? If you enclose any of those products in an enclosure with an Raspberry Pi, NONE of those included buttons could be accessed externally.

Do people actually use the circuit boards just like that? Aren't there any similar products out there that just have some headers/leads on them that I could plug directly to?

I'm not good at soldering onto circuit boards last I tried it, so I'd prefer to find something that is simply plug and play but that has the ability for an external button to be added instead of some useless surface mount button. I need the circuit to be able to power up the Raspberry Pi and properly send a shutdown signal as well.

  • 1
    You could just use a script to watch a GPIO pin and run shutdown -h now when it is pulled low.
    – user8894
    Nov 22, 2014 at 21:00
  • I will have to look into that. If a solution is that easy, then how to people justify buying these special switches that I linked above? What is the point of those if you can just wire a switch directly to the GPIO pins? Also, can I power the RPi on using the same GPIO pins? Nov 22, 2014 at 21:17
  • you may want to look into programming in python so that when you press the button it runs the command sudo shutdown Nov 22, 2014 at 21:48
  • @Jakobud Is your primary concern to save power on the raspberry Pi or shutdown it using a button? Nov 26, 2014 at 3:46
  • Just shutdown and power it back up. It's going to be plugged in all the time. Nov 26, 2014 at 7:22

3 Answers 3


It is trivial to write a script that runs the shutdown command on button press. The complication comes from people who want to power down the Pi. Unless you are using batteries this seems pointless.

It is simple to "restart" the B or B+ from the halt state see https://raspberrypi.stackexchange.com/a/23725/8697

  • Can the switch also be used to power on the device though? Thinking of like a toggle/rocker switch. Switching to off, runs the shutdown script. Switching to on, powers on the Pi somehow... Is that possible with the GPIO headers? Nov 23, 2014 at 3:57
  • @Jakobud Not without some additional circuitry. You could connect one button to GPIO to STOP and another to the Run on B+ or P6 on the B. It may be possible to just use a push button on pin 5 to START/STOP.
    – Milliways
    Nov 23, 2014 at 5:52
  • @Milliways It is always beneficial to draw minimum power from the wall. Why it is pointless to avoid power savings? Just curious. Nov 24, 2014 at 4:30
  • @ChetanBhargava in principle yes, however as an engineer I am used to cost benefit analysis. The Pi uses ~3W @ 10c/kWH it would cost 26c PA. You would have to avoid running it for decades to recover the cost of any power saving circuit.
    – Milliways
    Nov 24, 2014 at 4:40
  • @Milliways I agree with your cost-benefit analysis but it would be beneficial if we power down each sub-system as possible as per good engineering practices. 26c is for the power only, what about the life extension of power circuits and the pi itself. Don't you think that powering down will extend life of the components? Nov 24, 2014 at 6:36

Here is a link that shows a complete solution to power a Pi, within it is also a link to a more simple solution to turn the Pi on and off, including power.


  • 1
    Hello and welcome to Raspberry Pi! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – Ghanima
    Jan 17, 2016 at 9:30

The software part of this is simple: detect the button pressing event happening on GPIO and execute the command shutdown -h now or halt.

But to cut the power properly you will need something hardware. Considering the scenario that you are building a power management HAT that back powers the Pi. You can detect whether the Pi is off by observing the UART lines: then TX go low for extended period the Pi is off. Some circuitry should be built to detect this and turn off the pass transistor controlling power to the Pi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.