I am new for raspberry, I have raspberry-3 board and I tried following Python code on it. Which I took from here.

import RPi.GPIO as GPIO  
import time  

def blink(pin):  


GPIO.setup(12, GPIO.OUT)  

for i in range(0,50):  


My circuit looks like this,

enter image description here But this does not blink LED, What is missing here?

Thanks in advance.

  • Have you connected a LED to pin 12? – joan Mar 28 '17 at 7:31
  • yes, its just in on state, does not blink. – Sachith Muhandiram Mar 28 '17 at 7:36
  • You have connected it incorrectly. A photo of the connections will help. I assume you run the script with python script_name.py. – joan Mar 28 '17 at 7:38
  • yes, i tried to upload, but image size in too large. I used the same python my_script.py – Sachith Muhandiram Mar 28 '17 at 7:40
  • If it's a jpeg change the quality to 50% or so. That makes the size much smaller but will still be fine to view. – joan Mar 28 '17 at 7:41

You are using GPIO12 (connected to pin 32) rather than GPIO18 (connected to pin 12).

GPIO.setmode(GPIO.BOARD) says you will refer to GPIO by the pin they are connected to.

Either move the LED wire to pin 12 (presumably marked P18) or change to BCM numbering with GPIO.setmode(GPIO.BCM).

See https://pinout.xyz/ or http://abyz.me.uk/rpi/pigpio/index.html#Type_3

  • I used GPIO.setmode(GPIO.BCM) but still the same. actually it turns on soon after raspberry-pi is powered up – Sachith Muhandiram Mar 28 '17 at 9:24
  • 1
    The connection needs to be GPIO to LED to resistor to ground. If it doesn't work that means your circuit is wrong. Perhaps a plan photo would help. – joan Mar 28 '17 at 10:43
  • it was a problem with that connector, after doing direct wiring, problem was solved. I accepted your answer, because it was the first mistake I made. – Sachith Muhandiram Mar 29 '17 at 7:48
  • Hopefully that will not put you off. Problems like that are hard to fix as they are so unexpected. – joan Mar 29 '17 at 7:59

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.