Skip to content

josephgalloway321/raspberry_pi_power_button

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Power Button 🔴

Overview

The main goal of this project is to have an easy way to safely power on and power off the raspberry pi with a physical button. The button used in this project has an RGB LED to show the current state of the Raspberry Pi to the user. This project has only been tested using Ubuntu Server 22.04 LTS (64-bit) and the hardware specified in the hardware section.

To use this program, please recreate the circuit using the hardware shown below then install the files found in the source (src) folder.

Color Process
No Color Operating System Off
Red Operating System Starting Up
Green Start Up Complete; Button Ready to Use
Yellow Operating System Restarting

Action Outcome
Button Press & Release (< 1 seconds) Shutdown
Button Press & Release (> 1 seconds) Restart


Table of Contents


Hardware

The following material was used to complete the project:

Item Price
Raspberry Pi 3 B+ $ 35
16GB Micro SD Card $ 9
USB Micro Power Supply $ 10
Dupont Wires $ 7
Resistors $ 11
Spade Connectors $ 9
Wire Crimper $ 27
LED Power Button $ 17
18 AWG Solid Wire $ 17
Breadboard $ 10
Wire Cutters $ 20

Note: The links provided are only suggestions. They are not the only options for purchasing these specific products. I do not have any affiliation with the companies selling these products. The prices shown now may not be up to date.

Note: A Micro SD to USB A converter may be needed if the computer you're going to use to flash the operating system does not have a SD card slot.


Circuit & Setup

Notes:

  • The LED in the power button is a common anode RGB. This means that the three LEDs share a positive connection.
  • From the LED Power Button, the wire going to GPIO 3 and the wire going to ground (GND) are both for the button. They need to be connected to the normally open (NO) spade connectors on the button, which are the two outermost connectors. A drawing can be found here or on the LED Power Button product webpage.

Circuit Circuit Circuit Circuit Circuit


Install & Uninstall

Note: The first step assumes that the user has already installed Ubuntu 22.04 LTS (64-bit) on their Raspberry Pi micro SD card. I recommend using the Raspberry Pi Imager.
Also, please complete the circuit above before beginning this section.

  1. First, please update your operating system using the following commands:
sudo apt update && sudo apt upgrade

Note: This can take some time depending on how updated your operating system is currently. Consider restarting after this command is finished.

  1. In order to install the installation file, please install curl using the following command:
sudo apt-get install curl
  1. The program uses Python 3 and the GPIO Zero module Please run the next two commands to install both of them:
sudo apt-get install python3   
sudo apt-get install python3-gpiozero   
  1. To install the program, please run the installation file:
curl https://raw.githubusercontent.com/josephgalloway321/raspberry_pi_power_button/main/src/install.sh | bash

Note: If everything installed correctly, the shell will print "Installation complete. Please restart your device." The LED will also turn green.

  1. Please restart your device using the following command:
reboot

Once the operating system completes restarting, the system should be ready to use.


Run the following command to see if the service is actively running:

systemctl status power_button.service

To Uninstall, please run the uninstallation file:

curl https://raw.githubusercontent.com/josephgalloway321/raspberry_pi_power_button/main/src/uninstall.sh | bash

Demonstration

There are three demonstration videos of how the operating system should behave depending on how the button is pressed. The start up and restart videos are sped up, but each should take around two minutes total for each process. The shutdown video is in real time. Please download and watch each video found in the videos folder.


Final Thoughts

I learned so much completing this project. In addition to adding a convenient power button to my Raspberry Pi, I learned about bash scripting, systemd, and mechatronics. I intend on using this project in combination with my future robotics projects. I also plan on updating the project to work on different operating systems, different hardware, and a YouTube video walking viewers through recreating the project themselves.

Please let me know if this project helped in any way! I'd really appreciate any feedback or how someone improved upon this design. I would also really appreciate credit if this project helped.


Acknowledgments

The credit for all of the information in this project goes to the people who made the content in the resources section below. They were all excellent resources and guides for this project. I'm very grateful and could not have done it without their help.


Resources

License

MIT License


Top of the page

About

This project is about using an RGB LED power button for the Raspberry Pi to safely turn on, turn off, and restart the operating system.

Topics

Resources

License

Stars

Watchers

Forks