Raspberry Pi Led Programming

shape
shape
shape
shape
shape
shape
shape
shape
blog-details
December, 2019

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 !!! 

Digital Operation in RPi

INSTALL DEPENDENCY:

  • Check any Python package installed in RPi
  • Open terminal paste below code
python

python3

  • 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

DIGITAL OUTPUT

Install GPIO library for python

sudo apt-get install python-rpi.gpio python3-rpi.gpio

CIRCUIT CONNECTION:

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)

CODE:

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

GPIO.setwarnings(False) 
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")
    time.sleep(1)
    GPIO.output(3,False) ## Turn off pin 3
    print ("led off")
    time.sleep(1)

NOTE:

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

Terminal

  • If use Thonny IDE

Thonny IDE

 

 

 

Comments

client

John Smith

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et minus, saepe porro a voluptatem, quidem aut libero consequatur unde molestiae quae impedit accusantium dolor est corporis! Dolores ut dignissimos doloribus?

Jan 19, 2018 - 9:10AM Reply
client

Doe John

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et minus, saepe porro a voluptatem, quidem aut libero consequatur unde molestiae quae impedit accusantium dolor est corporis! Dolores ut dignissimos doloribus?

Jan 19, 2018 - 9:10AM Reply
client

Steven Doe

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et minus, saepe porro a voluptatem, quidem aut libero consequatur unde molestiae quae impedit accusantium dolor est corporis! Dolores ut dignissimos doloribus?

Jan 19, 2018 - 9:10AM Reply
client

John Cina

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et minus, saepe porro a voluptatem, quidem aut libero consequatur unde molestiae quae impedit accusantium dolor est corporis! Dolores ut dignissimos doloribus?

Jan 19, 2018 - 9:10AM Reply

Leave a Reply