Things used in this project


Thanks to Inderpreet Singh for the original code! Be careful about the indents if you're copying & pasting.
# Simple script for shutting down the raspberry Pi at the press of a button. 
# by Inderpreet Singh
import RPi.GPIO as GPIO  
import time  
import os  
# Use the Broadcom SOC Pin numbers 
# Setup the Pin with Internal pullups enabled and PIN in reading mode. 
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)  
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Our function on what to do when the button is pressed 
def Shutdown(channel):  
   os.system("sudo shutdown -h now")  
def Restart(channel):
   os.system("sudo shutdown -r now")
# Add our function to execute when the button pressed event happens 
GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)  
GPIO.add_event_detect(23, GPIO.FALLING, callback = Restart, bouncetime = 2000) 
# Now wait! 
while 1:  


Photo on 7 5 17 at 5 06 pm 7 05huowsyxv
Alex Glow

The Hackster team's resident Hardware Nerd. I like robots, music, EEG, wearables, and languages. FIRST Robotics kid.



Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Similar projects you might like

LED Roulette Game
  • 10
  • 2

Full instructions

A fun pocket-sized travel game for any age. Try your luck and make the light stop on the green LED.

New MATRIX Creator Weather App on Eclipse Day
  • 13
  • 2

Full instructions

In celebration of Eclipse Day we have made this app to tell you what the weather is outside so you know if you can see the eclipse.

Mask with Blinking Eye
  • 74
  • 3


Makes a great mask more eye-catching when one eye is blinking. Has an on-off switch, is powered by a cell , and driven by an ATtiny85.

Chicken Coop Livestream
  • 2,881
  • 11

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

PHPoC - Detect Someone Taking Your Stuff  and send Gmail
  • 634
  • 14

When your stuff is being taken away by a thief, PHPoC makes an alert and sends a notification to you via Gmail.

Test Your Internet Speed Using a Raspberry Pi + Ubidots
  • 453
  • 6


Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog