Electronics and
Robotics Club
IIT Bombay

Our Events About Us

title = rasbe heading = Raspberry Pi subheading = Get started with using Raspberry Pi though this tutorial. category = None tags = None author = Darshan Tank, Pranav Sankhe, Om Kolhe, Tanya Chaudhary, Sanket Agrawal, Arkya Chatterjee, Parth Kothari date = July 07, 2016 //(DO NOT REMOVE THESE LINES) //(WRITE YOUR BLOG BELOW)

The Raspberry Pi (read R-pi) is a series of low-cost, credit card-sized single-board computers. It is just like any other computer and features built in Wi-Fi, Bluetooth. You can connect a keyboard, mouse through USB or Bluetooth and a display monitor through HDMI cable and start using it just like a normal computer.

But the real power of Rpi is realized in embedded systems. The Raspberry Pi has the ability to interact with the outside world, and has been used in a wide array of digital maker projects, from music machines and parent detectors to weather stations and tweeting birdhouses with infra-red cameras.


First Look

What does Raspberry Pi board look like?

The image given below is a top-view of Raspberry Pi 3 model B. Raspberry Pi 3

Now lets have a closer look at those 40 pins. Here is a pin diagram of those 40 pins. Raspberry Pi 3 Pin Diagram We can see that out of the 40 pins

The GPIO pins are used to connect to electronic devices and can be used as input or output. GPIO 2 and 3 can be used for I2C communication as they are the SDA and SCL pins respectively.

The 5V pins can be used to give 5V supply to any of the electronic devices. Same goes for 3.3V pins.


Depending on whether your laptop/pc has Linux or Windows, follow this steps to set your Raspberry Pi.

For Linux

  1. First download the image file of the operating system you want to install on your R-pi.
  2. Open a linux terminal of your choice.
  3. Connect your R-pi to laptop using the connector and insert the memory card in its slot.
  4. Now unmount the memory card using command:

    sudo umount /dev/PORT_NAME

    To see which port your sdcard belongs to, type:


  5. To copy the contents of img file to sdcard, type:


  6. It may take some time to copy the contents. Once done, you are ready to configure your r-pi.

For Windows

  1. First download the image file of the operating system you want to install on your R-pi.
  2. Download Win32DiskImager and unzip the application (.exe file) inside.
  3. Insert your SD card into your Windows PC using a card reader.
  4. Open Win32DiskImager.exe with Administrator privileges ( That is, right click on it and choose “Run as Administrator” ).
  5. If your SD card isn’t automatically detected by the application, click on the drop-down menu at the top right (labeled “Device”) and choose it from the list.
  6. In the image file section of the application, click the little folder icon and choose .img file of your operating system.
  7. Click the Write button and wait for Win32DiskImager to do its thing. When it finishes, you can safely eject your SD card and insert it into your Raspberry Pi.


  1. First download the image file of the operating system you want to install on your R-pi.
  2. Download RPi-sd card builder (be sure to pick the appropriate version for your installed version of OS X) and unzip the application.
  3. Insert your SD card into your Mac using a card reader.
  4. Open RPi-sd card builder. You’ll immediately be asked to choose a Raspbian image. Choose the .img file you downloaded earlier.
  5. You’ll be asked if your SD card is connected. Since we inserted it earlier, it is, so go ahead and click Continue. You’ll be presented with SD card options. If you only have one inserted, you won’t see anything else in the list and it’ll be checked. If not, just check only the card you want to use and click OK.
  6. Enter your administrator password and click OK. You’ll be asked if the SD card was ejected. This is supposed to happen, as the application needs to unmount it so it can perform a direct copy. Double-check that your SD card is no longer available in the Finder. DO NOT remove it from your USB port. When you’re sure, click Continue.
  7. RPi-sd card builder finishes prepping your SD card, safely eject it and insert it into your Raspberry Pi unit.

Time to configure your R-pi!


We use SSH to control R-pi through our laptop for SSH, we need r-pi to be connected to some network.

We can configure R-pi’s SSH, without ever requiring to boot R-pi.

Open os/etc/wpa_supplicant/wpa_supplicant.conf and write following piece of code in it:


Use command ‘ifconfig’ to see ip,network,gateway of your Wi-fi.

For setting static ip, open etc/network/interfaces.d 1- Change auto lo to wlan0 2- Change manual to static 3- After iface wlan0 inet manual , enter => address network gateway(first ip of subnet)

Once configured, type ‘ssh pi@address’ in terminal to connect to your R-pi.


Configuring GPIO

For programming the GPIO pins we have to install the python 2 library RPi.GPIO. This module makes it simple to use the GPIO pins. To install RPi.GPIO on your Raspberry Pi follow the following instructions.

In the LXTerminal of your R-Pi type the commands

sudo apt-get update    

To install RPi.GPIO, you first need to install the Python Development toolkit that RPi.GPIO requires.

To do this enter the following command:

sudo apt-get install python-dev

Then to install Rpi.GPIO itself type:

sudo apt-get install python-rpi.gpio

Thats it! Now you are ready to program GPIO pins.

Basics of GPIO programming

To program GPIO pins you have to import RPi.GPIO library in your python program. To do this type the following line at the top of your program:

import RPi.GPIO as GPIO

But before we start programming we have to set the numbering system of the pins. There are two types of numbering systems:

The GPIO.BOARD option specifies that you are referring to the pins by the number of the pin the the plug - i.e the numbers printed on the board (e.g. P1) and in the middle of the diagrams below.

The GPIO.BCM option means that you are referring to the pins by the “Broadcom SOC channel” number, these are the numbers after “GPIO” in the green rectangles around the outside of the below diagrams:

In the image below the numbers in the middle correspond to BOARD numbering and those written outside refer to BCM numbering. Pin Numbering

Based on which numbering system is comfortable to you, which RPi shield your are using, what program you are using you can choose the numbering sytem which is most convinient to you.

To specify in your code which number-system is being used, use the GPIO.setmode() function. For example…




After specifying the numbering system we have to decide whether the pins that we are using will be input or output (just like in Arduino).

To do this we use GPIO.setup() function. So if you want to setup pin 4 as output you would enter:

GPIO.setup(4, GPIO.OUT)  

If you want to set pin 17 as input you would enter:

GPIO.setup(17, GPIO.IN) 

So if you have set a particular pin as input you would like to read the value of that pin. To do this you would use the GPIO.input() function.

For example if you would like to read the value of pin 17 you would enter:


If you have setup a pin as output you would like to write a value to it. You would use the function GPIO.output() for it.

For example if you would like to set the value of pin 4 as HIGH you would enter:

GPIO.output(4, GPIO.HIGH)

If you want to set it as low:

GPIO.output(4, GPIO.LOW)

Now that you know how to set input and output of pins you are set to use any electronic devices along with the entire convinience of python.

One important thing to note that after the program is terminated either on its own or by a Keyboard Interrupt some of the pins which were high remain high after execution of the program. So in order to set everything to low we use the GPIO.cleanup() function.

Here is an example of simple LED blink program in which the usage of each and every function will become clear

    import RPi.GPIO as GPIO
    import time
    GPIO.setup(4, GPIO.OUT)
        while True:
            GPIO.output(4, GPIO.HIGH)
            GPIO.output(4, GPIO.LOW)
    except KeyboardInterrupt:

When we execute this program with a led at pin 4 we would see the LED blinking at a rate of 1 second. This program would go on for ever unless we terminate it by CTRL-C which is a KeyBoardInterrupt which then initiates the GPIO.cleanup function.

With this much knowledge you should be able to interface any electronic equipment with R-Pi with one last precation :P.

All the GPIO pins on R-pi are 3.3 volt logic level. So it is not safe to connect any device that gives or takes more than 3.3v as it might damage the GPIO pins. If you have to use any device that has a 5V supply such as HCSR04 ultrasonic sensors you should use a potential divider.

Time to try some good projects with your R-pi. Happy tinkering!

Contact Us

Tinkerers' Laboratory