IoT Final Journal
IoT Final Journal
CERTIFICATE
Class: T.Y.BSc.(IT) Year: 2022 - 2023
This is to certify that the practical entitled Internet of Things in this journal is
the work of Miss. Tejaswinee Dinkar Kamble of T.Y.BSc.(IT) Roll No. 11 has
satisfactorily completed the required number of practicals and worked for
Semester 5 of the academic year 2022 – 2023 in the college laboratory as laid
down by the university.
__________
Date: College Seal
1
INDEX
2
Practical 1: Displaying Different LED patterns using Raspberry Pi
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(25,GPIO.OUT)
switch0 = 7
switch1 = 8
switchPressCount = 0
pins = [12,13,16,20,21,23,24,25]
def blink():
for j in range(0,8):
GPIO.output(pins[j],False)
time.sleep(0.5)
for j in range(0,8):
3
GPIO.output(pins[j],True)
time.sleep(0.5)
def toggle():
for j in range(0,8):
if j%2 == 0:
GPIO.output(pins[j],False)
else:
GPIO.output(pins[j],True)
time.sleep(0.5)
for j in range(0,8):
if j%2 == 1:
GPIO.output(pins[j],False)
else:
GPIO.output(pins[j],True)
time.sleep(0.5)
def incremental():
for j in range(0,8):
GPIO.output(pins[j],False)
for j in range(0,8):
GPIO.output(pins[j],True)
time.sleep(0.5)
print('LED Pattern')
while True:
try:
switchPressed = GPIO.input(switch0)
if switchPressed == False:
switchPressCount += 1
switchPressCount %= 3
if switchPressCount == 0:
blink();
4
if switchPressCount == 1:
toggle();
if switchPressCount == 2:
incremental();
except KeyboardInterrupt as e:
print('Cleaning GPIO')
GPIO.cleanup()
print('Cleaning GPIO')
GPIO.cleanup()
5
Practical 2: Displaying Time Over 4-Digit-7 Segment display using Raspberry Pi
now = datetime.datetime.now()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
segment8 = (26,19,13,6,5,11,9,10)
GPIO.setup(segment, GPIO.OUT)
GPIO.output(segment, 0)
#Digit 1
GPIO.setup(7, GPIO.OUT)
#Digit 2
GPIO.setup(8, GPIO.OUT)
#Digit 3
GPIO.setup(25, GPIO.OUT)
#Digit 4
GPIO.setup(24, GPIO.OUT)
null = [0,0,0,0,0,0,0]
zero = [1,1,1,1,1,1,0]
one = [0,1,1,0,0,0,0]
two = [1,1,0,1,1,0,1]
three = [1,1,1,1,0,0,1]
four = [0,1,1,0,0,1,1]
five = [1,0,1,1,0,1,1]
6
six = [1,0,1,1,1,1,1]
seven = [1,1,1,0,0,0,0]
eight = [1,1,1,1,1,1,1]
nine = [1,1,1,1,0,1,1]
def print_segment(charector):
if charector == 1:
for i in range(7):
GPIO.output(segment8[i], one[i])
if charector == 2:
for i in range(7):
GPIO.output(segment8[i], two[i])
if charector == 3:
for i in range(7):
GPIO.output(segment8[i], three[i])
if charector == 4:
for i in range(7):
GPIO.output(segment8[i], four[i])
if charector == 5:
for i in range(7):
GPIO.output(segment8[i], five[i])
if charector == 6:
for i in range(7):
GPIO.output(segment8[i], six[i])
if charector == 7:
for i in range(7):
GPIO.output(segment8[i], seven[i])
if charector == 8:
for i in range(7):
GPIO.output(segment8[i], eight[i])
if charector == 9:
for i in range(7):
GPIO.output(segment8[i], nine[i])
if charector == 0:
7
for i in range(7):
GPIO.output(segment8[i], zero[i])
return;
while 1:
now = datetime.datetime.now()
hour = now.minute
minute = now.second
h1 = hour/10
h2 = hour % 10
m1 = minute /10
m2 = minute % 10
print (h1,h2,m1,m2)
time.sleep(delay_time)
time.sleep(delay_time)
time.sleep(delay_time)
time.sleep(delay_time)
#time.sleep(1)
8
Practical 3: Raspberry Pi based Oscilloscope
import time
#import numpy
import Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1115()
GAIN = 1
val = [ ]
cnt = 0
plt.ion()
# Start continuous ADC conversions on channel 0 using the previous gain value.
adc.start_adc(0, gain=GAIN)
def makeFig():
plt.ylim(-5000,5000)
plt.title('Osciloscope')
plt.grid(True)
plt.ylabel('ADC outputs')
plt.legend(loc='lower right')
while (True):
value = adc.get_last_result()
print('Channel 0: {0}'.format(value))
9
time.sleep(0.5)
val.append(int(value))
drawnow(makeFig)
plt.pause(.000001)
cnt = cnt+1
if(cnt>50):
val.pop(0)
10
Practical 4: Fingerprint sensor interfacing with Raspberry Pi
import binascii
import time
class GT511C3:
self.serial = serial
paramBytes.reverse()
cmdBytes.reverse()
checksum = 256
data = []
i = 0;
data.append(0x55)
data.append(0xAA)
data.append(0x01)
data.append(0x00)
#print(data)
self.serial.write(data)
def getACK(self):
11
data = bytearray(12)
self.serial.readinto(data)
resp = ""
for c in data:
#sprint(resp)
return data
def open(self):
return self.isACK(self.getACK())
param = [0,0,0,0]
if turnOn:
param[3] = 1
return self.isACK(self.getACK())
def isPressFinger(self):
resp = self.getACK()
if self.isACK(resp):
respParam = resp[4]+resp[5]+resp[6]+resp[7]
return respParam == 0
return False
12
time.sleep(0.01)
param = [0,0,0,0]
if goodQuality:
param[3] = 1
return self.isACK(self.getACK())
if id == -1:
else:
resp = self.getACK()
if not self.isACK(resp):
return 0xFFFF
def enrollFirst(self):
return self.enroll(0x23)
def enrollSecond(self):
return self.enroll(0x24)
def enrollThird(self):
return self.enroll(0x25)
param = [0,0,0,0]
resp = self.getACK()
if not self.isACK(resp):
13
return 0xFFFF
def identify(self):
resp = self.getACK()
if self.isACK(resp):
respParam = resp[4]
return respParam
return -1
def deleteAll(self):
return self.isACK(self.getACK())
FingerPrintTest
import FingerPrintGT511C3
import serial
import time
if not serialPort.isOpen():
serialPort.open()
fps = FingerPrintGT511C3.GT511C3(serialPort)
def enroll():
fps.cmosLED(True)
fps.enrollStart(int(id))
fps.captureFinger(True)
fps.enrollFirst()
14
print('Remove Finger')
while fps.isPressFinger():
time.sleep(0.1)
fps.captureFinger(True)
fps.enrollSecond()
print('Remove Finger')
while fps.isPressFinger():
time.sleep(0.1)
fps.captureFinger(True)
fps.enrollThird()
print('Remove Finger')
while fps.isPressFinger():
time.sleep(0.1)
fps.cmosLED(False)
print(' ')
def openFPS():
print('Opening FPS')
if fps.open():
else:
raise Exception('')
def blinkLED():
if fps.cmosLED(True):
time.sleep(2)
fps.cmosLED(False)
else:
15
def search():
print('Searching...')
fps.cmosLED(True)
fps.captureFinger(True)
foundAt = fps.identify()
else:
print('Not Found')
fps.cmosLED(False)
print('')
def deleteAll():
fps.deleteAll()
time.sleep(00.0001)
openFPS()
#blinkLED()
while(True):
print('4. Exit')
option = input()
print(option)
if option == 1:
deleteAll()
16
if option == 2:
enroll()
if option == 3:
search()
if option == 4:
break
print('Exiting program...')
17
Practical 5: Raspberry Pi GPS module Interface
import time
import serial
import string
import pynmea2
LCD_RS = 7
LCD_E = 8
LCD_D4 = 21
LCD_D5 = 23
LCD_D6 = 24
LCD_D7 = 25
LCD_WIDTH = 16
LCD_CHR = True
LCD_CMD = False
LCD_LINE_1 = 0X80
LCD_LINE_2 = 0XC0
E_PULSE = 0.0005
E_DELAY = 0.0005
GPIO.setmode(GPIO.BCM)
GPIO.setup(LCD_E, GPIO.OUT)
GPIO.setup(LCD_RS, GPIO.OUT)
GPIO.setup(LCD_D4, GPIO.OUT)
GPIO.setup(LCD_D5, GPIO.OUT)
GPIO.setup(LCD_D6, GPIO.OUT)
GPIO.setup(LCD_D7, GPIO.OUT)
18
def lcd_init():
lcd_byte(0X33,LCD_CMD)
lcd_byte(0X32,LCD_CMD)
lcd_byte(0X28,LCD_CMD)
lcd_byte(0X0C,LCD_CMD)
lcd_byte(0X06,LCD_CMD)
lcd_byte(0X01,LCD_CMD)
def lcd_string(msg):
for i in range(LCD_WIDTH):
lcd_byte(ord(msg[i]),LCD_CHR)
def lcd_byte(bits,mode):
GPIO.output(LCD_RS, mode)
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)
time.sleep(E_DELAY)
GPIO.output(LCD_E, True)
time.sleep(E_PULSE)
GPIO.output(LCD_E, False)
19
time.sleep(E_DELAY)
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)
time.sleep(E_DELAY)
GPIO.output(LCD_E, True)
time.sleep(E_PULSE)
GPIO.output(LCD_E, False)
time.sleep(E_DELAY)
lcd_init()
lcd_byte(LCD_LINE_1, LCD_CMD)
while 1:
try:
data = ser.readline()
20
#wait for the serial port to churn out data
if data[0:6] == '$GPGGA': # the long and lat data are always contained in the GPGGA string of the NMEA
data
msg = pynmea2.parse(data)
latval = msg.lat
print(concatlat)
lcd_byte(LCD_LINE_1, LCD_CMD)
lcd_string(concatlat)
longval = msg.lon
print(concatlong)
lcd_byte(LCD_LINE_2, LCD_CMD)
lcd_string(concatlong)
finally:
GPIO.cleanup()
LCD
import time
LCD_RS = 7
LCD_E = 8
LCD_D4 = 21
LCD_D5 = 23
LCD_D6 = 24
LCD_D7 = 25
21
LCD_WIDTH = 16
LCD_CHR = True
LCD_CMD = False
LCD_LINE_1 = 0X80
LCD_LINE_2 = 0XC0
E_PULSE = 0.0005
E_DELAY = 0.0005
def main():
GPIO.setmode(GPIO.BCM)
GPIO.setup(LCD_E, GPIO.OUT)
GPIO.setup(LCD_RS, GPIO.OUT)
GPIO.setup(LCD_D4, GPIO.OUT)
GPIO.setup(LCD_D5, GPIO.OUT)
GPIO.setup(LCD_D6, GPIO.OUT)
GPIO.setup(LCD_D7, GPIO.OUT)
lcd_init()
lcd_byte(LCD_LINE_1, LCD_CMD)
lcd_string("Future Chip")
lcd_byte(LCD_LINE_2, LCD_CMD)
lcd_string("Technologies")
time.sleep(3)
def lcd_init():
lcd_byte(0X33,LCD_CMD)
lcd_byte(0X32,LCD_CMD)
lcd_byte(0X28,LCD_CMD)
lcd_byte(0X0C,LCD_CMD)
lcd_byte(0X06,LCD_CMD)
22
lcd_byte(0X01,LCD_CMD)
def lcd_string(msg):
for i in range(LCD_WIDTH):
lcd_byte(ord(msg[i]),LCD_CHR)
def lcd_byte(bits,mode):
GPIO.output(LCD_RS, mode)
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)
time.sleep(E_DELAY)
GPIO.output(LCD_E, True)
time.sleep(E_PULSE)
GPIO.output(LCD_E, False)
time.sleep(E_DELAY)
GPIO.output(LCD_D4, False)
GPIO.output(LCD_D5, False)
GPIO.output(LCD_D6, False)
GPIO.output(LCD_D7, False)
23
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)
time.sleep(E_DELAY)
GPIO.output(LCD_E, True)
time.sleep(E_PULSE)
GPIO.output(LCD_E, False)
time.sleep(E_DELAY)
if __name__=='__main__':
try:
main()
finally:
print("Cleanning GPIO")
GPIO.cleanup()
24
Practical 6: visitor Monitoring with Raspberry Pi & Pi Camera
import time
import picamera
import datetime
buzzer = 6
switch0 = 7
readyLED = 8
MOTOR_P = 12
MOTOR_M = 13
GPIO.setmode(GPIO.BCM)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.setup(readyLED,GPIO.OUT)
GPIO.setup(MOTOR_P,GPIO.OUT)
GPIO.setup(MOTOR_M,GPIO.OUT)
GPIO.output(MOTOR_P, False)
GPIO.output(MOTOR_M, False)
GPIO.output(buzzer, False)
GPIO.output(readyLED, True)
camera = picamera.PiCamera()
while True:
try:
25
switchPressed = GPIO.input(switch0)
if switchPressed == False:
GPIO.output(readyLED, False)
GPIO.output(buzzer, True)
time.sleep(0.001)
GPIO.output(buzzer, False)
camera.start_preview()
time.sleep(2)
camera.stop_preview()
timestamp = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
camera.capture(imagename)
print('Opening Door...')
GPIO.output(MOTOR_P, True)
GPIO.output(MOTOR_M, False)
time.sleep(0.8)
GPIO.output(MOTOR_P, False)
GPIO.output(MOTOR_M, False)
time.sleep(1.5)
GPIO.output(MOTOR_P, False)
GPIO.output(MOTOR_M, True)
print('Closing Door...')
time.sleep(0.81)
GPIO.output(MOTOR_P, False)
GPIO.output(MOTOR_M, False)
GPIO.output(readyLED, True)
except Exception as e:
print('Cleaning GPIO')
GPIO.cleanup()
GPIO.cleanup()
26
Practical 7: Interfacing Raspberry Pi with RFID
#!/usr/bin/env python
# it under the terms of the GNU Lesser General Public License as published by
# You should have received a copy of the GNU Lesser General Public License
'''
|:------:|:-------:|:------------:|
| SDA | 24 | GPIO8 |
27
| SCK | 23 | GPIO11 |
| MOSI | 19 | GPIO10 |
| MISO | 21 | GPIO9 |
| RST | 22 | GPIO25 |
| 3.3V | 1 | 3V3 |
'''
import MFRC522
import signal
import time
continue_reading = True
buzzer = 33 #13
errorLED = 35 #19
readyLED = 37 #26
GPIO.setmode(GPIO.BOARD)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.setup(readyLED,GPIO.OUT)
GPIO.setup(errorLED,GPIO.OUT)
GPIO.output(buzzer, False)
GPIO.output(errorLED, False)
GPIO.output(readyLED, False)
def end_read(signal,frame):
28
global continue_reading
continue_reading = False
GPIO.cleanup()
signal.signal(signal.SIGINT, end_read)
MIFAREReader = MFRC522.MFRC522()
# Welcome message
orignalID = ""
def getHexChar(d):
if d > 9:
if d == 10:
return "A"
if d == 11:
return "B"
if d == 12:
return "C"
if d == 13:
return "D"
if d == 14:
return "E"
if d == 15:
return "F"
else:
return str(d)
29
def getHex(no):
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# If a card is found
if status == MIFAREReader.MI_OK:
print("Card detected")
(status,uid) = MIFAREReader.MFRC522_Anticoll()
if status == MIFAREReader.MI_OK:
GPIO.output(buzzer, True)
# Print UID
rfid = getHex(uid[0]) + " " + getHex(uid[1]) + " " + getHex(uid[2]) + " " + getHex(uid[3])
if len(orignalID) < 2:
orignalID = rfid
if rfid == orignalID:
print('Approved')
GPIO.output(readyLED, True)
else:
30
print('Rejected')
GPIO.output(errorLED, True)
time.sleep(1)
GPIO.output(readyLED, False)
GPIO.output(errorLED, False)
GPIO.output(buzzer, False)
'''
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
MIFAREReader.MFRC522_SelectTag(uid)
# Authenticate
# Check if authenticated
if status == MIFAREReader.MI_OK:
MIFAREReader.MFRC522_Read(8)
MIFAREReader.MFRC522_StopCrypto1()
else:
print("Authentication error")
31