Led Blink using Raspberry Pi

Digital output, it is very wonderful features of a Raspberry Pi(RPi), RPi has some GPIO pins(General Purpose Input Output) which is helps to give digital data to digital output devices like led, Relay, Seven segment, led cube, led matrix etc.

In Digital world mainly two things are their which is ON & OFF; in uP language we can say that is 1 & 0 or 5v & Gnd. In case of RPi GPIO pin generate 5v or high signal to turn on led and gnd or low signal to turn off led.

So lets start how its work !!! 

If python and python3 is Not installed copy the below code and paste in terminal.
sudo apt-get update sudo apt-get upgrade sudo apt-get install python sudo apt-get install pyhton3
Install GPIO library for python
sudo apt-get install python-rpi.gpio python3-rpi.gpio


Led is connected to GPIO2 which is pin3 of RPi as we know RPi generate 5v but led workings on 3v for that purpose we need one Resistor ie. 220E which is connected series with led and led cathode is connected to Gnd of RPi(pin6)


import RPi.GPIO as GPIO ## Import GPIO library
import time

GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(3, GPIO.OUT) ## Setup Pin 3 to OUTPUT

 while True: 
    #Infinite Loop  
    GPIO.output(3, True) ## Turn on pin 3
    print ("led on")
    GPIO.output(3,False) ## Turn off pin 3
    print ("led off")


  • Save above code in .py
    • E.g.:  led_blink.py
  • Run code in terminal
python led_blink.py

If use Thonny IDE

Thonny IDE

Leave a Comment

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

Scroll to Top


Start your journey with us.

I hope this message finds you well. I’m writing to inquire about your offerings in IoT, robotics, and software solutions courses. Could you please provide details regarding the curriculum, duration, and enrollment process? Thank you in advance for your assistance.

Inquiry Now