<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Adding a Shutdown Button to the Raspberry Pi B+</title><link>/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><description>Introduction 


 What do you need? 


 Step 1. Setup the RPi 


 Step 2. Connecting the button 


 Step 3. Writing a Python Script 


 Step 4. Adding it to startup 


 Step 5. More to do 

 Introduction For a beginner to the world of raspberry pi, ther</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Sat, 05 Dec 2020 23:17:43 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>ipv1</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I think its time to update this little tutorial with an install script. I have gone though a couple of iteration of this one and run it on the Avnet IIOT gateway as well, successfully. &lt;span&gt;&lt;span class="e14-init-shown" id="addProduct-2FbdAbdW-linked"&gt;&lt;a class="jive-link-product-addtolist" href="https://www.element14.com/community/view-product.jspa?fsku=&amp;amp;nsku=02AH6799&amp;amp;COM=noscript&amp;amp;COM=e14c-direct-ugc&amp;amp;CMP=e14c-direct-ugc&amp;amp;osetc=e14c-direct-ugc" target="_blank" data-e14adj="t"&gt;&lt;span class="pf-widget-map pf-productlink-cart-icon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;a class="jive-link-product pf-embedded-product-link" href="https://www.element14.com/community/view-product.jspa?fsku=&amp;amp;nsku=02AH6799&amp;amp;COM=noscript&amp;amp;COM=e14c-direct-ugc&amp;amp;CMP=e14c-direct-ugc&amp;amp;osetc=e14c-direct-ugc" target="_blank" data-e14adj="t"&gt;Product Link&lt;/a&gt;&lt;/span&gt;&lt;span class="e14-init-hidden" id="addProduct-2FbdAbdW-unlinked"&gt;Product Link&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Will post a new blog over the holidays.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Sat, 05 Dec 2020 13:03:57 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>lolgamerslol</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;does it work with raspberry pi os too?&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Tue, 17 Sep 2019 15:22:49 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>afletch</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Two questions:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;1. Can I use a &amp;quot;rocker&amp;quot; switch, or do I have to use a momentary type button. I&amp;#39;d like a true &amp;quot;power&amp;quot; switch.&lt;/p&gt;&lt;p&gt;2. Will the turn the Pi back on as well?&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Tue, 19 Mar 2019 20:06:04 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>k4nk3i</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi, I am stuck at the testing phase. If I run &amp;#39;sudo python shutdown_pi.py&amp;#39;, nothing happen in the terminal and nothing happen if pressing the reset button on the RPi. CTRL-C then return the following: &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;^CTraceback (most recent call last):&lt;/p&gt;&lt;p&gt;&amp;nbsp; File &amp;quot;shutdown_pi.py&amp;quot;, line 23, in &amp;lt;module&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; time.sleep(1)&lt;/p&gt;&lt;p&gt;KeyboardInterrupt&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Any advice?&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Sat, 25 Nov 2017 04:34:08 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>mcstarcoin</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Can this also work as a power on switch?&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Thu, 23 Nov 2017 21:21:33 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>omniearth</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Maybe the PowerBlock might be interesting for you. It provides an easy way for adding a shutdown button to the Raspberry Pi.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Wed, 12 Apr 2017 08:29:15 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>palluetd</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi, when i pushed the button after wrote &amp;quot;sudo python shutdown_pi.py&amp;quot; nothing did happen but the command are good, do you know why ? &lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Thu, 30 Mar 2017 17:58:20 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>ntewinkel</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Thanks Inderpreet!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I&amp;#39;ve been wanting to add this to my sprinkler controller Pi for a while, but kept putting it off.&lt;/p&gt;&lt;p&gt;For some reason I thought this would have been more complicated &lt;span&gt;[View:/resized-image/__size/16x16/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-cae11ecc-e503-4c2f-843c-48121ddedfe0/8154.contentimage_5F00_1.png:16:16]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Being a belt-and-suspenders kind of guy, I tested first by having it just print out a debug line.&lt;/p&gt;&lt;p&gt;Once I proved to myself that I did indeed have the correct kind of button (normally-open) and that it was working well, I changed the line back to the shutdown line, and tested from the IDE first to make sure all was well before adding it to the startup script. Nothing like having a startup script invoke an immediate shut-down &lt;span&gt;[View:/resized-image/__size/16x16/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-cae11ecc-e503-4c2f-843c-48121ddedfe0/contentimage_5F00_3.png:16:16]&lt;/span&gt;&amp;nbsp; I can&amp;#39;t recall for sure but I&amp;#39;m pretty sure I&amp;#39;ve done that before on the old DOS systems!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I chose to use GPIO21 - at the very end of the connector, right beside the GND. Harder to mess that up, plus I already had a connector on the other end that covered the pin you had picked out.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;And for the switch, I used a reset switch complete with plug connector from an old computer - works like a charm!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Cheers,&lt;/p&gt;&lt;p&gt;-Nico&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Tue, 07 Mar 2017 01:31:42 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>z4y5f3</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;&lt;span&gt;[mention:4236e66f810f492faa977aafb3ee70a6:e9ed411860ed4f2ba0265705b8793d05]&lt;/span&gt; Hi I tried to use your instruction, and my Raspberry Pi indeed shut off correctly. However, after I shut it down by triggering the GPIO, the Raspberry Pi cannot boot up again. I tried to trigger the reset pin but even so it still cannot be powered up. Do you have any ideas about why would this happen? Thanks!&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Mon, 09 Jan 2017 21:00:53 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>Workshopshed</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;You can use wait_for_edge rather than the loop to remove the need for a endless loop.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a class="jive-link-external-small" href="https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/" title="https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/" rel="noopener noreferrer nofollow" target="_blank" data-e14adj="t"&gt;https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/&lt;/a&gt; &lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Thu, 05 Jan 2017 21:08:48 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>balearicdynamics</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hello Inderpreet! I have bookmarked your project at the time you published it as it is very good to automate the shutdown procedure. This is specially useful in headless installation. But at this point a question arises; do you think it is possible to power off automatically the PI after the shutdown procedure is finished? Else remain the physical question to power off / power on the Pi ... The power itself, in my opinion, can be controlled by a relay but at this points ideas come a bit confusing. I have developed in bas a solution (for the Gizmo SBC, but the case is exactly the same) that require an external circuit and a microcontroller over the entire system. Some ideas?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Enrico&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Tue, 29 Nov 2016 14:06:03 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>xd3l</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Hello, this works for me, but ONLY if I am connected to the Internet. Also I must be set to connect to the Internet while the device is booting, otherwise if I just connect after the fact, the Shutdown button still will not work.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;EDIT&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;Resolved:&lt;/p&gt;&lt;p&gt;My rc.local script was arranged wrong.&lt;/p&gt;&lt;p&gt;I had my shut down script after the bit about the network and not before. Therefore if no network was detected, then the Shutdown script would never be activated.&lt;/p&gt;Shutdown Button&lt;p&gt;sudo python /home/pi/scripts/shutdown_pi.py &amp;amp;&lt;/p&gt;Print the IP address&lt;p&gt;_IP=$(hostname -I) || true&lt;br /&gt; if [ "$_IP" ]; then&lt;br /&gt; printf &amp;quot;My IP address is %s\n&amp;quot; &amp;quot;$_IP&amp;quot;&lt;br /&gt; fi&lt;/p&gt;&lt;p&gt;exit 0&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Mon, 12 Sep 2016 16:58:18 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>volly</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a class="jive-link-profile-small jiveTT-hover-user" href="https://www.element14.com/community/people/foolycooly71?COM=e14c-direct-ugc&amp;amp;CMP=e14c-direct-ugc&amp;amp;osetc=e14c-direct-ugc" target="_blank" data-e14adj="t"&gt;foolycooly71&lt;/a&gt; I am of the opinion that you have your point of reference wrong somewhere. &lt;/p&gt;&lt;p&gt;You also saying that you are using pie 4.0?????&lt;/p&gt;&lt;p&gt;Please substantiate a bit more and/or add some pics please?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Yunus Vollenhoven.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Mon, 12 Sep 2016 15:28:07 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>arye</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I have been trying to make the button power on as well - and it did NOT work for me at all.&lt;/p&gt;&lt;p&gt;I have used it to power on when I connected it to the IO3, But now since my project has I2C sensors all over - I NEED that IO and I have moved with BCM IO 16 to try and do the same - BUT without success at all!! Just Shutting down the PI and not Power up at all.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;How come that it can do that ONLY on GPIO 3 and NOT on the others?&lt;/p&gt;&lt;p&gt;Is there a need to make it SCL I2C adaptable by code in order to get the CLK and make it boot?&lt;/p&gt;&lt;p&gt;I am not sure about using the &lt;strong&gt;I2C0&lt;/strong&gt; - BCM &lt;strong&gt;1&lt;/strong&gt; or BCM &lt;strong&gt;0&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Since it worked on the BCM3 It might work on the I2C0, No?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I have noticed that when it was connected to the I2C1 connection when I did &lt;em&gt;&lt;strong&gt;i2cdetect -y 1&lt;/strong&gt; &lt;/em&gt;it took a very long time to detect the sensors on that bus. &lt;/p&gt;&lt;p&gt;If I will do that and make it on BUS I2C0 - would it do the same? interfering with the detection of the ID&amp;#39;s on that BUS?&lt;/p&gt;&lt;p&gt;and also - I have read that I2C0 and I2C1 uses the same interrupt - it might mess with I2C1 as well, correct?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Please help me understand and I would be happy to know how to make the button work correctly? I need it also for power on, since after power off I might need this as well &lt;span&gt;[View:/resized-image/__size/16x16/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-cae11ecc-e503-4c2f-843c-48121ddedfe0/5164.contentimage_5F00_1.png:16:16]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;Arye &lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Adding a Shutdown Button to the Raspberry Pi B+</title><link>https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/adding-a-shutdown-button-to-the-raspberry-pi-b</link><pubDate>Sun, 28 Aug 2016 21:46:51 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:cae11ecc-e503-4c2f-843c-48121ddedfe0</guid><dc:creator>Former Member</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;I am having a problem its like my raspberry pi2 b is not seeing the GPIO, I have up dated them in python and the script that is in your instruction is exact as you have it. the only diffrance that I see is that my code when you put in the GPIO.setup(&lt;span class="number"&gt;18, GPIO.IN, pull_up_down = GPIO.PUD_UP) the 18 is not select green like yours. I am new at this and confused I am using the raspberry pie 4.0, also in your code GPIO.add_event_detect(&lt;span class="number"&gt;18, GPIO.FALLING, callback = Shutdown, bouncetime = &lt;span class="number"&gt;2000&lt;/span&gt;)&amp;nbsp; the 18 is green and my is not and the 2000 is green on your and mine is not as well. can you please help me?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28172&amp;AppID=84&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>