Flash the onboard green LED of the Raspberry Pi.

You have probably already seen that the Raspberry Pi has two LEDs directly soldered to the board, one red and one green. But did you know that it is possible to control this green LED, and sometimes even the red one?

Flash the onboard green LED of the Raspberry Pi.

In this tutorial, we are going to see how we can use the green LED of the Raspberry Pi by flashing it to transmit a message.

The necessary equipment

The interesting point with this green LED is that it is already on board the Raspberry Pi. Therefore, we will not need any additional hardware. So we just need to:

And like (almost) every time, a way to control the Raspberry Pi, for example in SSH.

What are the onboard LEDs of the Raspberry Pi used for?

Raspberry Pi have two LEDs (except Zero models which only have green), one red and one green. These LEDs are used by the Raspberry Pi to tell us information about its operating status.

Thus, the red LED is directly connected to the power supply of the Raspberry Pi. It therefore allows us to know whether or not our Raspberry Pi is receiving current.

The green LED on the other hand provides us with a little more complex information, mainly at the time of startup.

I’m not going to give you a complete transcription of the Raspberry Pi / Humans dictionary, but be aware that depending on how this LED flashes, you can know if the Raspberry Pi is booting correctly or if it encounters an error, and if so the type of this mistake.

Turning on the green LED of the Raspberry Pi is writing to a file!

Once the Pi is turned on, the green LED stays off as long as there is no activity on the SD card.

It is possible to slightly modify this behavior and control the way the LED lights up ourselves, simply by writing to a file!

First, we will have to modify the default behavior of the LED by writing none in the file /sys/class/leds/led0/trigger with the command below:

sudo sh -c "echo none > /sys/class/leds/led0/trigger"

Once this command is placed, if you open this file you will see that it does not actually contain none as you might expect, but a line where none is ent[]ered to show that this is the selected mode.

The default behavior being overwritten, all we have to do is check the LED ourselves. And for that, nothing could be simpler!

To turn the LED on or off, we just need to write to the file /sys/class/leds/led0/brightness.

Source: Flash the onboard green LED of the Raspberry Pi.

About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Scroll to Top