0

I have a raspberry pi 2 Model B v1.1 and 7 color flash sensor. I want to flash the led to get my hand into practice. This is my first program with raspberry pi and unfortunately i failed to flash the led.

I am not using breadboard. I am using pi pin. For that i have used three female-female wire. One for connecting to 5v, one to ground and one to 11 number pin as a channel for supplying high or low voltage so when i use GPIO.output(11,True) led will flash. But it is not working. Here is my code.

7colorflash.py

import RPi.GPIO as GPIO
import time



GPIO.setmode(GPIO.BOARD)
mode = GPIO.getmode()
if mode == GPIO.BOARD:
    GPIO.setup(12,GPIO.OUT)
    GPIO.output(12,True)
    GPIO.output(12,False)
elif mode == GPIO.BCM:
    GPIO.setup(18,GPIO.OUT)
    GPIO.output(12,True)
    GPIO.output(12,False)
else:
    print('None')
GPIO.cleanup()

I have attached an image to show the connection. wire connected to 5v is in number 2 pin, ground in number 6 pin and channel number 11 is used.

enter image description here

What might be the cause for not flashing the led?

goldilocks
  • 60,325
  • 17
  • 117
  • 234
Tushant
  • 109
  • 2

2 Answers2

0

I can think of the following.

  • Broken LED
  • Not connected to pin 11
  • Not driving the LED according to its specifications
  • LED connected back to front
joan
  • 71,852
  • 5
  • 76
  • 108
0

As per this, there are two commonplace ways of conceiving of the board pin numbers. Based on your photograph, you are assuming the BOARD numbering scheme, but you have not actually specified one way or the other.

While it says there setting that is mandatory, it could be importing the module under an alias (GPIO) sets it for you (or there actually is a default and setting it isn't so "mandatory"). I do not use python so don't know. You should try an if/else clause to test the value of GPIO.getmode() against GPIO.BOARD, GPIO.BCM, or None to see which it is.

If it is GPIO.BCM that is not pin 11, that is pin 18 (or perhaps 17, if you started counting from 1, it is hard to tell which row that connection is on).

goldilocks
  • 60,325
  • 17
  • 117
  • 234