Interfacing LED with Raspberry Pi GPIO Pin





3.Jumper Wire

4.330 ohm resistor

5.wiringPi library to write program in c

First we need to install wiringPi library as below:

Library install:

     We are writing the program in c for that we need to install the library. To install follow the below steps:

1.Install Git Core

  Git Core need to be installed to download wiringPi library

  Command to install

  sudo apt-get install git-core

2.Command to download wiringPi:

  git clone git://

3.Built and install wiringPi library:

  Go to library as

  cd wiringPi

  Run command : ./built

Instruction to glow LED:

1.Understand the GPIO structure

  For that type the command pinout on terminal

2.As we are using wiringPi library then refer GPIO structure

  For that type the command gpio readall on terminal

  Refer below diagram


Circuit Building:

1.Connect any GPIO pin of Raspberry Pi (Ex:GPIO25 in wPi it’s 6 refer in above table) to anode of LED  through jumper wire and breadboard

2.Connect any Ground pin of Raspberry Pi to cathode of LED through jumper wire and breadboard

3.Connect one leg of resistor to cathode of LED and another leg of resistor to ground

As shown below

Now connect all the peripherals of raspberry pi and power on the supply


1.Open the terminal in that open a vi file to write c code

  Ex: vi blink_led.c

2.Type the following code in vi blink_led.c

     /* Program to blink led using GPIO pin of raspberry pi

     Author: PTI                                                       Date:02/07/18*/

  #include <stdio.h>

  #include <wiringPi.h>                                                                  //to include wiringPi library

  #define PIN25 6

  int main()


               if(wiringPiSetup() == -1)                                    //function to setup wiringPi


                          printf(“Cannot setup wiringPi\n”);

   return 0;


              pinMode(PIN25, OUTPUT);                                //set output pin



    digitalWrite(PIN25, HIGH);                      //To make GPIO pin high

               printf(“led on\n”);


    digitalWrite(PIN25, LOW);                       //To make GPIO pin low

               printf(“led off\n”);



               return 0;


3.Once writing program is done save it

4.compile the program as show below

  gcc blink_led.c -o blink_led -lwiringPi

  -lwiringPi is given to tell compiler we are using wiringPi library because compiler by default search in standard library

5.Run the executable file

  sudo ./blink_led  

Glow led through command line:

Led can also be glow through command line as shown

Now i have connect led to GPIO25

pi@raspberrypi:~$ echo 25 > /sys/class/gpio/export

pi@raspberrypi:~$ cd /sys/class/gpio/gpio25

pi@raspberrypi:/sys/class/gpio/gpio25# echo out > direction

pi@raspberrypi:/sys/class/gpio/gpio25# echo 1 > value

Now led will glow

To turn off the led

pi@raspberrypi:/sys/class/gpio/gpio25# echo 0 >value