New Iot Practical
New Iot Practical
PRACTICAL NO – 01
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.
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:
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
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
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.
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
5
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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
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
Circuit Diagram:
Pin Configuration:
Python code:
1-LED.py
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
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.
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
2 ON 2 OFF LED.py
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
LED Serially.py
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
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:
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:
17
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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.
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:
Circuit Diagram:
19
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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.
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
20
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
Python code:
clock.py
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
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:
23
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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
The telepot library enables the Raspberry Pi to communicate with the Telegram bot using the
API.
25
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
26
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
Pin Configuration:
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']
if command == 'on':
bot.sendMessage(chat_id, on(17))
elif command =='off':
bot.sendMessage(chat_id, off(17))
while 1:
time.sleep(10)
Use Bot Token: 6628306168:AAE-T2NvNJV99JvRvFhgEeqgLeXZPXyRdOc
27
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
Conclusion:
28
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
PRACTICAL NO – 05
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 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
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
Step 1: To install this library, root privileges are required. So first we enter in root by given
command:
sudo bash
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:
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*
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
#example_downloadimage
import tempfile
from pyfingerprint.pyfingerprint import PyFingerprint
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)
try:
print('Waiting for finger...')
35
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
pass
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
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.
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
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.
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
$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
Longitude Longitude(Coordinate)
M Meter
Height Height
41
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
Circuit Diagram:
42
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
dtparam=spi=on
dtoverlay=pi3-disable-bt
core_freq=250
enable_uart=1
force_turbo=1
43
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
a. If in your output, Serial0 is linked with ttyAMA0, then to disable it use the below command,
b. If in your output Serial0 is linked with ttys0, then to disable it use the below command,
44
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
Use minicom python library to connect with the GPS module and make sense of the data.
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
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
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
48
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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.
Circuit Diagram:
49
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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
51
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
#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.capture(“/home/pi/image.jpeg”)
E.g. Camera.start_preview()
E.g. Camera.stop_preview()
52
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
import picamera
from time import sleep
camera = picamera.PiCamera()
camera.resolution = (640, 480)
print()
#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:
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:
Circuit Diagram:
56
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
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.
57
T.Y.B.Sc. (I.T.) SEM-V INTERNET OF THINGS
source.py
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
valid.py
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