I have installed a jack button to turn on and off my raspberry pi 3 following the method described in the youtbue video The Borkin Button Easy Raspberry Pi Power Butto.

This allows to create a shutdown and boot up switch taking advantage of the 3.55mm av(audio video) jack.

For this to work the GPIO PIN 5 needs to be connected with a wire to the jack enter image description here

Then the script below manage starting/shutting down the device.

import RPi.GPIO as GPIO
import time
import subprocess


# use the same pin that is used for the reset button (one button to rule them all!)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

oldButtonState1 = True

while True:
        #grab the current button state
        buttonState1 = GPIO.input(5)

    # check to see if button has been pushed
    if buttonState1 != oldButtonState1 and buttonState1 == False:
      subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      oldButtonState1 = buttonState1


It does work fine when the raspi is connected to a screen. However when not connected to a screen the button doesn't work.

Anyone can shed some light on what the issue could be?

  • Keep in mind most people are unlikely to bother watching a youtube video for you, so you may want to actually explain what you have done. – goldilocks Oct 29 '17 at 14:44
  • just a hunch ... try launching shutdown without the extra arguments to subprocess.call() like so subprocess.call("shutdown -h now") – Shreyas Murali Oct 29 '17 at 17:29

If you use certain displays that use all GPIO pins, this will not work.. Using Pimoroni HyperPixel 4"

Running script to watch Pin5, makes LCD go black

  • Is this meant to answer the question or comment on something else? – Brick Apr 23 '19 at 19:47

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.