How to Reset or Shutdown Raspberry Pi using a Button

(Last Updated On: April 1, 2021)

Raspberry Pi Reset/shutdown button

The question arises again and again as to how the Raspberry Pi can be reset via a button or simply shut down. To accomplish this you have two options.

  • Hard reset
  • Soft reset

Hard reset button

All current Raspberry Pi models support a hard reset. With the Raspberry Pi 1, model B, the two contacts of the P6 header must be short-circuited for a moment, i.e. by a button.

Raspberry Pi Reset or shutdown

With the B+ model and the Raspberry Pi 2, the run headers offer the same function. The easiest way is a reset switch – without any Python! This means you don’t need any python code to reset the Raspberry Pi, you can use jumper wires or simply a push button to reset the Raspberry Pi. My recommendation is use a push button, pressing the button now leads to a hard reset, i.e., the Raspberry Pi will restart seamlessly- as if you had just pulled the power plug.

Caution, risk of data loss!

In general, a hard reset is always an emergency solution. A running system is system simply switched off or restarted without warning. There is none Ability to close open files, complete saves, or the Shut down the file system correctly. Usually the Raspberry Pi responds to Such resets are surprisingly robust, but it cannot be ruled out that the file system will suffer lasting damage at some point or that just at the time an important file is written after the reset and then after the restart is only available in an incomplete or faulty state.

If the Raspberry Pi is already in a halt when you press the reset button State (e.g. after the previous sudo halt), then pressing it causes the reset button to restart the Raspberry Pi.

Amazon Purchase Links:

Raspberry Pi

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Soft reset button

One speaks of a soft reset when the push of a button causes a proper shutdown of the Raspberry Pi triggers. The easiest way to implement such a function by a button that you connect to a GPIO pin configured as an input. When the computer starts up, you start a script that constantly uses this GPIO pin checked. As soon as the button is pressed, run out reboot or halt in your script. If you want, you can also rewrite your soft reset code so that a restart only occurs if the button is pressed for several seconds.

The following lines show a very simple Python script that executes reboot, as soon as the button on GPIO pin 21 is pressed. The wiring is quite simple, all you need is connect a push button between the GPIO Pin 21 and GND, this way when the button is pressed the GPIO Pin 21 is pulled to GND.

Should the Raspberry Pi restart with the soft reset button (command reboot) or just be stopped (stop)? It depends what you are aiming for: After a stop, the Raspberry Pi can safely be disconnected from the power supply, for example to carry out maintenance work on the presentation system, plugging in a new USB stick etc. but has the disadvantage that the Raspberry Pi can now only be restarted by interrupting the power supply or by an additional hard reset button.

Don’t forget to make the script executable with chmod a + x Now add a line before exit in /etc/rc.local to have the script at the end of the boot process to start. Note the & character at the end of the command: that the reboot script is executed as a background process.

Raspberry Pi Hard reset Vs soft reset

Now which is better, a hard or a soft reset? Should the Raspberry Pi come from crash completely for one reason (e.g. hardware problem, kernel error), then this helps just a hard reset. Since there are no more programs running on the Raspberry Pi, there is also no possible reaction to the soft reset button.

On the other hand, this case is fortunately the exception, and should it really occur, you can just as easily disconnect the power supply. The advantage of the soft reset is that the computer is shut down properly. So if you have a Build a presentation system for an end customer and have a reset button would like to make a soft reset.

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply