Hello I wanted to blink a LEDS. I have Raspberry Pi 3 B+ and I have LED connected to PIN 4 5v Power. The LED lights but I can't OFF LED

while True:[![enter image description here][1]][1]

Anyone know what is wrong?

my gpio scheme

red resistor blue GND green LED

  • If you have connected the LED to 5V and to a Pi GPIO you might have destroyed the Pi. A photo of your connections would help.
    – joan
    Commented Jan 29, 2018 at 8:06
  • 1
    Expansion header pin 4 is the 5V rail. GPIO 4 is connected to expansion header pin 7.
    – joan
    Commented Jan 29, 2018 at 8:30
  • @joan , added photo
    – lemming
    Commented Jan 29, 2018 at 8:34

2 Answers 2


From your diagram, it doesn't seem that you have connected the LED to a GPIO!

Here is a map of the GPIO connector:

enter image description here

As per the map you have connected the LED to 5V and GND via a resistor.

GPIO Pin4 (as mentioned in your code) is actually pin 7 on the GPIO connector. You need to connect the LED to right GPIO pin in order to control it from software.


To switch a LED on and off you need to connect one end of the LED to a GPIO, the other end of the LED to a resistor, and the other end of the resistor to ground or the 3V3 rail.

Switching the GPIO high and low will then switch the LED on and off (on and off will be reversed if you connect the other end of the resistor to 3V3).

You need a resistor to stop the LED burning out straight away.

To prevent damage to the GPIO/Pi you must never connect a GPIO to a voltage outside the range 0V to 3V3.

See https://pinout.xyz/ for the GPIO connected to the expansion header pins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.