Saturday 2 April 2016

Basic model of IOT using raspberry pi A+

Hello technocrats,
In this tutorial you will get an introduction to the concept of internet of things and how this concept can be manipulated with the help of this 25$ chip .

Prerequisites for this tutorial
1. Your SD card should be pre installed  with raspbian OS.(You will get its tutorial in YouTube)
2. Raspberry pi should be connected to internet via LAN cable or WiFi adapter( if it is connected via       WiFi adapter then the adapter should be configured )
3. Knowledge of accessing raspberry pi remotely via putty.(I'll cover a bit of this concept in this             tutorial)

Requirements
1. Raspberry pi with pre-installed SD card( I have used model A+)
2. LAN cable or WiFi adapter
3. breadboard
4. LEDs (5-6)
5. 100 ohm resistors(5-6)
6. male to female jumper wires (10)

Internet of Things ( IoT)
Internet of things is a future model where every real life entities will be connected virtually via internet .





The Internet of Things (IoT) is the network of physical objects—devices, vehicles, buildings and other items—embedded  with electronics,software, sensors, and network activity that enables these objects to collect and exchange data. The IoT allows objects to be sensed and controlled remotely across existing network infrastructure, creating opportunities for more direct integration of the physical world into computer-based systems, and resulting in improved efficiency, accuracy and economic benefit; when IoT is augmented with sensors and actuators, the technology becomes an instance of the more general class of cyber-physical systems, which also encompasses technologies such as smart grids, smart homes, intelligent transportation and smart cities.

The raspberry pi is an open sourced processor having Linux OS and its ability to perform data sharing by connecting to internet via LAN cable or WiFi adapter makes it useful for IoT projects as the devices and electronic components can be easily connected to GPIO pins and manipulated remotely using python programming.

STEPS FOR BASIC IOT PROJECT (LED BLINK) 

1. Access raspberry pi remotely
    
    Remote access basically means getting the Graphical user interface of raspberry pi on your laptop       screen or mobile screen and controlling it via internet . For this to happen  your laptop /android cell     phone should be connected to the same router to which your raspberry pi is connected.
    In this project ( LED Blink) you may connect it using LAN cable or WiFi adapter .
   
    The protocol through which remote access of raspberry pi is possible is known as SSH network or          secure shell network.
     Secure Shell, or SSH, is a cryptographic (encrypted) network protocol operating at layer 7 of                the OSI Model to allow remote login and other network services to operate securely over an                   unsecured network.[1]
     SSH provides a secure channel over an unsecured network in a client - server architecture,                    connecting an SSH client application with an SSH server .Common applications include                          remote command line login and remote command execution, but any network service can be                secured with SSH.
     


  •     Router assigns dynamic IP to all the devices connected to it . We can get the IP address by softwares like Advanced IP Scanner ( For PC) and Fing ( for Android smartphone) .
  •  The Image will give you the idea of connectivity and  IP address . Usually home group network IP address starts with 192.168.**.*** .
  • Software like Xming will be helpful to create the GUI of raspberry pi . It acts as an emulator so that you can easily switch between your windows screen and  raspberry pi screen simultaneously
  • Putty ( For PC ) and connectbot ( for Android smartphone ) is a SSH Clients where you have to enter the dynamic IP of raspberry pi obtained from IP scanner applications .
  • After entering the IP address and clicking OK you will be prompted with a warning , just click OK 
  • default ID - pi , default password - raspberry . You will gain access to the terminal of raspberry pi which is basically the command line  where you enter command " startlxde-pi" for GUI
  • Command line login looks something like this
This tutorial will guide you the steps for remote access

2. GPIO Access 
    
   .Till now you should be having the screen of raspberry pi on your laptop screen after entering "startlxde-pi".
GPIO stands for general purpose input output . This  allows you to connect different electronic components and devices , Recent models of raspberry pi comes with 40 GPIO pins  The function of each pin can be referred by the following diagram .



  •  Enter the following commands in the LX - Terminal of Raspberry pi ( Command line ). You will need to connect raspberry pi to internet as the commands will download certain MB s of files
  •  sudo apt-get update (checks for updates and installs it )
  • sudo apt-get dist upgrade (checks for the upgraded version of Raspbian annd installs it)
  • sudo apt-get install python-rpi.gpio python3-rpi.gpio ( installs the gpio library files ).
Open the python shell which is the python IDE where you can write the programs through LX-Terminal . It is named as Idle .The code for opening idle through terminal ( this step is important ) is "sudo idle " or ( if it fails ) " gksudo idle ".
It will look like this .

Go to file> New . Which will open a new shell where you can write the program
  1. import RPi.GPIO as GPIO  #imports library files
  2. import time  #imports variable time
  3. # blinking function  
  4. def blink(pin):  
  5.         GPIO.output(pin,GPIO.HIGH)  
  6.         time.sleep(1)  
  7.         GPIO.output(pin,GPIO.LOW)  
  8.         time.sleep(1)  
  9.         return  
  10. # to use Raspberry Pi board pin numbers  
  11. GPIO.setmode(GPIO.BOARD)  
  12. # set up GPIO output channel  
  13. GPIO.setup(3, GPIO.OUT)  
  14. # blink GPIO17 50 times  
  15. for i in range(0,50):  
  16.         blink(3)  
  17. GPIO.cleanup() #stops the program and de-assigns the pins
  • Save the file ( cntrl+s) , Check the module for errors (alt+x) .
  • if there is no error proceed for connections
3. Connections and Program run

Connect your led and resistors ( 50 ohm or 100 ohm) as :

Finally press F5 to run the program . If it doesnt work , open terminal and write command as "sudo python programname.py " .
  programname -  Name of the led blink program that you saved in raspberry pi

Demonstration video:


4 . Modifiations
Add your own modifications like changing the program to allow the user to enter the no. of blinks and time interval of led blinks . 
Access Pi through android smartphone , in connect bot after successful login , run yor blink program same as " sudo python programname.py
This demonstration will look way more advanced . This was your first step towards IOT and by now you may have realized that sky is the limit for the possibilities of IOT  . Various other devices like motors , robots , sensors etc can be manipulated and controlled via internet .




Hope you have found this post informative.
Thank you
 

 

No comments:

Post a Comment