0% found this document useful (0 votes)
12 views

New Iot Practical

Uploaded by

jayeshthorat2703
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

New Iot Practical

Uploaded by

jayeshthorat2703
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

T.Y.B.Sc. (I.T.

) SEM-V INTERNET OF THINGS

PRACTICAL NO – 01

AIM: Starting Raspbian OS, Familiarizing with Raspberry Pi Components


and interface, Connecting to Ethernet, Monitor, USB.

Raspberry pi is the name of the “credit card-sized computer board” developed by the
Raspberry pi foundation, based in the U.K. It gets plugged in a TV or monitor and provides a
fully functional computer capability. It is aimed at imparting knowledge about computing to even
younger students at the cheapest possible price.

Raspberry Pi is developed by Raspberry Pi Foundation in the United Kingdom. The Raspberry


Pi is a series of powerful, small single-board computers. Raspberry Pi is launched in 2012 and
there have been several iterations and variations released since then.

Raspbian is a free operating system based on Debian, optimized for use in Raspberry Pi boards.
Raspbian is the recommended operating system for working with Raspberry Pi boards by the
Raspberry Pi foundation. There are two different flavors of Raspbian which can be installed:

 Raspbian (Full Version/Desktop Version)


 Raspbian Lite

List of Raspberry pi models and releases year:

 pi 1 model B – 2012
 pi 1 model A – 2013
 pi 1 model B+ - 2014
 pi 1 model A+ – 2014
 Pi 2 Model B – 2015
 Pi 3 Model B - 2016
 Pi 3 Model B+ - 2018
 Pi 3 Model A+ - 2019
 Pi 4 Model A – 2019
 Pi Model B – 2020
 Pi 400 – 2021

1
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Hadware Requirements:
 Raspberry Pi 3B+,
 Power Adapter,
 Card Reader,
 PC with OS installed,
 SD card(16 GB)
 HDMI to VGA or HDMI to HDMI Connector
 Key Board and Mouse

Software Requirements
 Noobs or Raspbian
 SD card Formatter
 RPi Imager or win32 Disk Imager
 VNC Viewer

Network Installation : Using RPi Image and Internet

The Raspberry Pi OS operating system via the Raspberry Pi Imager


Using the Raspberry Pi Imager is the easiest way to install Raspberry Pi OS on your SD card.

Step1: Download and launch the Raspberry Pi Imager


 Visit the Raspberry Pi downloads page

2
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 2: Click on the link for the Raspberry Pi Imager that matches your operating system

Step 3: When the download finishes, click it to launch the installer

Step 4: Using the Raspberry Pi Imager

Anything that’s stored on the SD card will be overwritten during formatting. If your SD card
currently has any files on it, e.g. from an older version of Raspberry Pi OS, you may wish to back
up these files first to prevent you from permanently losing them.

 Follow the instructions to install and run the Raspberry Pi Imager:

 Insert your SD card into the computer or laptop SD card slot

 In the Raspberry Pi Imager, select the OS that you want to install and the SD card you
would like to install it on

3
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Note: You will need to be connected to the internet the first time for the the Raspberry Pi Imager
to download the OS that you choose. That OS will then be stored for future offline use.
Being online for later uses means that the Raspberry Pi imager will always give you the
latest version.

4
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

 Then simply click the button.


 Wait for the Raspberry Pi Imager to finish writing
 After writing wait it its verified
 Once you get the following message, you can eject your SD card

Step 5: Insert microSD card into Raspberry Pi

5
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Connecting Raspberry Pi 3 B+ Model:

 A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose


input/output) pins along the top edge of the board. A 40-pin GPIO header is found on all
current Raspberry Pi 3 B+ boards.
 Prior to the Raspberry Pi 1 Model B+ (2014), boards comprised a shorter 26-pin header.
The GPIO header on all boards (including the Raspberry Pi 400) have a 0.1" (2.54mm) pin
pitch.

6
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Specification Comparison:

Conclusion:

Thus, Raspbian OS was installed, Raspberry Pi Components and Interface were studied and
implemented and Raspberry was also connected to Ethernet, Monitor and USB.

7
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 02

AIM: Program to display different LED patterns with Raspberry Pi.

Raspberry Pi has a powerful feature in the form of the General Purpose Input / Output (GPIO
Pins). GPIO Pins form the physical interface between the real world and the Raspberry Pi.
Different external components like LEDs, Motors, Sensors, Display, etc. are connected to the
Raspberry Pi through these GPIO Pins.
In this practical, we are going to blink an LED using Raspberry Pi and hence the knowledge
of all the GPIO Pins is important.

The latest revision of the Raspberry Pi series i.e. Raspberry Pi 3 Model B has 40 GPIO Pins. Out
of these 40 GPIO pins few are power pins i.e. 3.3V Pins (2), 5V Pins (2) and GND (8). In the rest
of the 28 pins, few are truly general purpose GPIO Pins while few pins have a dual function.

Components Required:

 Raspberry Pi 3 Model B+
 A Breadboard
 4- LED’s with different colors
 A 330 ohm resistor
 Male to Female jumper wires
 Female to Female jumper wires

8
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Q1. Interface Raspberry Pi with single LED and blink LED.

Circuit Diagram:

Pin Configuration:

LED Physical Pin GPIO Number

Python code:

1-LED.py

import RPi.GPIO as GPIO


import time

GPIO.setwarnings (False)

GPIO.setmode(GPIO.BOARD)
GPIO.setup (17,GPIO.OUT)

while True:
GPIO.output (17,GPIO.HIGH)
print ('LED IS ON')
time.sleep(2)

GPIO.output (17,GPIO.LOW)
print('LED IS OFF')
time.sleep(2)

9
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Pin Configuration for 4-LED’s:

Components Physical Pin Wire color

Circuit Diagram:

10
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Q2. Interface Raspberry Pi with 4 LEDS and blink LEDS with different patterns.

Case-I: 1-ON 1-OFF LED pattern


4 LED.py

import RPi.GPIO as GPIO


from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(8,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(10,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(12,GPIO.OUT,initial=GPIO.LOW)

while True:
GPIO.output(7,GPIO.HIGH)
print("LED on")
sleep(1)
GPIO.output(7,GPIO.LOW)
print("LED off")
sleep(1)
GPIO.output(8,GPIO.HIGH)
print("LED on")
sleep(1)
GPIO.output(8,GPIO.LOW)
print("LED off")
sleep(1)
GPIO.output(10,GPIO.HIGH)
print("LED on")
sleep(1)
GPIO.output(10,GPIO.LOW)
print("LED off")
sleep(1)
GPIO.output(12,GPIO.HIGH)
print("LED on")
sleep(1)
GPIO.output(12,GPIO.LOW)
print("LED off")
sleep(1)
GPIO.cleanup

11
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Output:

12
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Case-2: 2 ON 2 OFF LED Pattern

2 ON 2 OFF LED.py

import RPi.GPIO as GPIO


from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(8,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(10,GPIO.OUT,initial = GPIO.LOW)
GPIO.setup(12,GPIO.OUT,initial = GPIO.LOW)

while True:
GPIO.output(7,GPIO.HIGH)
GPIO.output(8,GPIO.HIGH)
print("LED on")
sleep(1)

GPIO.output(7,GPIO.LOW)
GPIO.output(8,GPIO.LOW)
print("LED off")
sleep(1)

GPIO.output(10,GPIO.HIGH)
GPIO.output(12,GPIO.HIGH)
print("LED on")
sleep(1)

GPIO.output(10,GPIO.LOW)
GPIO.output(12,GPIO.LOW)
print("LED off")
sleep(1)

GPIO.cleanup

13
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Output:

14
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Case-3: 4-LED SERIALLY ON-OFF

LED Serially.py

import RPi.GPIO as GPIO


from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

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


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

while True:
GPIO.output(7, GPIO.HIGH)
sleep(1)
GPIO.output(8, GPIO.HIGH)
sleep(1)
GPIO.output(10, GPIO.HIGH)
sleep(1)
GPIO.output(11, GPIO.HIGH)
sleep(1)
print("ON")

GPIO.output(7, GPIO.LOW)
sleep(1)
GPIO.output(8, GPIO.LOW)
sleep(1)
GPIO.output(10, GPIO.LOW)
sleep(1)
GPIO.output(11, GPIO.LOW)
sleep(1)
print("OFF")

GPIO.cleanup

15
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Output:

Conclusion:

Hence the different LED’s successfully interfaced with Raspberry Pi model.


Also LEDS blinked with different patterns as 1-ON 1-OFF, 2-ON 2-OFF and serially
ON - OFF pattern.

16
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 03

AIM: Interface Raspberry Pi with 4-digit Seven Segment module and write a
Program to display current time on it.

7 Segment Display has seven segments in it and each segment has one LED inside it to display
the numbers by lighting up the corresponding segments. Like if you want the 7-segment to
display the number "5" then you need to glow segment a, f, g, c and d by making their
corresponding pins high. There are two types of 7-segment displays: Common Cathode and
Common Anode, here we are using Common Cathode seven segment display.

In this practical we will Interface 4-digit Seven Segment Display Module with Raspberry Pi
and display Time over it.

Components Required:

Raspberry Pi 3 Model B+
TM1637 Module
4 - Connecting Wires (Female to Female)

TM1637 IC Features:

 Display common anode for the four red LED


 Powered supply by 3.3V/5V
 It supports two wire serial interface and provides two DIO pins (CLK and DIO), for
connecting it in Raspberry Pi
 Four common anode tube display module is driven by IC TM1637
 TM1637 is a LED drive control device, with inbuilt key scan functionality
 TM1637 devices support to control the brightness (8 levels) of the display

17
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

TM1637 Seven Segment Display Module Pinout:

The pin out of the TM1637 4-digit Seven Segment Display is shown below. It has 4 pins those are
CLK, DIO, VCC, and GND.
All the pins of this sensor module are digital, except VCC and Ground, and the device can operate
in the 3.3V to 5V voltage range.

Pin Name Function

The Clock pin helps to keep the clock pulse sync in with module and
CLK
microcontroller.

The data pin helps in sending and receiving data from the
DIO
microcontroller.

The ground (GND) is used to make the common ground with external
GND
devices.

VCC The power (VCC) input pin to power the module. Accepts 3.3-5V VCC.

18
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Pin Configuration:

TM1637 Module Raspberry Pi pins Physical Pin Numbers

Circuit Diagram:

19
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Setting up Raspberry Pi for displaying Time:

1. To program our Raspberry with the TM1637 display module we will require the TM1637
library.

A bare four digit 7-Segment Displays usually requires 12 connection pins but the TM1637
LED Driver removes the need of the extra wiring for the 7-Segments and the entire setup can
be controlled just by using 2 wires (DIO and CLK) and two more for power.

2. Make a new folder with name: actor-led-7segment-4numbers

3. Download and Copy TM1637 library and save it in your Raspberry with the name tm1637.py.

4. Open a new file in Thonny python and write main code with file name clock.py

5. Open command prompt and change directory to respective folder as shown below:

cd /home/pi/actor-led-7segment-4numbers

6. Run the main python code:

sudo python clock.py

20
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Python code:

clock.py

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)
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()

21
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Output:

Conclusion:
Hence the demonstration of displaying Time over 4-Digit 7-Segment Display is successfully
completed with Raspberry Pi and TM1637display driver module.
The TM1637 display driver can be also used for many embedded projects for numerical data
display, time and temperature display.

22
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 04

AIM: Program for controlling Raspberry Pi GPIO pins with Telegram Bot.

Telegram is a popular cloud-based messaging application used for sending messages, videos, and
images privately or in groups with end-to-end encryption.

Additionally, Telegram has an API bot that allows the human to talk to machines. Using
Telegram bot we can send and receive message, we can create IOT platform based home
automation to control our home appliances remotely.

In this practical, we are going to control a LED connected with Raspberry Pi using Telegram
Bot which will send and receive the commands from Raspberry Pi board. We will connect LED
at GPIO 11 to control remotely to make it ON / OFF by sending the command text over
telegram bot.

Components Required:

 Raspberry Pi3 Model B’s with Installed Raspbian


 RED LED
 220 ohm Resistor
 Internet connection (Wired or Wireless) to access Pi Desktop
 VNC client on a wired or wireless device
 Breadboard
 Jumper Wires

23
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 1: Open Telegram app in your system or mobile

1.1 Open Telegram app in your system or mobile


1.2 Search and open "BotFather"
1.3 Start "BotFather"

1.4 Create a new Bot with Bot name, Bot username and obtain access token

24
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

1.5 Search your Bot name:

Step 2: Setup Raspberry Pi

Step 3: Install TelegramBot on Raspberry Pi

3.1 Install "Python Package Index"


sudo apt-get install python-pip

3.2 Install "telepot" Library:

The telepot library enables the Raspberry Pi to communicate with the Telegram bot using the
API.

sudo pip install telepot

25
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 4: Run the Python Code

4.1 Clone the git

git clone https://github.com/salmanfarisvp/TelegramBot.git

4.2 Paste your Bot Token here

bot = telepot.Bot('Bot Token')

4.3 Run the Code


python telegrambot.py

Step 5: Connect LED to Pi: Circuit Diagram

26
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Pin Configuration:

LED Physical Pin GPIO Number

Step 6: Python Code

import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO

#LED
def on(pin):
GPIO.output(pin,GPIO.HIGH)
return
def off(pin):
GPIO.output(pin,GPIO.LOW)
return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(17, GPIO.OUT)

def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']

print ('Got command: %s' % command)

if command == 'on':
bot.sendMessage(chat_id, on(17))
elif command =='off':
bot.sendMessage(chat_id, off(17))

bot = telepot.Bot('Bot Token')


bot.message_loop(handle)
print ('I am listening: RKT_College')

while 1:
time.sleep(10)
Use Bot Token: 6628306168:AAE-T2NvNJV99JvRvFhgEeqgLeXZPXyRdOc

27
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 7: Send Command from Bot’s Chat Window: RKT_college

Conclusion:

Thus, successfully controlled Raspberry Pi GPIO pins with Telegram Bot.


By sending valid commands through Bot’s chat window, one can write/read Raspberry Pi GPIO
pins. That's mean one can control status of any devices over the telegram using Raspberry Pi and
control circuit.

28
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 05

AIM: Interface Raspberry Pi with Fingerprint Module and write a program to


capture and verify Fingerprint.

In present time we can see fingerprint-based systems everywhere in our daily life like for
attendance in offices, employee verification in banks, for cash withdrawal or deposits in ATMs,
for identity verification in government offices etc.
Using this Raspberry Pi Fingerprint System, we can enroll new finger prints in the system and can
delete the already fed finger prints.

Components Required:
 Raspberry Pi
 USB to Serial converter
 R307 Fingerprint Module
 Jumper wires

R307 Fingerprint Module:

R307 Fingerprint Module consists of optical fingerprint sensor, high-speed DSP processor,
high-performance fingerprint alignment algorithm, high-capacity FLASH chips and other
hardware and software composition, stable performance, simple structure, with fingerprint entry,
image processing, fingerprint matching, search and template storage and other functions.

29
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Pin Functions:
R307 Fingerprint Module consists of optical fingerprint sensor, Supply voltage: DC 4.2 ~ 6.0V

Connect fingerprint module to USB Serial converter:

USB to Serial
Pin No. Finger Print Module Wire Color
Converter

30
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Circuit Diagram:

31
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Setting up Rpi with Fingerprint module:

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 wget 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/

32
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

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: we need to check USB port on which your finger print sensor is connected. Use this
USB port in our Python script.

ls /dev/ttyUSB*

Step 5: Now go to the examples directory.

cd /home/pi/Desktop/pyfingerprint-Development/src/files/examples

33
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 6: Run the sample file to test to see if the finger print sensor is detected and ready for
access.

The above data should appear, which allows you to display the positions under which an imprint
is stored by selecting a page (0-3).python example_enroll.py

Step 7: Now execute other scripts, to make sure Fingerprint module is working.

Step 8: Now, Run example_downloadimage.py script to see whether our finger is recognized.

Step 9: After indicating BLUE Light put the finger on glass surface. If the fingerprint is
detected, it displays below message.

34
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 10: The fingerprint image will be stored at temp folder:


/tmp/fingerprint.bmp

Python Code for capturing Fingerprint:

#example_downloadimage

import tempfile
from pyfingerprint.pyfingerprint import PyFingerprint

# Reads image and download it


# Tries to initialize the sensor

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

if ( f.verifyPassword() == False ):
raise ValueError('The given fingerprint sensor password is wrong!')

except Exception as e:
print('The fingerprint sensor could not be initialized!')
print('Exception message: ' + str(e))
exit(1)

# Gets some sensor information

print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+


str(f.getStorageCapacity()))

# Tries to read image and download it

try:
print('Waiting for finger...')

#Wait that finger is read

while ( f.readImage() == False ):

35
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

pass

print('Downloading image (this take a while)...')

imageDestination = tempfile.gettempdir() + '/fingerprint.bmp'


f.downloadImage(imageDestination)

print('The image was saved to "' + imageDestination + '".')

except Exception as e:
print('Operation failed!')
print('Exception message: ' + str(e))
exit(1)

36
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Results:

fingerprint.bmp

Conclusion:

Fingerprint testing is done by connecting the R307 fingerprint sensor using USB to TTL
which is connected directly to the USB port of the Raspberry Pi. Then fingerprint capturing is
done by running the program.
Fingerprint module successfully recorded user’s fingerprint with different kinds of sample data. It
also managed to search and download the fingerprint data that has been recorded.

37
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 06

AIM: Interface Raspberry Pi with GPS module and write a program to


display the current location (Latitude and Longitude).

GPS stands for Global Positioning System and used to detect the Latitude and Longitude of any
location on the Earth, with exact UTC time (Universal Time Coordinated). This device receives
the coordinates from the satellite for each and every second, with time and date.

GPS module sends the data related to tracking position in real time, and it sends so many data in
NMEA format (National Marine Electronics Association).

NMEA format consist several sentences, in which we only need one sentence. This sentence
starts from $GPGGA and contains the coordinates, time and other useful information.
This GPGGA is referred to Global Positioning System Fix Data.

We can extract coordinate from $GPGGA string by counting the commas in the string.
Suppose you find $GPGGA string and stores it in an array, then Latitude can be found after two
commas and Longitude can be found after four commas.

38
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

GPS coordinates are a unique identifier of a precise geographic location on the earth, usually
expressed in alphanumeric characters. GPS coordinates are usually expressed as the combination
of latitude and longitude.
Latitude coordinates measure distance north and south from the equator. Longitude
coordinates measure distance east and west from the prime meridian.

There are different uses of Global Positioning System (GPS):

1. Location: Determining a position.


2. Navigation: Getting from one location to another.
3. Tracking: Monitoring object or personal movement.
4. Mapping: Creating maps of the world.
5. Timing: Making it possible to take precise time measurements.

Required Components:

 Raspberry Pi 3B+
 Neo 6M v2 GPS Module
 Power Adapter
 SD card (16GB)
 HDMI to VGA Connector
 Key Board and Mouse

39
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

NEO-6MV2 GPS (Global Positioning System) module with active Antenna:

The NEO-6MV2 is a GPS (Global Positioning System) module and is used for navigation. The
module simply checks its location on earth and provides output data which is longitude and
latitude of its position.

Features and Electrical Characteristics:

 UART Interface at the output pins (Can use SPI ,I2C and USB by soldering pins to the
chip core)
 Maximum navigation update rate: 5Hz
 Default baud rate: 9600bps
 EEPROM with battery backup
 Supply voltage: 3.6V
 Maximum DC current at any output: 10mA
 Operation limits: Gravity-4g, Altitude-50000m, Velocity-500m/s

40
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Below is the $GPGGA String, along with its description:

$GPGGA,104534.000,7791.0381,N,06727.4434,E,1,08,0.9,510.4,M,43.9,M,,*47

$GPGGA,HHMMSS.SSS,latitude,N,longitude,E,FQ,NOS,HDP,altitude,M,height,M,,checksum data

Identifier Description

$GPGGA Global Positioning system fix data

Time in hour minute seconds and milliseconds


HHMMSS.SSS
format.

Latitude Latitude (Coordinate)

N Direction N=North, S=South

Longitude Longitude(Coordinate)

E Direction E= East, W=West

FQ Fix Quality Data

NOS No. of Satellites being Used

HPD Horizontal Dilution of Precision

Altitude Altitude from sea level

M Meter

Height Height

Checksum Checksum Data

41
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Connect GPS Module to RPi

Neo-6M V2 GPS Module Raspberry Pi Functions Physical Pins

Circuit Diagram:

42
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Set Up the UART in Raspberry Pi

Step1: Update the Raspberry Pi:

sudo apt-get update


sudo apt-get upgrade

Step 2: edit the /boot/config.txt file

sudo nano /boot /config.txt

At the bottom of the config.txt file, add the following lines

dtparam=spi=on

dtoverlay=pi3-disable-bt

core_freq=250

enable_uart=1

force_turbo=1

ctrl+x to exit and press y and enter to save.

43
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 3: Before proceeding, make a copy of cmdline.txt file

sudo cp boot/cmdline.txt boot/cmdline_backup.txt

Now, edit file cmdline.txt

sudo nano /boot.cmdline.txt

Remove console=serial0,115200 and Modify root=/dev/mmcblk0p2

Replace the content with;

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4


elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-
consoles

Press ctrl+x to exit and press y and enter to save.

Step 4: Reboot Raspberry Pi using the command sudo reboot

Step 5: Disable the Raspberry Pi Serial Getty Service

a. If in your output, Serial0 is linked with ttyAMA0, then to disable it use the below command,

sudo systemctl stop [email protected]


sudo systemctl disable [email protected]

b. If in your output Serial0 is linked with ttys0, then to disable it use the below command,

sudo systemctl stop [email protected]


sudo systemctl disable [email protected]

Step 6: Activate Ttys0

To enable the ttyso use following command,

sudo systemctl enable [email protected]

44
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 7: Install Minicom and Pynmea2

Use minicom python library to connect with the GPS module and make sense of the data.

sudo apt-get install minicom

Use pynmea2 python library to parse the received NMEA data.

sudo pip install pynmea2

Step 8: To test the GPS run the command

sudo cat /dev/ttyAMA0

You'll get the output as shown below. That basically means that it’s working. To stop this type
Ctrl + c

This sentence gives you Latitude found after two commas and Longitude found after four
commas.

45
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Python code for the interfacing of the GPS module with Raspberry pi

gps.py

import serial
Import time
import string import pynmea2

while True:
port=“/dev/ttyAMAO”
ser=serial.Serial(port,baudrate=9600,timeout=0.5)
dataout =pynmea2.NMEAStreamReader()
newdata=ser.readline()

if newdata[0:6]==“$GPRMC”:
newmsg=pynmea2.parse(newdata)

lat=newmsg.latitude
lng=newmsg.longitude

gps=“Latitude=" +str(lat) + “and Longitude=" +str(lng)

print(gps)

46
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Result:

Hence this window provides the data of your exact position in terms of Latitude and Longitude.

Conclusion:

Hence GPS module successfully interfaced with Raspberry Pi which helped to read co-ordinates
of current location.
By making Raspberry Pi physical connections and python code, exact position of current location
accessed in terms of Latitude and Longitude co-ordinates.

47
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 07

AIM: Interface Raspberry Pi with Pi Camera and write a program to capture


Image and record Video.

In this practical, we are demonstrating Visitors Monitoring System with Image capture and
recording functionality. This Monitoring system will digitize and automate the whole visitor
entries, and there will be no need to maintain them manually.

We are interfacing Pi camera with Raspberry Pi to capture the image and record videos of every
visitor which has entered through the Gate or door. This captured image is saved in the system
with the Date and time of the entry.
This system is very useful in offices, factories where visitor entry record is maintained for
visitors, employees. So this can be very useful for security purpose.

Components Required:

 Raspberry Pi 3B+
 Power Adapter
 SD card (16GB)
 HDMI to VGA Connector
 Key Board and Mouse
 Pi Camera

The pi Camera module is a camera that can be used to take pictures and high definition video.
Raspberry Pi Board has CSI (Camera Serial Interface) interface to which we can attach the
PiCamera module directly.
This Pi Camera module can attach to the Raspberry Pi’s CSI port using a 15-pin ribbon cable

Pi Camera Module (V 1.3)

48
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Features of Pi Camera V1.3

 Resolution – 5 MP
 HD Video recording – 1080p @30fps, 720p @60fps, 960p @45fps and so on.
 It Can capture wide, still (motionless) images of a resolution 2592x1944 pixels
 CSI Interface enabled.

Connect the Camera Module:

1. Locate the Camera Module port


2. Gently pull up on the edges of the port’s plastic clip
3. Insert the Camera Module ribbon cable; make sure the connectors at the bottom of the ribbon
cable are facing the contacts in the port.
4. Push the plastic clip back into place

Circuit Diagram:

49
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

To Enable Camera functionality on Raspberry Pi

Step 1: Open the raspberry pi configuration using the following command,

sudo raspi-config

Step 2: Then select Interfacing options in which select the camera option to enable its
functionality.

50
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Step 3: reboot Raspberry Pi:


Now we can access the camera on Raspberry Pi and capture images and videos using Pi Camera
module on Raspberry Pi.

Step 4: The camera module can be controlled using Python.


This requires the picamera library which provides different classes for Raspberry Pi.
Out of which we are interested in PiCamera class which is for camera module.

sudo apt-get install python3-picamera

Step 5: upgrade after installing the picamera library:

sudo apt-get update


sudo apt-get upgrade

51
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Python Code for Image Capturing:

#import picamera library


import picamera
from time import sleep

#create object for PiCamera class


camera = picamera.PiCamera()

#set resolution
camera.resolution = (1024, 768)
camera.brightness = 60
camera.start_preview()
time.sleep(5)

#store image
camera.capture('/home/pi/Desktop/pic1.jpg')
camera.stop_preview()

Functions Uses
import picamera library This picamera library has PiCamera class for camera
module. So, we have to create object for PiCamera class.

Class and its object We need to create object for PiCamera class.

E.g. Camera = picamera.PiCamera()

capture() It is used to capture images using Pi Camera.

E.g. Camera.capture(“/home/pi/image.jpeg”)

resolution= (width,height) The resolution can be specified as (width, height)

E.g. Camera.resolution = (1024, 768)

start_preview() It displays the preview overlay of default or specified


resolution.

E.g. Camera.start_preview()

stop_preview() It is used to close the preview overlay.

E.g. Camera.stop_preview()

52
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Python Code for Video recording:

import picamera
from time import sleep

camera = picamera.PiCamera()
camera.resolution = (640, 480)
print()

#start recording using pi camera


camera.start_recording("/home/pi/Desktop/rec.h264")

#wait for video to record


camera.wait_recording(10)

#stop recording
camera.stop_recording()
camera.close()
print("video recording stopped")

Functions Uses
start_recording() It is used to start video recording and store it in h264 format.

E.g. Camera.start_recording(‘demo.h264’)
wait_recording(timeout) Wait on video encoder for specified timeout seconds.

E.g. Camera.wait_recording(60)
stop_recording() It is used to stop video recording.

E.g. Camera.stop_recording()

Conclusion:

Hence Pi camera successfully interfaced with Raspberry Pi to capture the image and record
videos of every visitor.

In this practical, the Pi Camera module and its Python library have been used as basic tool for
capturing and recording real-time data.
The combination of picamera and Python is a powerful tool with applications in many
technologies ranging from Smartphone facial recognition, to security systems, and even
autonomous vehicle navigation.

53
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

PRACTICAL NO – 08

AIM: Interfacing Raspberry Pi with RFID and writing a program to read the
RFID.

Radio Frequency Identification (RFID) devices are an essential part of almost all physical
security systems. RFID cards and card readers are used to restrict access to buildings or rooms.
In this context, the RFID card stores a unique identification number that is wirelessly detected by
a RFID card reader attached. If the RFID card’s identification number matches an identification
number from a stored list of authorized cards, then user is declared as authorized.

RFID devices operate at high-frequency from 3MHz to 30MHz. But most RFID devices usually
operate at 13.56MHz.

In this practical, we will use the EM-18 RFID Reader Module and the Raspberry Pi to trigger
a 5V relay when an RFID card’s identification number matches a number stored on the Raspberry
Pi.

Components Required:

 Raspberry Pi 3 Model B+


 EM-18 RFID Reader Module
 Few RFID Cards
 USB to Serial Converter
 Connecting Wires

54
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Working:

The RFID system comprises three components: a Raspberry Pi, an RFID card reader, and an
RFID card:
All RFID cards and tags have two components – an IC that stores the unique identification
number and a coil of wire that acts as the radio frequency antenna:

The RFID card reader also has a coil of copper wire. This coil creates a magnetic field when a
current flows through it. When the RFID card is placed near the card reader, the magnetic field
from the card reader induces a current in the card’s wire coil. This current is enough to power the
card’s onboard IC. The card reader can then read the unique identification number on the card.
The card’s identification number is then transmitted from the card reader to Raspberry Pi.
The RFID card reader we are going to use can also write identification information to RFID
cards or tags. This is useful for creating new RFID cards.

The main differences between EM-18 and RC522 RFID Modules are:
 EM-18 is based on 125 KHz Radio Frequency Communication while the RC522 is based
on 13.56 MHz Frequency.
 Coming to the interface options, EM-18 uses Serial Communication whereas RC522 uses
SPI Communication (although the chip supports I2C and UART as well).

Interfacing RFID Reader with Raspberry Pi can be very useful as you can implement a
wide range of applications like:
 Access Control
 Authentication
 e-Ticket
 e-Payment
 e-Toll
 Attendance

55
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Pin Configuration:

RFID Reader Module USB to Serial Converter

Circuit Diagram:

56
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

Setting up Raspberry Pi for Serial Communication:

The Raspberry Pi RFID Reader Module Interface is the EM-18 RFID Reader Module uses UART
Communication i.e. Serial Communication.
But, we want to change this to act as a Serial Communication Port so that we can connect external
peripherals, like RFID Reader in this project, to communicate through serial communication.

1. Enter the Raspberry Pi Configuration Tool by entering the following command:


sudo raspi-config

2. In the “Interfacing Options”, select the “Serial” option.

57
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

CODE TO READ THE RFID CARD

source.py

import RPi.GPIO as gpio


import time
import serial

gpio.setmode(gpio.BOARD)

def read_rfid():
ser = serial.Serial("/dev/ttyUSB0")
ser.baudrate = 9600
data.ser.read(12)
ser.close()
return data

try:
while 1:
print("Place the card")
id = read_rfid()
print(id)

finally:
pass

58
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

CODE TO WRITE TO THE RFID CARD

valid.py

import RPi.GPIO as gpio


import time
import serial
gpio.setmode(gpio.BOARD)

def read_rfid():
ser = serial.Serial("/dev/ttyUSB0")
ser.baudrate = 9600
data = ser.read(12)
return data
try:
while 1:
print("Place the card")
id = read_rfid()
print(id)
c = b'1E005FD8950C'
d = b'0006311315096'
if id == c:
print("valid id")
else:
print("invalid id")

finally:
pass

59
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

RESULTS:

60
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS

CONCLUSION:

After running code, we got a message as “Place the Card”. When you place your RFID Card on
the RFID Reader, it will read the Biometric id number (B’ Id) from the card and sends the data
to the Raspberry Pi over Serial Communication.
This data is further analyzed by the Raspberry Pi and appropriate messages are displayed in the
screen. Hence Valid and Invalid users can be verified through RFID process.

61

You might also like