0% found this document useful (0 votes)
13 views51 pages

IOT Journal 6406

The document outlines a journal for a TYBSC-IT student, detailing various Internet of Things (IoT) projects and practical exercises involving Raspberry Pi. It includes topics such as GPIO operations, LED control, and home automation, along with installation steps for Raspbian OS. The journal serves as a record of completed tasks and experiments related to IoT applications using Raspberry Pi Model 3 B.

Uploaded by

kakashihata932
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)
13 views51 pages

IOT Journal 6406

The document outlines a journal for a TYBSC-IT student, detailing various Internet of Things (IoT) projects and practical exercises involving Raspberry Pi. It includes topics such as GPIO operations, LED control, and home automation, along with installation steps for Raspbian OS. The journal serves as a record of completed tasks and experiments related to IoT applications using Raspberry Pi Model 3 B.

Uploaded by

kakashihata932
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/ 51

Ramniranjan

jhunjhunwala college
ghatkopar (w),
mumbai - 400 086

Department of information

technology 2024 - 2025

Tybsc-it Semester - V

IOT JOurnal

6406_Yash_Mourya
Name : yash mourya
Roll No : 6406

IOT

Sr Title Date Remark


No

1 Introduction to RPi 26/6/24 DONE


● Introduction to Rpi – ABOUT
● Rpi model 3 B
● GPIO
● Raspbian OS
● Steps of installation of Raspbian OS
on SD Card

2 RPi I/O operations 4/7/24 DONE


● Blinking LED
● 4 LED Blink
● 2 ON 2 OFF Pattern
● Serial Blinking
● Push Button control
● Buzzer with PUSH Button
● 16 * 2 LCD Interface

3 4 digit 7 segment display to show time DONE

4 Using Telegram app for IOT


● telegram BOT
● controlling LED using BOT

5 Use RFID tag to control entry

6 Attendance management system using


Fingerprint scanner

7 Picamera Visitor monitoring system


8 Home Automation using Mobile App /
NodeRed

9 Configuration of Wireless Access Point


Practical - 1
(Introduction to Raspberry Pi)

About Raspberry Pi:


Raspberry Pi is a series of small single-board computers
developed by the Raspberry Pi Foundation to promote the
teaching of basic computer science in schools and in developing
countries. The original model became far more popular than
anticipated, selling outside its target market for uses such as
robotics. It does not include peripherals (such as keyboards and
mice) or cases. However, some accessories have been included in
several official and unofficial bundles.

Raspberry Pi Model 3 B:
The Raspberry Pi 3 Model B is a version of the Raspberry Pi
single-board computer. Here are some of its key features:
● Processor: Quad-core 64-bit ARM Cortex A53 clocked at
1.2GHz
● RAM: 1GB LPDDR2
● Wireless: 802.11n Wireless LAN
● Bluetooth: Bluetooth 4.1, Bluetooth Low Energy (BLE)
● Ethernet: 100 Base Ethernet
● USB Ports: 4 USB 2.0 ports
● Video Output: Full-size HDMI
● Audio Output: 3.5mm audio jack
● GPIO: 40-pin GPIO header
● Storage: microSD card slot
● Other: CSI camera port, DSI display port

GPIO (General Purpose Input/Output)


The GPIO pins on a Raspberry Pi are a physical interface between
the Pi and the outside world. At the simplest level, you can think
of them as switches
that you can turn on or off (input) or that the Raspberry Pi can
turn on or off (output). The Raspberry Pi 3 Model B has a 40-pin
GPIO header.

● Power pins: 3.3V and 5V


● Ground pins: GND
● Data pins: GPIO pins that can be configured as input or output

Raspbian OS
Raspbian is the officially supported operating system for
Raspberry Pi. It is a free operating system based on Debian
optimized for the Raspberry Pi hardware. Raspbian comes with
over 35,000 packages, pre-compiled software bundled in a nice
format for easy installation on your Raspberry Pi.

Steps of Installation of Raspbian OS on SD Card

1. Download Raspbian OS:


● Visit the Raspberry Pi website and download the latest
version of Raspbian OS. You can choose between different
versions such as Raspberry Pi OS with desktop, Raspberry
Pi OS Lite, etc.

2. Download Raspberry Pi Imager:


Download and install the Raspberry Pi Imager from the official
website.

3. Insert the microSD Card:


● Insert the microSD card into your computer using an SD
card adapter if necessary.

4. Launch Raspberry Pi Imager:


● Open the Raspberry Pi Imager and click on “Choose OS”.
5. Select Raspbian OS:
● Select “Raspberry Pi OS (32-bit)” from the list.
6. Select SD Card:
● Click on “Choose SD Card” and select your microSD card
from the list of available storage devices.

7. Write the Image:


● Click on “Write” to begin writing the Raspbian OS image
to the SD card. This process can take several minutes.

8. Eject the SD Card:


● Once the writing process is complete, safely eject the SD
card from your computer.

9. Insert the SD Card into Raspberry Pi:


● Insert the microSD card into the SD card slot on the
Raspberry Pi.

10. Power Up the Raspberry Pi:


● Connect your peripherals (keyboard, mouse, monitor) and
power supply to the Raspberry Pi. When you power it on, it
should boot up into the Raspbian OS setup screen.

11. Complete the Setup:


● Follow the on-screen instructions to complete the initial
setup of Raspbian OS, including setting up your Wi-Fi
connection, updating the system, and creating a user
account.

This process will set up your Raspberry Pi with the Raspbian


operating system, allowing you to start exploring and using your
Raspberry Pi for various projects.
Practical - 2
(RPi I/O operations)

1. Blinking LED

Problem Statement:
To control an LED using a Raspberry Pi by turning it on and off in
regular intervals through a Python script. This will demonstrate how
to use the GPIO pins for basic digital output operations.

Objective:
The objective of this practical is to understand and perform basic I/O
operations using the GPIO pins on the Raspberry Pi by creating a
simple circuit to blink an LED.

Components Used:
● Raspberry Pi 3 Model B
● LED (Light Emitting Diode)
● 220Ω resistor
● Jumper wires

Circuit dig

Algorithm
I. Initialize GPIO Library: Import the necessary libraries and configure the
GPIO settings.
II. Setup GPIO Pins:
III. Set up GPIO pin 8 as an output pin.
IV. Initialize the pin state to LOW (LED off).
V. Blinking Loop:
VI. Turn the LED on by setting GPIO pin 8 to HIGH.
VII. Wait for 1 second.
VIII. Turn the LED off by setting GPIO pin 8 to LOW.
IX. Wait for 1 second.
X. Repeat the above steps indefinitely.
XI. Handle Exit:
XII. On a keyboard interrupt (Ctrl+C), clean up GPIO settings to avoid
warnings and reset the pin states.

Libraries used
● RPi. GPIO
● time

Code:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, 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)

Output:
2. Blinking of 4 LEDs:

Problem Statement:
To control four LEDs connected to a Raspberry Pi by turning them on
and off in a sequence through a Python script. This will demonstrate
how to use multiple GPIO pins for digital output operations.

Objective:
The objective is to understand and perform I/O operations using the
GPIO pins on the Raspberry Pi by creating a circuit to blink four LEDs in
a sequential pattern.

Components Used:
● Raspberry Pi 3 Model B
● 4 LEDs (Light Emitting Diodes)
● 4 220Ω resistors
● Jumper wires

Circuit dig
Algorithm
I. Initialize GPIO Library: Import the necessary libraries and configure the
GPIO settings.
II. Setup GPIO Pins:
III. Set up GPIO pins 8, 10, 12, and 16 as output pins.
IV. Initialize the pin states to LOW (LEDs off).
V. Blinking Sequence:
VI. Turn LED 1 on, wait for 1 second, and turn it off.
VII. Turn LED 2 on, wait for 1 second, and turn it off.
VIII. Turn LED 3 on, wait for 1 second, and turn it off.
IX. Turn LED 4 on, wait for 1 second, and turn it off.
X. Repeat the above sequence indefinitely.
XI. Handle Exit:
XII. On a keyboard interrupt (Ctrl+C), clean up GPIO settings to avoid
warnings and reset the pin states.

Libraries used

● RPi. GPIO
● time
Code:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
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(8, GPIO.OUT, initial = GPIO.LOW)
while True:
GPIO.output(3, GPIO.HIGH)
GPIO.output(5, GPIO.HIGH)
GPIO.output(7, GPIO.HIGH)
GPIO.output(8, GPIO.HIGH)
print(“LED on”)
sleep(1)
GPIO.output(3, GPIO.LOW)
GPIO.output(5, GPIO.LOW)
GPIO.output(7, GPIO.LOW)
GPIO.output(8, GPIO.LOW)
print(“LED off”)
sleep(1)

Output:
3. Two ON Two OFF Pattern:

Problem Statement :-
Design and implement a system on a Raspberry Pi that controls a set
of four LEDs. The system should follow a "Two ON, Two OFF" pattern,
where two LEDs are turned on while the other two are off, and then
the states are alternated after a certain interval.

Objective :-
Understand GPIO Pin Control: Learn to control the General Purpose
Input /Output (GPIO) pins on a Raspberry Pi to manage external
devices like LEDs.
Implement Timing Mechanism: Use a timing mechanism to create the
desired pattern with specified intervals.
Create a Repeating Pattern: Ensure that the "Two ON, Two OFF"
pattern repeats continuously.

Components Used :-
● Raspberry Pi 3 Model B
● 4 LEDs (Light Emitting Diodes)
● Jumper Wires
Circuit dig

Algorithm
I. Initialize GPIO Library: Import the necessary libraries and configure
the GPIO settings.
II. Setup GPIO Pins:
III. Set up GPIO pins 8, 10, 12, and 16 as output pins.
IV. Initialize all pins to LOW (LEDs off).
V. 2 ON 2 OFF Pattern:
VI. Turn LED 1 and LED 2 on, and LED 3 and LED 4 off.
VII. Wait for 1 second.
VIII. Turn LED 1 and LED 2 off, and LED 3 and LED 4 on.
IX. Wait for 1 second.
X. Repeat the above pattern indefinitely.
XI. Handle Exit:
XII. On a keyboard interrupt (Ctrl+C), clean up GPIO settings to avoid
warnings and reset the pin states.

Libraries used
● RPi. GPIO
● time

Code :-
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
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(8, GPIO.OUT, initial = GPIO.LOW)

while True:
GPIO.output(3, GPIO.HIGH)
GPIO.output(5, GPIO.LOW)
GPIO.output(7, GPIO.HIGH)
GPIO.output(8, GPIO.LOW)
print(“LED on”)
sleep(1)
GPIO.output(3, GPIO.LOW)
GPIO.output(5, GPIO.HIGH)
GPIO.output(7, GPIO.LOW)
GPIO.output(8, GPIO.HIGH)
print(“LED off”)
sleep(1)
Output:
4. Serial Blinking
Problem Statement :-
Design and implement a system on a Raspberry Pi that controls a set
of LEDs to blink in a sequential (serial) manner. Each LED should turn
on and off one after the other in a repeating sequence.

Objective :-
Learn GPIO Pin Control: Understand how to control the GPIO pins on a
Raspberry Pi to manage multiple LEDs.
Implement Timing Mechanism: Use timing to create a sequential
blinking pattern.
Create a Repeating Pattern: Ensure that the LEDs blink in a serial
manner continuously.

Components Used :-

● Raspberry Pi 3 Model B
● 4 LEDs (Light Emitting Diodes)
● Jumper Wires
Circuit dig

Algorithm

I. Initialize GPIO Library: Import the necessary libraries and configure the
GPIO settings.
II. Setup GPIO Pins:
III. Set up GPIO pins 8, 10, 12, and 16 as output pins.
IV. Initialize all pins to LOW (LEDs off).
V. Serial Blinking Pattern:
VI. Turn LED 1 on, wait for 0.5 seconds, then turn LED 1 off.
VII. Turn LED 2 on, wait for 0.5 seconds, then turn LED 2 off.
VIII. Turn LED 3 on, wait for 0.5 seconds, then turn LED 3 off.
IX. Turn LED 4 on, wait for 0.5 seconds, then turn LED 4 off.
X. Repeat the above sequence indefinitely.
XI. Handle Exit:
XII. On a keyboard interrupt (Ctrl+C), clean up GPIO settings to avoid
warnings and reset the pin states.

Libraries used
● RPi. GPIO
● time

Code :-
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
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(8, GPIO.OUT, initial = GPIO.LOW)
while True:
GPIO.setup(8, GPIO.OUT, initial = GPIO.LOW)
GPIO.setup(3, GPIO.OUT, initial = GPIO.HIGH)
sleep(1)
GPIO.setup(3, GPIO.OUT, initial = GPIO.LOW)
GPIO.setup(5, GPIO.OUT, initial = GPIO.HIGH)
sleep(1)
GPIO.setup(5, GPIO.OUT, initial = GPIO.LOW)
GPIO.setup(7, GPIO.OUT, initial = GPIO.HIGH)
sleep(1)
GPIO.setup(7, GPIO.OUT, initial = GPIO.LOW)
GPIO.setup(8, GPIO.OUT, initial = GPIO.HIGH)
sleep(1)
Output:

Video Link: serial blinking


5. Push Button Control

Problem Statement :-
Design and implement a system on a Raspberry Pi that allows an LED
to be turned on or off using a push button. When the button is pressed,
the LED should turn on, and when the button is released, the LED
should turn off.

Objective :-
Learn GPIO Pin Control: Understand how to control GPIO pins on a
Raspberry Pi to manage an LED and read input from a push button.
Implement Button Debouncing: Ensure that the button press is
accurately detected, avoiding false triggers due to mechanical bounce.
Create an Interactive System: Develop a responsive system that reacts
to user input via the push button.
Components Used :-
● Raspberry Pi 3 Model B
● 4 LEDs (Light Emitting Diodes)
● Jumper Wires
● Push Button

Circuit dig
Code :-
import RPi.GPIO as GPIO
import time
led_pin = 4
button_pin = 11
# Setup GPIO mode and pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
while True:
GPIO.output(led_pin, GPIO.input(button_pin)) # LED on when
button pressed
time.sleep(0.1) # Short delay to avoid high CPU usage
Output:
6. Buzzer with PUSH Button
Problem Statement :-
Design and implement a system on a Raspberry Pi that allows a buzzer
to be activated using a push button. When the button is pressed, the
buzzer should sound, and when the button is released, the buzzer
should stop.

Objective :-
Understand GPIO Pin Control: Learn to control the General Purpose
Input /Output (GPIO) pins on a Raspberry Pi to manage a buzzer.
Implement Button Control: Read the state of a push button and use it
to control the buzzer.
Create an Interactive System: Develop a responsive system that
accurately detects button presses and controls the buzzer accordingly.

Components Used :-
● Raspberry Pi 3 Model B
● 4 LEDs (Light Emitting Diodes)
● Jumper Wires
● Buzzer
● Push Button

Code :-
import RPi.GPIO as GPIO
import time
# Define the GPIO pins for the buzzer and the button
buzzer_pin = 17
button_pin = 18
# Setup GPIO mode and pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(buzzer_pin, GPIO.OUT)
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
while True:
if GPIO.input(button_pin) == GPIO.HIGH:
GPIO.output(buzzer_pin, GPIO.HIGH) # Turn on Buzzer
else:
GPIO.output(buzzer_pin, GPIO.LOW) # Turn off Buzzer
time.sleep(0.1) # Short delay to avoid high CPU usage

Output:
Practical - 3
(4 digit 7 segment display to show time)

Problem Statement :-
Create a digital clock using a 4-digit 7-segment display to accurately
display hours and minutes.

Objective :-
Design a system that reads time from an RTC module and displays it
on the 7-segment display, updating every minute.

Components Used :-
● Raspberry Pi (e.g., Raspberry Pi 3 Model B)

● Jumper Wires

Code :-
from time import sleep
import tm1637
try:
import thread
except ImportError:
Import_thread as thread

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


try:
print(“Start clock in the background(Press ctrl+c to stop:)”)
Display.StartClock(military_time=True)
Display.SetBrightness(1.0)
while True:
Display.ShowDoublepoint(True)
sleep(1)
Display.ShowDoublepoint(False)
sleep(1)
Display.StopClock();
thread.interrupt_main()
except KeyboardInterrupt:
print(“Closed Succesfully”)
Display.cleanup()

Output:
Practical - 4
(Using Telegram app for IOT)

Telegram BOT:

Problem Statement:
Develop a Telegram bot that interacts with an IoT device, allowing
users to control and monitor the device remotely through the
Telegram app.

Objective:
The primary objective of this practical is to create a Telegram bot
that can communicate with an IoT device, allowing users to:
1. Send Commands: Control the IoT device (e.g., turning on/off
a light, adjusting temperature, etc.) by sending commands
through the Telegram bot.
2. Receive Status Updates: Receive real-time status updates
from the IoT device (e.g., temperature readings, device
status, etc.) via the Telegram bot.

Components:
● Raspberry Pi (e.g., Raspberry Pi 3 Model B)

● Jumper Wires

● Mobile Phone(for Telegram Bot API)

Algorithm:

I. Setup Telegram Bot:

Create a bot using the BotFather on Telegram and get the API token.

II. Install Required Libraries:


III. Ensure Python and telepot are installed on your Raspberry Pi:

pip install telepot

IV. Write Python Code:

Define the action function to handle incoming messages.

Implement the bot’s responses for various commands.

Set up the bot with the API token.

Use MessageLoop to listen for incoming messages and respond

accordingly.

V. Run the Bot:

Start the bot and keep it running to handle incoming messages.

Libraries and Tools

● Telepot: A Python library used to interact with the Telegram Bot API.

● Python's datetime and time modules: To handle time-based functions

and delays.

● IoT Device: The device you wish to control or monitor. (e.g., a smart

light, temperature sensor, etc.)

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! CircuitDigest”))

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_1464122100_280.jpg”)

elif command == ‘/file’:

telegram_bot.sendDocument(chat_id,document =

open(‘/home/pi/IOT/Practical 2.py’))

elif command == ‘/audio’:

telegram_bot.sendAudio(chat_id, audio=open(‘

/home/pi/test.mp3’))

telegram_bot = telepot.Bot(‘//your token number’)

print (telegram_bot.getMe())

MessageLoop(telegram_bot, action).run_as_thread()
print (“up and running..”)

while 1:

time.sleep(10)

Output:

Input on bot and getting message:


B. Controlling LED using BOT:
Problem Statement:

Create a system that allows users to remotely control an LED using a


Telegram bot. The system should enable users to turn the LED on or
off by sending commands through the Telegram app, providing a
simple and effective way to manage the LED remotely.

Objective:

Design and implement a Telegram bot that interacts with an IoT setup
to control an LED.
The bot should:
Receive Commands: Accept user commands (/on and /off) through
Telegram to control the LED.
Control LED: Turn the LED on or off based on the received commands.

Components and Library:


● Raspberry Pi: For controlling the LED and running the bot script.
● LED: Connected to GPIO pins on the Raspberry Pi.
● Jumper Wires: To connect the LED to the GPIO pins.
● Telegram Bot API: To send and receive messages from the Telegram
app.
● Python Libraries:
I. telepot: For interacting with the Telegram Bot API.
II. RPi.GPIO: For controlling GPIO pins on the Raspberry Pi.

Algorithm
1. Setup the Environment:
a. Initialize GPIO: Configure the GPIO pins on the Raspberry Pi.
b. Setup Telegram Bot: Create a bot using BotFather on Telegram
and get the API token.
2. Write Python Code:
a. Import Libraries: Import the necessary libraries for GPIO and
Telegram interactions.
b. Define GPIO Configuration: Setup GPIO pins and their modes.
c. Define Bot Commands: Implement the action function to handle
/on and /off commands and control the LED.
d. Initialize Bot: Start the bot and listen for incoming messages.
3. Run the Bot:
a. Start the Bot: Keep the script running to continuously listen for
commands.

Code:
import time, datetime
import telepot
from telepot.loop import MessageLoop
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(5, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(7, GPIO.OUT, initial=GPIO.LOW)

now = datetime.datetime.now()
def action(msg):
chat_id = msg[‘chat’][‘id’]
command = msg[‘text’]

print (‘Received %s’ %command)


if command == ‘/led1’:
GPIO.output(3,GPIO.HIGH);
GPIO.output(5,GPIO.LOW);
GPIO.output(7,GPIO.LOW);

print (‘Received %s’ %command)


elif command == ‘/led2’:
GPIO.output(3,GPIO.LOW);
GPIO.output(5,GPIO.HIGH);
GPIO.output(7,GPIO.LOW);

print (‘Received %s’ %command)


if command == ‘/led3’:
GPIO.output(3,GPIO.LOW);
GPIO.output(5,GPIO.LOW);
GPIO.output(7,GPIO.HIGH);

print (‘Received %s’ %command)


if command == ‘/off’:
GPIO.output(3,GPIO.LOW);
GPIO.output(5,GPIO.LOW);
GPIO.output(7,GPIO.LOW);

telegram_bot = telepot.Bot(‘//Your token number’)


print(telegram_bot.getMe())
MessageLoop(telegram_bot.action).run_as_thread()
print(“up and running….”)
while True:
time.sleep(10)
Output:
Practical - 5
(Use EM-18 tag to control entry)
Aim : To study input-output controls using the Raspberry Pi by
implementing a system to control an LED based on an EM-18tag's
presence.

Circuit dig

Libraries Used
1. RPi.GPIO: This library allows for interaction with the GPIO pins on the
Raspberry Pi.
2. time: This standard Python library is used for handling time-related
functions. You use it to manage delays and sleep intervals.
3. serial: This library, part of the PySerial package, allows for serial
communication with devices like RFID readers.
Components Used
● Raspberry Pi: A small, affordable computer used to interface with
various hardware components.
● EM-18Reader: A device that reads EM-18 tags. It's connected to the
Raspberry Pi via a USB-to-serial adapter.

● Serial Connection: The RFID reader is connected to the Raspberry Pi


through a serial communication link (typically USB-to-serial)

Algorithm
1. Initialization:
a. Import necessary libraries:
b. RPi.GPIO for GPIO (though not utilized in this snippet).
c. time for handling sleep intervals.
d. serial from PySerial for serial communication.
e. Configure GPIO to suppress warnings using
gpio.setwarnings(False).
f. Set the GPIO pin numbering mode to BOARD using
gpio.setmode(gpio.BOARD).
2. Define Function read_em18():
a. Open a serial connection to the EM-18 reader:
b. Use serial.Serial("/dev/ttyUSB0") to create a serial object.
c. Set the baud rate to 9600 with ser.baudrate = 9600.
d. Read data from the EM-18 reader:
e. The EM-18 typically sends data in a specific format (often 12
bytes or more).
f. Close the serial connection with ser.close().
g. Return the read data.
3. Main Execution Loop:
a. Continuously run an infinite loop using while True:
b. Print "Place the card" to prompt the user.
c. Wait for 1 second using sleep(1).
d. Call read_em18() to read data from the EM-18 reader.
e. Print the received EM-18 data.
4. Cleanup:
a. In the finally block, ensure GPIO resources are cleaned up with
gpio.cleanup().
Python Script:

import RPi.GPIO as gpio


import time
import serial
from time import sleep
gpio.setwarnings(False)
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")
sleep(1)
id=read_rfid()
print(id)
finally:
gpio.cleanup()
Output image
Push Button:
import RPi.GPIO as GPIO
import time
import serial
from time import sleep

# Setup GPIO pins


GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(29, GPIO.OUT, initial=GPIO.LOW) # Light (LED)
GPIO.setup(31, GPIO.OUT, initial=GPIO.LOW) # Buzzer (Active Buzzer)
GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Push Button

# Attendance dictionary (replace with actual RFID IDs and names)


attendance = {
b'1C0039660043': {'name': 'Student A', 'count': 0},
b'1C0039660044': {'name': 'Student B', 'count': 0},
# Add more students as needed
}

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

def show_attendance():
print("\n--- Attendance Report ---")
for student_id, info in attendance.items():
print(f"{info['name']}: {info['count']} times")
print("-------------------------\n")

try:
while True:
# Wait for button press
print("Waiting for button press...")
GPIO.wait_for_edge(37, GPIO.FALLING) # Wait until button is pressed
print("Button pressed! Place the card")

sleep(1) # Small delay after button press


id = read_rfid()
print(f"Scanned ID: {id}")

if id in attendance:
attendance[id]['count'] += 1 # Increment attendance count for the student
print(f"Card No: {id}")
print(f"Welcome {attendance[id]['name']}")
print(f"Attendance Count for {attendance[id]['name']}:
{attendance[id]['count']}")
GPIO.output(29, GPIO.HIGH) # Turn on light
for _ in range(5): # Beep the buzzer 5 times
GPIO.output(31, GPIO.HIGH) # Turn on buzzer
sleep(0.1) # Beep duration
GPIO.output(31, GPIO.LOW) # Turn off buzzer
sleep(0.1) # Silence duration between beeps
GPIO.output(29, GPIO.LOW) # Turn off light
else:
print("Wrong Card......")
GPIO.output(29, GPIO.LOW) # Ensure light is off
GPIO.output(31, GPIO.LOW) # Ensure buzzer is off

show_attendance() # Display attendance after each scan

finally:
GPIO.cleanup()
Practical - 6

Attendance management system using Fingerprint scanner

Code:
Import time
form pyfingerprint.pyfingerprint import Pyfingerprint
import RPi.GPIO as gpio

gpio.setwarning(False)
gpio.setmode(gpio.BCM)
gpio.setup(3, gpio.IN,pull_up_down=gpio.PUD_UP)
gpio.setup(17,gpio.IN,pull_up_down=gpio.PUD_UP)

try:
F = PyFingerprint(‘dev/ttyUSB0’,57600,0xFFFFFFFF,0x00000000)
except Exception as e:
print(“exception message”+str(e))
exit(1)

def enrollFinger():
print(“Waiting For Finger”)
while(f.readImage()==False):
pass
f.convertImage(0x01)
result= f.searchTemplate()
positionNumber = result[0]
If(positionNumber >=0):
print(“Finger Already register at position” + str(positionNumber))
time.sleep(2)
return
print(“remove finger…”)
time.sleep(2)
print(“waiting for finger again…”)
while(f.readImage() == False):
Pass
f.convertImage(0x02)
if(f.compareCharacteristics == 0):
print(“finger do not match”)
time.sleep(2)
f.createTemplate()
postionNumber = f.storeTemplate()
print(“Finger enroll successfully”)
print(“New template Postion #”+str(postitionNumber))
time.sleep(2)

def attendance():
print(‘place finger for Attendence”)
print(“waiting for finger”)
while(f.readImage()==False):
pass
f.convertImage(0x01)
result= f.searchTemplate()
positionNumber = result[0]
If(positionNumber >=0):
print(“Attendence already register” + str(positionNumber))
time.sleep(2)
return
print(“remove finger…”)
f.createTemplate()
postionNumber = f.storeTemplate()
print(“Attendence Marked succesfully …”)
while(1):
Button_state =gpio.input(3)
Button2_state = gpio.input(17)
if(button_state == False):
print(“Place finger to enroll’)
enrollFinger()
If button2_state == False:
attendance()
Practical - 8
Home Automation using Mobile App / NodeRed

Step 1:
1. tar xvzf WebIOPi-0.7.1.tar.gz
2. cd WebIOPi-0.7.1/

At this point before running step we need to install a patch as this version
of the WebIOPi does not work with the raspberry pi 3

Below command are used to install patch


Step 2:
1.wget
https://raw.githubusercontent.com/doublebind/raspi/master/webiopi-pi2bp
lus.patch
2. patch -pI -i webiopi-pi2bplus.patch
3.sudo chmod 775 setup.sh

Then we can run the setup installation for webiopi using :

1. sudo ./setup.sh
2.sudo webiopi -d -c /etc/webiopi/config

Then open up the browser write the http://172.16.5.214:8000


It will ask user name and password default is
Username: webiopi
Password: raspberry

You can also start and stop the service :


1. sudo /etc/init.d/webiopi start
2. sudo /etc/init.d/webipoi stop
Images of step :
Output :

You might also like