You are on page 1of 47

SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Hindi Vidya Prachar Samiti’s


RAMNIRANJAN JHUNJHUNWALA
COLLEGE (AUTONOMOUS)
Ghatkopar (W), Mumbai-400 086

Department of
INFORMATION TECHNOLOGY

T.Y.BSc.(I.T.) SEM – V

Paper - RJSUITP502
Internet of Things (IoT)

Name: Vimal Tiwari


Roll No.: 50
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Hindi Vidya Prachar Samiti’s


RAMNIRANJAN JHUNJHUNWALA
COLLEGE (AUTONOMOUS)
Ghatkopar (W), Mumbai-400 086
Certificate

This is to certify that Vimal Tiwari of TY B.Sc. (I.T.) class has completed the
required number of experiments in the subject of Internet Of Things in the
Department of Information Technology during the academic year 2020-2021.

Professor In-Charge Co-ordinator of IT Department


Prof. Bharati Bhole
Prof. Archana Bhide

Examiner
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

INDEX

S.No Topic
Practical 0:
1 Starting Raspbian OS, Familiarizing with Raspberry Pi Components and interface,
Connecting to Ethernet, Monitor, and USB.

Practical 1:
Basic I/O of GPIO
a. Blinking 8 LEDs connected to GPIO.
2 b. Blinking 8 LEDs in different patterns.
c. Turning an LED ON or OFF using a Push Button.
d. Demonstrate the use of 16*2 LCD screen using raspberry Pi.
e. Sounding an alarm using a buzzer when a button is pressed.
Practical 2:
3
Use of 4 digit 7 segment LED display to show the time
Practical 3:
4 a. Controlling Raspberry Pi with Telegram App
b. Controlling Led via Telegram App
Practical 4:
5
Interfacing Raspberry Pi with RFID
Practical 5:
6
Fingerprint Sensor interfacing with Raspberry Pi

PRACTICAL 0: Starting Raspbian OS, Familiarizing with Raspberry Pi Components and


interface, Connecting to Ethernet, Monitor, USB
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Introduction to Raspberry Pi:

 Raspberry Pi is a small single board computer. By connecting peripherals like


Keyboard, mouse, display to the Raspberry Pi, it will act as a mini personal computer.

 Raspberry Pi is popularly used for real time Image/Video Processing; IoT based
applications and Robotics applications.

 Raspberry Pi is slower than laptop or desktop but is still a computer which can
provide all the expected features or abilities, at low power consumption.

 Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they
provide NOOBS OS for Raspberry Pi. We can install several Third-Party versions of
OS like Ubuntu, Archlinux, RISC OS, Windows 10 IOT Core, etc.

 Raspbian OS is official Operating System available for free to use. This OS is


efficiently optimized to use with Raspberry Pi. Raspbian have GUI which includes
tools for Browsing, Python programming, office, games, etc.

 We should use SD card (minimum 8 GB recommended) to store the OS (operating


System).

 Raspberry Pi is more than computer as it provides access to the on-chip hardware i.e.
GPIOs for developing an application. By accessing GPIO, we can connect devices
like LED, motors, sensors, etc and can control them too.

 It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics
Processing Unit).

 The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz. Also, it has on-
board SDRAM that ranges from 256 MB to 1 GB.

 Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules.

Introduction to GPIO:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

GPIO (General Purpose Input Output) pins can be used as input or output and allows
raspberry pi to connect with general purpose I/O devices.

 Raspberry pi 3 model B took out 26 GPIO pins on board.

 Raspberry pi can control many external I/O devices using these GPIO’s.

 These pins are a physical interface between the Pi and the outside world.

 We can program these pins according to our needs to interact with external devices.
For example, if we want to read the state of a physical switch, we can configure any
of the available GPIO pins as input and read the switch status to make decisions. We
can also configure any GPIO pin as an output to control LED ON/OFF.

 Raspberry Pi can connect to the Internet using on-board Wi-Fi or Wi-Fi USB adapter.
Once the Raspberry Pi is connected to the Internet then we can control devices, which
are connected to the Raspberry Pi, remotely.

GPIO Pins of Raspberry Pi 3 are shown in below figure:


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

How to install Raspbian on the Raspberry Pi:

Step 1: Download Raspbian. ...

Step 2: Unzip the file. ...

Step 3: Write the disc image to your microSD card.

Step 4: Put the microSD card in your Pi and boot up.

Use of Python:

Python is a general purpose and high level programming language. You can use Python for
developing desktop GUI applications, websites and web applications. Also, Python, as a high
level programming language, allows you to focus on core functionality of the application by
taking care of common programming tasks. The simple syntax rules of the programming
language further makes it easier for you to keep the code base readable and application
maintainable. There are also a number of reasons why you should prefer Python to other
programming languages.

1. Readable and Maintainable Code

2. Multiple Programming Paradigms

3. Compatible with Major Platforms and Systems

4. Robust Standard Library

5. Many Open Source Frameworks and Tools

6. Simplify Complex Software Development

7. Adopt Test Driven Development

Control LED using Python


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Aim:-

To make a prototype for controlling the LED using python as raspberry Pie.

Components used:

1. Breadboard.

2. LED

3. Resistor

4. Raspberry Pie.

Circuit Diagram:

Python Program:

importRPi.GPIO as GPIO #import RPi.GPIO module

LED = 32 #pin no. as per BOARD, GPIO18 as per BCM

Switch_input = 29 #pin no. as per BOARD, GPIO27 as


per BCM

GPIO.setwarnings(False) #disable warnings

GPIO.setmode(GPIO.BOARD) #set pin numbering format

GPIO.setup(LED, GPIO.OUT) #set GPIO as output

GPIO.setup(Switch_input, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:

if(GPIO.input(Switch_input)):

GPIO.output(LED,GPIO.LOW)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

else:

GPIO.output(LED,GPIO.HIGH)

Conclusion:

Hence we have successful created a prototype to for blinking a LED using raspberry PI.

Practical 1: Basic I/O of GPIO


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Practical 1 A] Blinking 8 LEDs connected to GPIO:

Aim: The aim is to blink 8 LED’s connected to GPIO using Raspberry Pi.

Components used:

1. 1*Raspberry Pi

2. 1* Breadboard

3. 8* LED

4. 8* Resistor (220Ω)

5. Jumper Wires

Circuit Diagram:

Algorithm:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

1. Initialize the required GPIO ports and import required modules.

2. Set warnings to false,use Broadcom SOC channel by setting mode to


GPIO.BOARD.

3. Set pull up register enabled to take input for push button.

4. If the value of pullup register is false the blink the LED in a super loop.

5. Else stop blinking the LED.

Python code:

import RPi.GPIO as GPIO

from time import sleep

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BOARD)

pins=[8,10,12,3,5,7,11,13]

GPIO.setup(8,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(10,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(12,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(3,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(5,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(7,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(11,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(13,GPIO.OUT,initial=GPIO.LOW)

while True:

for pin in pins:


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

GPIO.output(8,GPIO.HIGH)

GPIO.output(10,GPIO.HIGH)

GPIO.output(12,GPIO.HIGH)

GPIO.output(3,GPIO.HIGH)

sleep(0.1)

GPIO.output(5,GPIO.LOW)

GPIO.output(7,GPIO.LOW)

GPIO.output(11,GPIO.LOW)

GPIO.output(13,GPIO.LOW)

sleep(0.1)

GPIO.output(5,GPIO.HIGH)

GPIO.output(7,GPIO.HIGH)

GPIO.output(11,GPIO.HIGH)

GPIO.output(13,GPIO.HIGH)

sleep(0.1)

GPIO.output(8,GPIO.LOW)

GPIO.output(10,GPIO.LOW)

GPIO.output(12,GPIO.LOW)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

GPIO.output(3,GPIO.LOW)

sleep(0.1)

Conclusion:

Hence we have successfully created a prototype to blink 8 LED’s connected to GPIO using
Raspberry Pi.

PRACTICAL 1
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 1 B) Blinking 8 LEDs in different patterns

Aim:

The aim of the practical is to create a prototype for blinking 8 LED’s in different patterns.

Components used:

1. 1*Raspberry Pi

2. 1* Breadboard

3. 8* LED

4. 8* Resistor (220Ω)

5. Jumper Wires

Circuit diagram:

Algorithm:

1. import required modules.

2. Initialize the required GPIO ports.

3. Setwarnings to false, use physical pin numbering by setting mode to GPIO.BOARD.

4. Initially set all ports as output port and LOW.

5. Write a super loop to display different patterns of LED's in 1 second interval.


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Python code:

import RPi.GPIO as GPIO # Import GPIO library

from time import sleep #import sleep module


from time library

GPIO.setwarnings(False) #set warnings to false

GPIO.setmode(GPIO.BOARD) # Use board pin numbering

pins=[8,10,12,3,5,7,11,13]

GPIO.setup(8,GPIO.OUT,initial=GPIO.LOW) #initially
setting all LED's to low

GPIO.setup(10,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(12,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(3,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(5,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(7,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(11,GPIO.OUT,initial=GPIO.LOW)

GPIO.setup(13,GPIO.OUT,initial=GPIO.LOW)

while True: #Super loop

for pin in pins:

GPIO.output(pin,GPIO.HIGH) #Blinking single LED


at a time in 1 second of sleep(1)
#interval

GPIO.output(pin,GPIO.LOW)

sleep(1)

GPIO.output(pin,GPIO.HIGH)

sleep(1)

GPIO.output(pin,GPIO.LOW)

sleep(1)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Conclusion:

Hence we have completed a practical to create a prototype for blinking 8 LED’s in different
patterns.

PRACTICAL 1

PRACTICAL 1 C] Turning an LED ON or OFF using a Push Button


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Aim:

The aim of the practical is to create a prototype for turning an LED ON and OFF using a push
button.

Components used:

1. 1*Raspberry Pi

2. 1* Breadboard

3. 1* LED

4. 1* Resistor (220Ω)

5. 1*Push button

6. Jumper Wires

Circuit diagram:

Algorithm:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

1] Initialize the required GPIO ports and import required modules.

2] Set warnings to false, use Broadcom SOC channel by setting mode to GPIO BOARD

3] Set pull up register enabled to take input for push button

4] If the value of pull up register is false then blink the led in super loop.

Python code:

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)

GPIO.setup(24, GPIO.OUT)

try:

while True:

button_state = GPIO.input(23)

if button_state == False:

GPIO.output(24, True)

print('Button Pressed...')

time.sleep(0.100)

else:

GPIO.output(24, False)

except:

GPIO.cleanup()

Conclusion:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Hence we have completed a practical to create a prototype for turning an LED ON and OFF
using a push button.

PRACTICAL 1
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 1D] Sounding an alarm using a buzzer when a button is pressed

Components used:

1. 1*Raspberry Pi
2. 1* Breadboard
3. 1* Buzzer
4. 1* Resistor (220Ω)
5. 1*Push button
6. Jumper wires

Circuit diagram:

Algorithm:

1. Import required modules.


2. Initialize the required GPIO ports.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

3. Set warnings to false, use Broadcom SOC channel by setting mode to


GPIO.BCM.
4. Set pull up register enabled to take input for push button.
5. If the value of pull up register is false then Enable the buzzer to make sound in
a super loop.
6. Else disable the buzzer.

Python code:

import RPi.GPIO as GPIO


import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.OUT)
try:
while True:
button_state = GPIO.input(23)
if button_state == False:
GPIO.output(24, True)
print('Button Pressed...')
time.sleep(0.100)
else:
GPIO.output(24, False)
except:
GPIO.cleanup()
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 1
PRACTICAL 1E] Demonstrate the use of 16*2 LCD screen using raspberry Pi.

Aim:
The aim of the practical is to demonstrate the use of 16*2 LCD using raspberry Pi.

Components used:
1. Raspberry Pi 3 Model B (any Raspberry Pi)
2. 16 x 2 LCD Module
3. 10 KΩ Potentiometer
4. Mini Breadboard
5. Connecting wires (Jumper wires)
6. 5V – 2A Power Supply

Circuit diagram:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Algorithm:

7. Import required modules.


8. Initialize the required GPIO ports.
9. Set warnings to false, use Broadcom SOC channel by setting mode to
GPIO.BCM.
10. Set pull up register enabled to take input for push button.
11. If the value of pull up register is false then Enable the buzzer to make sound in
a super loop.
12. Else disable the buzzer.

Python code:

#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import sleep

# Define GPIO to LCD mapping


LCD_RS = 7
LCD_E = 8
LCD_D4 = 25
LCD_D5 = 24
LCD_D6 = 23
LCD_D7 = 18

# Define some device constants


LCD_WIDTH = 16 # Maximum characters per line
LCD_CHR = True
LCD_CMD = False

LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line


LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.0005

def main():
# Main program block
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbers
GPIO.setup(LCD_E, GPIO.OUT) # E
GPIO.setup(LCD_RS, GPIO.OUT) # RS
GPIO.setup(LCD_D4, GPIO.OUT) # DB4
GPIO.setup(LCD_D5, GPIO.OUT) # DB5
GPIO.setup(LCD_D6, GPIO.OUT) # DB6
GPIO.setup(LCD_D7, GPIO.OUT) # DB7

# Initialise display
lcd_init()

while True:

# Send some test


lcd_string("Electronics Hub ",LCD_LINE_1)
lcd_string(" Presents ",LCD_LINE_2)

sleep(3) # 3 second delay

# Send some text


lcd_string("Rasbperry Pi",LCD_LINE_1)
lcd_string("16x2 LCD Test",LCD_LINE_2)

sleep(3) # 3 second delay

# Send some text


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

lcd_string("1234567890*@$#%&",LCD_LINE_1)
lcd_string("abcdefghijklmnop",LCD_LINE_2)

sleep(3)

def lcd_init():
lcd_display(0x28,LCD_CMD) # Selecting 4 - bit mode with two rows
lcd_display(0x0C,LCD_CMD) # Display On,Cursor Off, Blink Off
lcd_display(0x01,LCD_CMD) # Clear display

sleep(E_DELAY)

def lcd_display(bits, mode):


# Send byte to data pins
# bits = data
# mode = True for character
# False for command

GPIO.output(LCD_RS, mode) # RS

# High bits
GPIO.output(LCD_D4, False)
GPIO.output(LCD_D5, False)
GPIO.output(LCD_D6, False)
GPIO.output(LCD_D7, False)
if bits&0x10==0x10:
GPIO.output(LCD_D4, True)
if bits&0x20==0x20:
GPIO.output(LCD_D5, True)
if bits&0x40==0x40:
GPIO.output(LCD_D6, True)
if bits&0x80==0x80:
GPIO.output(LCD_D7, True)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

# Toggle 'Enable' pin


lcd_toggle_enable()

# Low bits
GPIO.output(LCD_D4, False)
GPIO.output(LCD_D5, False)
GPIO.output(LCD_D6, False)
GPIO.output(LCD_D7, False)
if bits&0x01==0x01:
GPIO.output(LCD_D4, True)
if bits&0x02==0x02:
GPIO.output(LCD_D5, True)
if bits&0x04==0x04:
GPIO.output(LCD_D6, True)
if bits&0x08==0x08:
GPIO.output(LCD_D7, True)

# Toggle 'Enable' pin


lcd_toggle_enable()

def lcd_toggle_enable():
# Toggle enable
time.sleep(E_DELAY)
GPIO.output(LCD_E, True)
time.sleep(E_PULSE)
GPIO.output(LCD_E, False)
time.sleep(E_DELAY)

def lcd_string(message,line):
# Send string to display

message = message.ljust(LCD_WIDTH," ")

lcd_display(line, LCD_CMD)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

for i in range(LCD_WIDTH):
lcd_display(ord(message[i]),LCD_CHR)

if __name__ == '__main__':

try:
main()
except KeyboardInterrupt:
pass
finally:
lcd_display(0x01, LCD_CMD)
GPIO.cleanup()

Conclusion:
Hence we have demonstrated the LCD with raspberry Pi.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 2

PRACTICAL 2: Use of 4 digit 7 segment LED display to show the time:

Aim:

The aim is to create a prototype by using 4 digit 7 segment LED display to show the time on
it using Raspberry Pi.

Components used:

1. 7 or 8 segment pins (here pins starting from 1 to 8)

2. Ground pin (here pin 11)

3. 4 digit pins (here pins 13 to 16)

4. Breadboard

5. RPi

Circuit diagram:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Algorithm:

1] Import all required libraries.

2] From tm1637LED driver, initialize clock for Vcc=3.3v, DIO=20, CLK=21.

3] Initially start clock & StartClock() and ShowDoublePoint() as false.

4] Display current time,change brightness level by using Setbrightness()

5] Stop by using StopClock() method.

Python code:

from time import sleep

import tm1637

try:

import thread

except ImportError:

import _thread as thread

# Initialize the clock (GND, VCC=3.3V, Example Pins are


DIO-20 and CLK21)

Display = tm1637.TM1637(CLK=21, DIO=20, brightness=1.0)

try:

print "Starting clock in the background (press CTRL + C


to stop):"

Display.StartClock(military_time=False)

print 'Continue Python script and tweak Display!'

sleep(5)

Display.ShowDoublepoint(False)

sleep(5)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

loops = 3

while loops > 0:

for i in range(0, 10):

Display.SetBrightness(i / 10.0)

sleep(0.5)

loops -= 1

Display.StopClock()

thread.interrupt_main()

except KeyboardInterrupt:

print "Properly closing the clock and open GPIO pins"

Display.cleanup()

Conclusion:

Hence we have created a prototype by using 4 digit 7 segment LED display to show the time
on it using Raspberry Pi.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 3: Controlling Raspberry Pi with Telegram App .

PRACTICAL 3 A] Chatbot using telegram app:

Aim:

The aim is to create a chatbot in telegram app using raspberry Pi.

Installing Libraries step:

Step 1: Installing Telegram on your Mobile. The first step would be to install Telegram on
your Mobile. Telegram is available for Android, IOS.

Step2: Talk to Bot Father, The next step would be to request the Bot Father to create us a
new Bot. On the top right corner of the Home screen there will be a search icon, click on it to
search for the name “botfather”. Botfather is a Bot by itself; it will guide you to create a new
bot for you. Click on start and select /newbot as shown in the picture below. Now, the bot
will ask for few details like name of your Bot and the user name of the bot. Fill those details
and remember the username for we will needing it in future.

Step3: Getting your token for access, we have named bot as circuitdigest1 and the username
as circuitdigest1Bot. After this process the botfather will give you a Token for access. This is
like the password for your bot, people can control program your bot using this token key. So
keep it safe and do not share it with anyone. Once you have received this token key it is time
to move on to Raspberry Pi.

Step3: Getting your token for access, we have named bot as circuitdigest1 and the username
as circuitdigest1Bot. After this process the botfather will give you a Token for access. This is
like the password for your bot, people can control program your bot using this token key. So
keep it safe and do not share it with anyone. Once you have received this token key it is time
to move on to Raspberry Pi.

Step4: Telepot for installing Telegram on Raspberry Pi, Using Telegram Bot in Raspberry Pi
is made possible by the python package called Telepot. We need to install this package on
Raspberry Pi by using the following commands on Lx terminal.

Sudo apt-get intsall python-pip

Sudo pip install telepot

Once Telepot is imported into Raspberry we can use this package in our python program to
communicate with our Telegram Bot.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Step5: Once Telepot is imported into Raspberry we can use this package in our python
program to communicate with our Telegram Bot

Python code:

import time, datetime

import telepot

from telepot.loop import MessageLoop

now = datetime.datetime.now()

def action(msg):

chat_id = msg['chat']['id']

command = msg['text']

print 'Received: %s' % command

if command == '/hi':

telegram_bot.sendMessage (chat_id, str("Hi!


CircuitDigest1"))

elif command == '/time':

telegram_bot.sendMessage(chat_id,
str(now.hour)+str(":")+str(now.minute))

elif command == '/logo':

telegram_bot.sendPhoto (chat_id, photo =


"https://i.pinimg.com/avatars/circuitdigest_14641221
00_280.jpg")

elif command == '/file':

telegram_bot.sendDocument(chat_id,
document=open('/home/pi/Aisha.py'))

elif command == '/audio':

telegram_bot.sendAudio(chat_id,
audio=open('/home/pi/test.mp3'))
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

telegram_bot =
telepot.Bot('468382312'770949120:AAEY9MTNxfk-
PirCslm5qip4Ee10RGcVXE)

print (telegram_bot.getMe())

MessageLoop(telegram_bot, action).run_as_thread()

print 'Up and Running....'

while 1:

time.sleep(10)

Conclusion:

Hence we have created a chat bot in telegram app using raspberry Pi.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 3

PRACTICAL 3 B) Controlling LED via Telegram App.

Aim:

The aim of the practical is to creating a prototype and controlling LED using Telegram App
and raspberry pi.

Components used:

1. Four LED (any colour)

2. Raspberry Pi (with internet connection)

3. Breadboard

4. Connecting wires

Circuit diagram:

Python code:

import time, datetime

import RPi.GPIO as GPIO

import telepot

from telepot.loop import MessageLoop


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

white = 26

yellow = 19

red = 13

green = 6

now = datetime.datetime.now()

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

#LED White

GPIO.setup(white, GPIO.OUT)

GPIO.output(white, 0) #Off initially

#LED Yellow

GPIO.setup(yellow, GPIO.OUT)

GPIO.output(yellow, 0) #Off initially

#LED Red

GPIO.setup(red, GPIO.OUT)

GPIO.output(red, 0) #Off initially

#LED green

GPIO.setup(green, GPIO.OUT)

GPIO.output(green, 0) #Off initially


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

def action(msg):

chat_id = msg['chat']['id']

command = msg['text')

print 'Received: %s' % command

if 'on' in command:

message = "Turned on "

if 'white' in command:

message = message + "white "

GPIO.output(white, 1)

if 'yellow' in command:

message = message + "yellow "

GPIO.output(yellow, 1)

if 'red' in command:

message = message + "red "

GPIO.output(red, 1)

if 'green' in command:

message = message + "green "

GPIO.output(green, 1)

if 'all' in command:

message = message + "all "

GPIO.output(white, 1)

GPIO.output(yellow, 1)

GPIO.output(red, 1)

GPIO.output(green, 1)

message = message + "light(s)"


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

telegram_bot.sendMessage (chat_id, message)

if 'off' in command:

message = "Turned off "

if 'white' in command:

message = message + "white "

GPIO.output(white, 0)

if 'yellow' in command:

message = message + "yellow "

GPIO.output(yellow, 0)

if 'red' in command:

message = message + "red "

GPIO.output(red, 0)

if 'green' in command:

message = message + "green "

GPIO.output(green, 0)

if 'all' in command:

message = message + "all "

GPIO.output(white, 0)

GPIO.output(yellow, 0)

GPIO.output(red, 0)

GPIO.output(green, 0)

message = message + "light(s)"

telegram_bot.sendMessage (chat_id, message)


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

telegram_bot = telepot.Bot('770949120:AAEY9MTNxfk-
PirCslm5qip4Ee10RGcVXE')

print (telegram_bot.getMe())

MessageLoop(telegram_bot, action).run_as_thread()

print 'Up and Running....'

while 1:

time.sleep(10)

Conclusion:

Hence we have done with the practical for creating a prototype and controlling LED using
Telegram App and raspberry pi.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 4

Practical 4: Interfacing Raspberry Pi with RFID

Aim:

The aim of the practical is creating a prototype for interfacing Raspberry Pi using RFID.

Components Used:

1. Raspberry Pi (with booted SD card)

2. Push button

3. Buzzer

4. 16x2 LCD

5. 10k pot

6. 10K Resistor

7. LED

8. 1k Resistor

9. Bread board

10. RFID Reader

11. Power 5 volt

12. RFID tags or Cards

13. Ethernet Cable

14. Connecting wires

Installing Dependencies:

sudo apt-get install git-core


SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

sudo apt-get update

sudo apt-get upgrade

git clone git://git.drogon.net/wiringPi

cd wiringPi

git pull origin

cd wiringPi

./build

Test the installation of wiringPi library, use below commands:

gpio –v

gpio readall

Circuit Diagram

Python Code:

import serial
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

import Rpi.GPIO as GPIO

from time import sleep

Buzz=14

Led=17

GPIO.setwarnings (False)

GPIO.setmode (GPIO.BCM)

GPIO.setup(Buzz,GPIO.OUT)

GPIO.setup(led,GPIO.OUT)

GPIO.output(Buzz,False)

Gpio.output(led,False)

def read_rfid():

print(“Reading Id:”)

ser=serial.Serial(„dev/ttyUSB0‟)

ser.baudrate=9600

data=ser.read(12)

ser.close()

return data

def Check():

print(“Start”)

id=read_rfid()

print(id)

if id==”1E005C079603”:

print(“Allow Access”)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

GPIO.output (led, True)

sleep (1)

GPIO.output (led, False)

else:

print (“Access Denied”)

GPIO.output(Buzz, True)

sleep(1)

GPIO.output(Buzz, False)

def destroy():

GPIO.cleanup()

try:

while True:

Check()

except KeyboardInterrupt:

destroy()

Conclusion:

Hence we have done the practical for creating a prototype for interfacing Raspberry Pi using
RFID.
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

PRACTICAL 5
PRACTICAL 5: Fingerprint Sensor interfacing with Raspberry Pi

Aim:

The aim of the practical is creating a prototype for fingerprint sensor interfacing with
Raspberry Pi.

Components used:
1. Raspberry Pi
2. USB to Serial converter
3. Fingerprint Module
4. Push buttons
5. Bread Board Jumper wires
6. LED
7. Resistor 150 ohm -1 k ohm

Circuit diagram:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Installing Library for Finger Print Sensor:

Step 1: To install this library, root privileges are required. So first we enter in root by given
command:
sudo bash
Step 2: Then download some required packages by using given commands:
wget –O – http://apt.pm-codeworks.de/pm-codeworks.de.gpg | apt-key add –
wget http://apt.pm-codeworks.de/pm-codeworks.list -P /etc/apt/sources.list.d/

Step 3: After this, we need to update the Raspberry pi and install the downloaded finger print
sensor library:
sudo apt-get update
sudo apt-get install python-fingerprint –yes

Step 4: After installing library now we need to check USB port on which your finger print
sensor is connected, by using given the command:
ls /dev/ttyUSB*
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

Python Code:
import time
frompyfingerprint.pyfingerprint import PyFingerprint
importRPi.GPIO as gpio

btn1=5
btn2=6
led1=13
led2=19

HIGH=1
LOW=0

gpio.setwarnings(False)
gpio.setmode(gpio.BCM)

gpio.setup(btn1, gpio.IN, pull_up_down=gpio.PUD_UP)


gpio.setup(btn2, gpio.IN, pull_up_down=gpio.PUD_UP)

gpio.setup(led1, gpio.OUT ,initial=gpio.LOW)


gpio.setup(led2, gpio.OUT ,initial=gpio.LOW)

try:
f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF,
0x00000000)

defenrollFinger():
time.sleep(2)
print('Waiting for finger...')
print("\nPlace Finger")
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

f.readImage()
f.convertImage(0x01)
time.sleep(2)
result = f.searchTemplate()
positionNumber = result[0]
if ( positionNumber>= 0 ):
print('Template already exists at position #' +
str(positionNumber))
print("Finger ALready")
print(" Exists ")
time.sleep(2)
return
print('Remove finger...')
time.sleep(2)
print('Waiting for same finger again...')
print("Place Finger")
print(" Again ")
while ( f.readImage() == False ):
pass
f.convertImage(0x02)
if ( f.compareCharacteristics() == 0 ):
print("Fingers do not match")
time.sleep(2)
return
f.createTemplate()
positionNumber = f.storeTemplate()
print('Finger enrolled successfully!')
print("Stored at Pos:")
print(str(positionNumber))
print("successfully")
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

print('New template position #' + str(positionNumber))


time.sleep(2)
defsearchFinger():
print('Searching for finger...')
time.sleep(2)
f.readImage()
f.convertImage(0x01)
time.sleep(2)
result = f.searchTemplate()
positionNumber = result[0]
accuracyScore = result[1]
ifpositionNumber == -1 :
print('No match found!')
time.sleep(2)
return
else:
print('Found template at position #' + str(positionNumber))
print("Found at Pos:")
print(str(positionNumber))
gpio.output(led2,HIGH)
time.sleep(2)
gpio.output(led2,LOW)
while 1:
gpio.output(led1,HIGH)
ifgpio.input(btn1)==0:
gpio.output(led1,LOW)
enrollFinger()
ifgpio.input(btn2)==0:
searchFinger()
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50

else:
pass

Conclusion:

Hence we have created a practical for creating a prototype for fingerprint sensor interfacing
with Raspberry Pi.

You might also like