Things used in this project

Hardware components:
Pi 3 02
Raspberry Pi 3 Model B
×1
Adafruit Illuminated Pushbutton
×1
Resistor 330 ohm
×1
Micro SD Card 8GB+
×1
Software apps and online services:
Python
Microsoft Visual Studio 2017
Raspberry Pi Raspbian
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Schematics

GPIO/Pins Scheme
Pins only grande jw3zscurha pqv71irrj6
Main Circuit Diagram
Scheme djpmpwryfb
Breadboard Circuit Diagram
Breadboard circuit 0xd0g8d5un
Alternative Breadboard Circuit Diagram
Alternative circuit kihmafb9xj

Code

Serial Approach СodePython
#!/usr/bin/python

import RPi.GPIO as GPIO
import subprocess

# Starting up
GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN)

# Wait until power button is off
# Recommended to use GPIO.BOTH for cases with switch
GPIO.wait_for_edge(3, GPIO.BOTH)

# Shutting down
subprocess.call(['shutdown', '-h', 'now'], shell=False)
GPIO Approach CodePython
#!/usr/bin/python

import RPi.GPIO as GPIO
import subprocess

# Starting up
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(3, GPIO.IN)

# Light up the led button
GPIO.output(23, True)

# Wait until power button is off
# Recommended to use GPIO.BOTH for cases with switch
GPIO.wait_for_edge(3, GPIO.BOTH)

# Shutting down
subprocess.call(['shutdown', '-h', 'now'], shell=False)

Credits

Dae05c3978e9f48bef1abd3e5e805383
Uladzislau Bayouski
4 projects • 20 followers
Contact
Thanks to Alex Glow and Tyler.

Replications

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

Comments

Add projectSign up / Login