I try to make a LED light up with the code enter image description here

        import RPi.GPIO as GPIO
        import time 

        GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(18, GPIO.OUT)
        while (var==1):


as illustrated in the figure, the pin 18 serves to light up a LED or switch it Down but when I try with sudo python3 this script I see that the LED is lighten just a bit. Only if I connect my transistor base to the ground, I see that the LED is off completely I conclude that pin 18 is between HIGH and LOW, ont completely LOW... why?

  • the LED is incorrectly oriented ... it will not light even if the transistor is bridged
    – jsotola
    Commented Apr 5, 2021 at 23:55

1 Answer 1


It is unclear exactly what you have done (list full code & connections). What is R_US

The fundamental problem is your circuit.

Using an emitter follower is POOR practice; it will attempt to put 2.7V across the LED when ON, overloading the GPIO with unpredictable results. You have shown the LED connected in reverse.

Try a more conventional circuit; the LED & resistor in series would form the load. See https://elinux.org/RPi_GPIO_Interface_Circuits

NOTE with normal LED you can drive (up to 16mA) directly from the GPIO.

enter image description here

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.