Configuring Power-On/Off Button for Raspberry Pi 4B

Introduction:
Adding a power-on/off button to your Raspberry Pi 4B can provide a convenient way to manage the device’s power state. In this guide, we’ll show you how to configure a power-on/off button using the GPIO pins on the Raspberry Pi 4B.

Step 1: Edit the /boot/config.txt File

To configure the power-on/off button, you need to edit the /boot/config.txt file on your Raspberry Pi. Open the file using the following command:

sudo vi /boot/config.txt

Step 2: Enable Shutdown Functionality

To enable the shutdown functionality of the power button (green LED turns off when shutting down), add the following line to the config file:

dtoverlay=gpio-shutdown

Step 3: Enable Power-Off Functionality

To enable the power-off functionality of the power button (both green and red LEDs turn off when powered off), add the following lines to the config file:

dtoverlay=gpio-shutdown,gpio_pin=3
dtoverlay=gpio-poweroff,gpio_pin=24,active_low=0

Explanation of options used:

  • dtoverlay=gpio-shutdown: Enables the GPIO shutdown overlay to manage the shutdown functionality.
  • gpio_pin=3: Specifies the GPIO pin (BCM numbering) to use for the shutdown function (default is GPIO3).
  • dtoverlay=gpio-poweroff: Enables the GPIO power-off overlay to manage the power-off functionality.
  • gpio_pin=24: Specifies the GPIO pin (BCM numbering) to use for the power-off function (default is GPIO24).
  • active_low=0: Sets the active_low parameter to 0, which means the GPIO pin is active high (low signal triggers the action).

Step 4: Save and Reboot

Save the changes to the /boot/config.txt file, and then reboot your Raspberry Pi for the changes to take effect:

sudo reboot

Conclusion:
By following these steps and editing the /boot/config.txt file, you can easily configure a power-on/off button for your Raspberry Pi 4B. The power button will provide you with convenient control over the device’s power state, allowing for a smooth and efficient experience in managing your Raspberry Pi.

For more detailed information and the source of this guide, you can visit the provided link: Reviving Borkin Power On/Off Button for the Raspberry Pi 4B.