So you have a Raspberry Pi 3 or 4 and been messing around the house with it. Perhaps you are using it “headless” like me through SSH. Quickly you probably realized the default behavior of the leds are quite useless: The red power led stays on even after shutdown, the green ACT led blinks even after the Pi has shut down as well and the GPIO power pins still supply power to whatever’s using it.

Well, turns out you can control the 2 LEDs on the Raspberry Pi’s board so I went ahead and made a small SystemD service that runs when the system has completely shut down. The service makes the red LED blink at max brightness and turns off the green LED so that you don’t see it blinking in the afterlife.

Keep in mind that once the Pi is completely off, there’s kind of a reset that happens on the LEDs (by the firmware I suppose) that puts the red LED back on solid.

Creating the script and the SystemD service file on your Raspberry Pi

First, we need to create 2 files on your Raspberry Pi:

touch led-poweroff.service

Using the text editor of your choice on your Raspberry Pi (I love Vim), you’ll need to write these few lines into them.

echo 1 > /sys/class/leds/led1/brightness
echo heartbeat > /sys/class/leds/led1/trigger
echo 0 > /sys/class/leds/led0/brightness
echo none > /sys/class/leds/led0/trigger
sleep 3


Description=Blink power led on completed shutdown 

ExecStart=/bin/bash /root/

WantedBy=systemd-halt.service systemd-poweroff.service

Save those 2 files. Good.

Installing the SystemD service on your Raspberry Pi

Now let’s install them so they actually do something. Here’s how with a few commands on Raspberry Pi’s command line:

sudo cp /root/.
sudo chown root:root /root/
sudo chmod 500 /root/
sudo cp led-poweroff.service /etc/systemd/system/.
sudo systemctl daemon-reload
sudo systemctl enable led-poweroff.service

And…. that’s it!

Testing it out on your Raspberry Pi

Try it out on your Raspberry Pi using the classic poweroff command:

sudo poweroff

That’ll be all for today. Tell me in the comments how it went and if you did make some tweaks to it!

2 thoughts on “Raspberry Pi Hacks: Make The Power LED Blink On Poweroff”

  1. When I executed
    > sudo systemctl enable led-poweroff.service
    I got
    > Failed to enable unit: File led-poweroff.service: Invalid argument
    But the led got on and off after poweroff

    1. hi Stephan, thanks for the comment! It says the service doesn’t exist. Perhaps running the commands in the “Installing the SystemD service on your Raspberry Pi” section would be a good idea. Perhaps the filenames you created have typos in them? It’s worth double checking!

Leave a Reply

Your email address will not be published. Required fields are marked *