2

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.output(pin,GPIO.HIGH)  
    time.sleep(1)  
    GPIO.output(pin,GPIO.LOW)  
    time.sleep(1)  
    return  

GPIO.setmode(GPIO.BOARD)  

GPIO.setup(12, GPIO.OUT)  

for i in range(0,50):  
    blink(12)  

GPIO.cleanup()   

My circuit looks like this,

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

Thanks in advance.

6
  • Have you connected a LED to pin 12? Commented Mar 28, 2017 at 7:31
  • yes, its just in on state, does not blink. Commented Mar 28, 2017 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. Commented Mar 28, 2017 at 7:38
  • yes, i tried to upload, but image size in too large. I used the same python my_script.py Commented Mar 28, 2017 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. Commented Mar 28, 2017 at 7:41

1 Answer 1

3

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

4
  • I used GPIO.setmode(GPIO.BCM) but still the same. actually it turns on soon after raspberry-pi is powered up Commented Mar 28, 2017 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. Commented Mar 28, 2017 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. Commented Mar 29, 2017 at 7:48
  • Hopefully that will not put you off. Problems like that are hard to fix as they are so unexpected. Commented Mar 29, 2017 at 7:59

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.