9

In Arduino a built in LED is attached with number 13 Digital pin. Is there any LED like Arduino in Raspberry Pi,which I can use to test my code?

Sohan Arafat
  • 1,828
  • 1
  • 10
  • 40

3 Answers3

10

Yes, it is possible to control the built-in leds. Green LED is easier.

According to here, though it is probably Pi 3 specific, since it didn't work for my Pi 4:

In the terminal:

sudo echo 1 > sudo /sys/class/leds/led0/brightness

This turns the green led on.

sudo echo 0 > sudo /sys/class/leds/led0/brightness

To turn off the activity indicator override: (put it back how it was)

echo mmc0 >/sys/class/leds/led0/trigger
Botspot
  • 1,759
  • 6
  • 27
9

though it is probably Pi 3 specific, since it didn't work for my Pi 4

It works on the 4 as well, you just need to set the right trigger. The instructions that you provided are not applicable to the 4 or just incorrect.

This will tell you what triggers you have available:

cat /sys/class/leds/led0/trigger

To enable manual control on a 4, do:

echo gpio |sudo tee /sys/class/leds/led0/trigger

Then control with:

# Any number > 0 will do
echo 255 |sudo tee /sys/class/leds/led0/brightness

# Zero turns it off
echo 0 |sudo tee /sys/class/leds/led0/brightness

icuwopcui
  • 91
  • 1
  • 1
4

Unfortunately the Pi has no GPIO programmable built-in LED.

Edit: This is incorrect. As pointed out in an answer below, the on-board can be controlled using echo none > /sys/class/leds/led0/trigger to enable, echo 1 >/sys/class/leds/led0/brightness to turn the LED on, and echo 0 >/sys/class/leds/led0/brightness to turn the LED off.

The rest of my previous answer for controlling an external LED...

Instead, you'd have to make a simple circuit between two pins, e.g. pin 9 and 11 (https://pinout.xyz/), with an LED and resistor (around 100 ohms should be fine). You can then control the LED using the gpio command. gpio mode 11 out to enable output, gpio write 11 1 to turn on the LED, and gpio write 11 0 to turn off the LED.

More details are available at https://thepihut.com/blogs/raspberry-pi-tutorials/27968772-turning-on-an-led-with-your-raspberry-pis-gpio-pins.

Fred
  • 4,552
  • 18
  • 29