Led have two-pin, Anode(+) and Cathode(-), Anode connected with raspberry pi pin 23 and Cathode is connected with 5v in Series with 220-ohm resistor.
- Raspberry pi
- Jumper wires
- Create a new text file “ledblink.py” by typing the following
- Now type the following code
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) //BCM is broadcom which specifies the actual pin number considered by broadcom chip GPIO.setwarnings(False) //Ignore warnings GPIO.setup(23,GPIO.OUT,initial=GPIO.LOW) //set pin 23 as output & set initial value to low(off) print "LED on" //This line prints the LED on to the terminal. GPIO.output(23,GPIO.HIGH) time.sleep(3) //delay function pauses the program for 3 secs print "LED off" GPIO.output(23,GPIO.LOW) GPIO.cleanup() //To reset the pin status
- To run type python ledblink.py in the terminal.