Raspberry Pi 4 LED and Button Panel

Raspberry Pi 4 LED and Button Panel

I run a Pi-NAS server at home, and ran into a problem. I want to see if the server is safe to cut off from power basically. And in addition to shutdown via SSH, it would be neat to have a shutdown button. However, to turn on the server again, I had to cut power and turn back on. There has to be another way. And there is.

Some notes for this post You'll do anything on your own risk. While this is working for me, it might be a disaster with your Pi. I have a Raspberry Pi 4 Model B. There are also other way, and definitely better ones, to do this. I chose to do it that way for the parts I had around here. So please don't be mad at me for not doing it the way you would have done it :). Feel free to adapt this to your wishes.

Pins & Parts

There are 3 LEDs and 1 Button. The red LED is for showing if the Raspberry is connected to power, the green LED is for showing if the OS is running (don't turn off the power if this is light up) and a blue LED showing read/write activities of the sdcard. The Button is to shutdown the Pi 4 in a safe way, and turn back on when after a shutdown (Pi is “off” but power is still connected -› red LED is still on).

Here you can see my quick draft. It's coming in handy if you connect all the wires to the GPIO connector on the Pi. Here are the Pins you'll need:

Pin GPIO Part
Pin 5 GPIO 3 (SCL) Switch
Pin 9 GND Switch
Pin 4 +5V Resistor -» Red LED
Pin 8 GPIO 14 (TxD) Resistor -» Green LED
Pin 11 GPIO 17 Resistor -» Blue LED
Pin 6 GND LEDs

Before every LED I used a 1K Ohm resistor instead of a 330 Ohm. Never use a LED without a resistor. My LEDs are really bright. Even with a stronger Resistor. As you can see in the 1st photo, the LEDs look weird. 4 solder joints per LED?! Yes, this is a RGB-LED with 1 pin for every color and GND. If you have common LEDs you just need the anode (+) connected to the resistor and GND to the ground pin. You can also see I have used 2 GND-pins. This might be totally unnecessary, I just wanted the switch completely parted from the LEDs. It might work with just 1 GND pin perfectly fine.

Changes to the config.txt

After wiring everything up, you'll have to add some lines to the /boot/config.txt

On/Off Button + LED Panel

dtoverlay=gpio-shutdown,gpiopin=3, activelow=1,gpio_pull=up dtoverlay=act-led,gpio=17 dtoverlay=disable-bt

Please note that while you can use every pin for shutdown, only pin 3 will wake it again. The blue LED is on pin 17, but you can use any unused GPIO pin. Finally the green LED needs to be connected to TxD on pin 8. But to make it work you'll need to use the PL011 UART instead of the mini UART. See why in the UART-Docs. Therefore Bluetooth is disabled in this configuration.

After that I made sure everything was running properly by doing

sudo apt update
sudo apt full-upgrade
sudo apt rpi-eeprom-update

This might not be necessary, but it makes sure you'll have the correct version to run these commands in config.txt. After all that, I rebooted with sudo shutdown -r now

And now everything should work.

  • Red LED: Power is supplied to the PI
  • Green LED: OS is running (flickering at boot, then permanently on)
  • Blue LED: Only flickers if Read/Write operation occurs on the sdcard

Any question? You can reach me via Mastodon @ryo@fosstodon.org