Raspberry-LED Blink

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.

Hardware Required

  • LED
  • Resistor
  • Raspberry pi
  • Jumper wires
  • Breadboard



  • Create a new text file “ledblink.py” by typing the following

           nano ledblink.py

  • 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.
time.sleep(3)                                                    //delay function pauses the program for 3 secs
print "LED off"
GPIO.cleanup()                                                  //To reset the pin status
  • To run type python ledblink.py in the terminal.