Professional Documents
Culture Documents
Department of
INFORMATION TECHNOLOGY
T.Y.BSc.(I.T.) SEM – V
Paper - RJSUITP502
Internet of Things (IoT)
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.
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
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.
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 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.
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.
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:
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.
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
4. If the value of pullup register is false the blink the LED in a super loop.
Python code:
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:
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
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:
Python code:
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)
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
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
2] Set warnings to false, use Broadcom SOC channel by setting mode to GPIO BOARD
4] If the value of pull up register is false then blink the led in super loop.
Python code:
import time
GPIO.setmode(GPIO.BCM)
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
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:
Python code:
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:
Python code:
#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import sleep
# 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:
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)
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
# 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)
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
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
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:
4. Breadboard
5. RPi
Circuit diagram:
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50
Algorithm:
Python code:
import tm1637
try:
import thread
except ImportError:
try:
Display.StartClock(military_time=False)
sleep(5)
Display.ShowDoublepoint(False)
sleep(5)
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50
loops = 3
Display.SetBrightness(i / 10.0)
sleep(0.5)
loops -= 1
Display.StopClock()
thread.interrupt_main()
except KeyboardInterrupt:
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
Aim:
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.
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 telepot
now = datetime.datetime.now()
def action(msg):
chat_id = msg['chat']['id']
command = msg['text']
if command == '/hi':
telegram_bot.sendMessage(chat_id,
str(now.hour)+str(":")+str(now.minute))
telegram_bot.sendDocument(chat_id,
document=open('/home/pi/Aisha.py'))
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()
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
Aim:
The aim of the practical is to creating a prototype and controlling LED using Telegram App
and raspberry pi.
Components used:
3. Breadboard
4. Connecting wires
Circuit diagram:
Python code:
import telepot
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)
#LED Yellow
GPIO.setup(yellow, GPIO.OUT)
#LED Red
GPIO.setup(red, GPIO.OUT)
#LED green
GPIO.setup(green, GPIO.OUT)
def action(msg):
chat_id = msg['chat']['id']
command = msg['text')
if 'on' in command:
if 'white' in command:
GPIO.output(white, 1)
if 'yellow' in command:
GPIO.output(yellow, 1)
if 'red' in command:
GPIO.output(red, 1)
if 'green' in command:
GPIO.output(green, 1)
if 'all' in command:
GPIO.output(white, 1)
GPIO.output(yellow, 1)
GPIO.output(red, 1)
GPIO.output(green, 1)
if 'off' in command:
if 'white' in command:
GPIO.output(white, 0)
if 'yellow' in command:
GPIO.output(yellow, 0)
if 'red' in command:
GPIO.output(red, 0)
if 'green' in command:
GPIO.output(green, 0)
if 'all' in command:
GPIO.output(white, 0)
GPIO.output(yellow, 0)
GPIO.output(red, 0)
GPIO.output(green, 0)
telegram_bot = telepot.Bot('770949120:AAEY9MTNxfk-
PirCslm5qip4Ee10RGcVXE')
print (telegram_bot.getMe())
MessageLoop(telegram_bot, action).run_as_thread()
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
Aim:
The aim of the practical is creating a prototype for interfacing Raspberry Pi using RFID.
Components Used:
2. Push button
3. Buzzer
4. 16x2 LCD
5. 10k pot
6. 10K Resistor
7. LED
8. 1k Resistor
9. Bread board
Installing Dependencies:
cd wiringPi
cd wiringPi
./build
gpio –v
gpio readall
Circuit Diagram
Python Code:
import serial
SEMESTER 5 Subject: INTERNET OF THINGS Roll No: 50
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
sleep (1)
else:
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
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)
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
else:
pass
Conclusion:
Hence we have created a practical for creating a prototype for fingerprint sensor interfacing
with Raspberry Pi.