fbpx

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

Circuit

Code

  • 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.
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.

Leave a Reply

Your email address will not be published. Required fields are marked *