1

Here is the code I am running on the Pi through IDLE.

import RPi.GPIO as GPIO
import time

GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)

for i in range(50):
    GPIO.output(12, 0)
    time.sleep(1)
    GPIO.output(12, 1)
    time.sleep(1)

GPIO.cleanup()

I am trying to get the LED to blink on and off. I have tried also using GPIO.BCM mode with 18 instead of 12 as the pin number.

I've attached pictures of my breadboard / general Pi set up. The longer end of the LED is attached to jumper cable, the shorter end is attached to the resistor. All parts are completely brand new.

The code runs, the LED does nothing.

edit:

I have since tried this exact set up with a 57 ohm resistors as opposed to the initial 10k ohm resistor. Still same results. LED does nothing.

edit Can get LED to turn on running through 5v and ground pins directly from the Pi with a 220 ohm resistor.

Breadboard Setup

Pi Setup

  • It's only on exit you should use GPIO.cleanup() – kuzeyron Sep 11 '17 at 16:53
  • Have you tried switching the LED around? – Steve Robillard Sep 11 '17 at 17:03
  • @amadeusxnet I tried removing the first GPIO.cleanup(). LED still won't turn on. Reverting the pins to there default state before the program runs shouldn't cause it to fail. Just an extra measure to ensure the program is running on a clean slate. – Ben Lucier Sep 11 '17 at 18:24
  • @SteveRobillard Would that not damage the circuitry? – Ben Lucier Sep 11 '17 at 18:38
  • the most common problem with an LED not blinking is installing it backwards. They are polarized meaning the connection direction matters. The long leg is normally the anode (the positive side). It won't hurt anything to try turning it around. – Steve Robillard Sep 11 '17 at 18:56
2

Your resistor is probably too big in this case. Image looks like it's 10k, if I see the colors properly. That's giving you less than 0.33 mA current. (It would be 0.33 mA if the LED had no forward voltage drop, which is actually does. That's usually around 2 V.) Try a smaller resistor. Depending on your LED, you probably want to get down in the hundreds of Ohms, not the tens-of-thousands.

For more information, look, for example, here: https://learn.sparkfun.com/tutorials/light-emitting-diodes-leds That gives information on how to determine the right resistance given your LED and your goals.

  • Comments are not for extended discussion; this conversation has been moved to chat. – Ghanima Sep 15 '17 at 19:53
0

I'm giving you the source code I wrote a long time ago. Hope you'll get yours working!

import atexit, RPi.GPIO as GPIO, time, decimal, random
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
def main():
        print "Blink begins! ctrl-c to stop"
        try:
                i = 0
                list = [18, 23, 24, 25]
                while True:
                        GPIO.output(list[i], True)
                        time.sleep(round(random.uniform(0.001, 0.1), 1))
                        GPIO.output(list[i], False)
                        i = random.randint(0,3)
        except KeyboardInterrupt:
                GPIO.output(18, False)
                GPIO.output(23, False)
                GPIO.output(24, False)
                GPIO.output(25, False)
                print "\nBlink DONE!"
                return
if __name__ == "__main__":
    main()
atexit.register(GPIO.cleanup)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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