Here is a great project for anyone running a Raspberry Pi board in “headless mode”, or just anybody who wants a simpler way of shutting down and restarting their Pi. Best of all, it’s super inexpensive and is simple to put together.

Standby Switch

The Raspberry Pi is undoubtedly a great little microcomputer, but one feature that it has always lacked is a power switch.

Putting a switch on the USB power supply input, or purchasing a supply that has a built-in switch, doesn’t really do the trick.  While it certainly is an effective way of removing power from the board, the Raspberry Pi (like most computers) requires a proper shutdown sequence before power is removed.

Now if you have a keyboard and monitor connected to your Pi then you can just use the Shutdown function to accomplish this. But even that isn’t perfect, as to restart the computer you need to remove and reinsert the USB power cable, which is at best a bit awkward.

And if you are using the Raspberry Pi in “headless mode”, without a keyboard and mouse, it is even more difficult to shut it down, although you can do it with SSH.

A much simpler method would be to have a pushbutton that you could use to shut down the Raspberry Pi, and then to start it up again. So that’s exactly what we are going to build today.

Standby vs Power Off

When you do a Shutdown on the Raspberry Pi using the operating system GUI, the Pi does not really turn completely off. Instead, it goes into a standby mode, where it consumes less current.

This is not unique to the Pi, as most computers also do this.  But it is an important distinction to make.

Our project, while often called a “Power Switch”, is really a “Standby Switch”. It does exactly the same thing as using the GUI to shut down the Raspberry Pi, it puts it into a low-current sleep mode.

Building the Standby Switch

This may go down as one of the simplest Raspberry Pi projects you have ever seen, as it only requires one part in addition to the Pi board!

Required Hardware

First, of course, you will need a Raspberry Pi. This project will work with any Raspberry Pi board, from the Zero all the way up to the Raspberry Pi 4.

You’ll also need a pushbutton switch, any normally open momentary contact pushbutton will work. You can use one of those inexpensive switches made for breadboarding, or a bigger switch – whatever you have in stock should suffice.

The only other thing you’ll need is some wire to hook it up. Our switch will be wired to two of the pins on the 40-pin Raspberry Pi GPIO connector, so having some female Dupont connectors would make this easier.

Standby Switch Hookup

Here is the hookup diagram for our standby switch:

The wiring is simple, one side of the switch is connected to pin 5 on the connector and the other end is connected to any of the grounds. You can use the ground on pin 6, which is right across from pin 5.

Pin 5 is the SCL connection, so you may find that it is in use if you are using I2C devices with your Raspberry Pi. But it shouldn’t be an issue in most cases, as you usually use the Pi as an I2C master and connect I2C slaves to it. As such, all you would be doing is grounding the clock line briefly, which is quite acceptable.

If you have a rare case of using the Raspberry Pi as an I2C slave, then you might want to add some buffering here. If you’re using the Pi as a slave to a 5-volt I2C master, then chances are you already have level converters here anyway.

Installing the Script

To make our switch work, we will need to install a script, and there are a few you can choose from.

I found a good one from GitHub user Howchoo. To install it, open your terminal and type the following command:

Once the script has been cloned to your Raspberry Pi,  you will need to run it to install the standby function. Again at the terminal type the following:

That’s all you need to do to install the script!

Testing the Standby Switch

Testing the script is even simpler than installing it. Just push the button!

If all is working, your Raspberry Pi will shut down. You can observe the activity (ACT) led, the green one on most boards, and wait for it to stop flashing. At that point, your Raspberry Pi is in standby mode.

Now press the button again. The Pi should boot back up.

You can also use the button to restart the Raspberry Pi when you shut it down using the operating system. So it’s a pretty versatile switch.

Conclusion

This is a pretty simple project, but also a pretty effective one. I think it would make a good addition to any Raspberry Pi board. Give it a try and see what you think.

 

Raspberry Pi Standby Switch
Summary
Raspberry Pi Standby Switch
Article Name
Raspberry Pi Standby Switch
Description
The Raspberry Pi is a great microcomputer, but it is missing one essential component - a power switch. Learn how to wire a pushbutton to your Raspberry Pi GPIO and use it to power your Pi on and off.
Author
Publisher Name
DroneBot Workshop
Publisher Logo

If you have a question...

Comments about this article are encouraged and appreciated. However, due to the large volume of comments that I receive, it may not be possible for me to answer you directly here on the website.

You are much more likely to get answers to technical questions by making a post on the DroneBot Workshop Forum. Your post will be seen not only by myself, but by a large group of tech enthusiasts who can quickly answer your question. You may also add code samples, images and videos to your forum posts.

Having said that, please feel free to leave constructive comments here. Your input is always welcome. Please note that all comments may be held for moderation.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x