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

Iot pdf code output

Uploaded by

r48167763
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Iot pdf code output

Uploaded by

r48167763
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

P2 different led pattern

import RPi.GPIO as GPIO


import time
GPIO.setmode(GPIO.BOARD)
led1 = 29
led2 = 31
led3 = 33
led4 = 35
led5 = 36
led6 = 37
led7 = 38
led8 = 40
#setup the ledPin(i.e. GPIO22) as output
GPIO.setup(led1, GPIO.OUT)
GPIO.setup(led2, GPIO.OUT)
GPIO.setup(led3, GPIO.OUT)
GPIO.setup(led4, GPIO.OUT)
GPIO.setup(led5, GPIO.OUT)
GPIO.setup(led6, GPIO.OUT)
GPIO.setup(led7, GPIO.OUT)
GPIO.setup(led8, GPIO.OUT)
GPIO.output(led1, False)
GPIO.output(led2, False)
GPIO.output(led3, False)
GPIO.output(led4, False)
GPIO.output(led5, False)
GPIO.output(led6, False)
GPIO.output(led7, False)
GPIO.output(led8, False)
def ledpattern(ledVal1, ledVal2, ledVal3, ledVal4, ledVal5, ledVal6, ledVal7,ledVal8):
GPIO.output(led1, ledVal1)
GPIO.output(led2, ledVal2)
GPIO.output(led3, ledVal3)
GPIO.output(led4, ledVal4)
GPIO.output(led5, ledVal5)
GPIO.output(led6, ledVal6)
GPIO.output(led7, ledVal7)
GPIO.output(led8, ledVal8)
def patterOne():
for i in range (0, 3):
ledpattern(1, 0, 1, 0, 1, 0, 1, 0)
time.sleep(1)
ledpattern(0, 1, 0, 1, 0, 1, 0, 1)
time.sleep(1)
def patternTwo():
for i in range (0, 5):
ledpattern(1, 0, 0, 0, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 1, 0, 0, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 1, 0, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 1, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 1, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 0, 1, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 0, 0, 1, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 0, 0, 0, 1)
time.sleep(0.1)
def patternThree():
for i in range (0, 5):
ledpattern(0, 0, 0, 0, 0, 0, 0, 1)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 0, 0, 1, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 0, 1, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 0, 1, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 0, 1, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 0, 1, 0, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(0, 1, 0, 0, 0, 0, 0, 0)
time.sleep(0.1)
ledpattern(1, 0, 0, 0, 0, 0, 0, 0)
time.sleep(0.1)
def patternFour():
for i in range (0, 5):
ledpattern(0, 1, 1, 1, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 0, 1, 1, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 0, 1, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 0, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 0, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 1, 0, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 1, 1, 0, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 1, 1, 1, 0)
time.sleep(0.1)
def patternFive():
for i in range (0, 5):
ledpattern(1, 1, 1, 1, 1, 1, 1, 0)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 1, 1, 0, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 1, 0, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 1, 0, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 1, 0, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 1, 0, 1, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(1, 0, 1, 1, 1, 1, 1, 1)
time.sleep(0.1)
ledpattern(0, 1, 1, 1, 1, 1, 1, 1)
time.sleep(0.1)
try:
while True:
patterOne()
patternTwo()
patternThree()
patternFour()
patternFive()
finally:
#reset the GPIO Pins
GPIO.cleanup()

P3 blinking led
#Blink LED Program
#Connect the LED to GPIO 22 Pin
#LED Blink Progarm
#Connect the LED to GPIO22 (i.e. Physical Pin15)
#import GPIO and time library
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM) ledPin = 22 #setup the ledPin(i.e. GPIO22) as output
GPIO.setup(ledPin, GPIO.OUT)
GPIO.output(ledPin, False)
#set the Pin mode you will be working with
#this is GPIO22 pin i.e Physical Pin15
try:
while True:
GPIO.output(ledPin, True) #Set the LED Pin to HIGH
print("LED ON")
sleep(1) #Wait for 1 sec
GPIO.output(ledPin, False) #Set the LED Pin to LOW
print("LED OFF")
sleep(1) #wait for 1 sec
finally:
#reset the GPIO Pins
GPIO.output(ledPin, False)
GPIO.cleanup()

P4 display time 4 digit

#Program to display Time on 4-digit Seven segment display


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=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 ("Properly closing the clock and open GPIO pins")
Display.cleanup()

P5 finger print sensors

import time
from pyfingerprint.pyfingerprint import PyFingerprint
import RPi.GPIO as gpio
enrol=5
delet=6
led=26
HIGH=1
LOW=0
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(enrol, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(delet, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(led, gpio.OUT)
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('Exception message: ' + str(e))
exit(1)
print('Currently used finger templates: ' + str(f.getTemplateCount()) +'/'+
str(f.getStorageCapacity()))
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 exists at position #' + str(positionNumber))
time.sleep(2)
return
print('Remove finger...')
time.sleep(2)
print('Waiting for same finger again...')
while ( f.readImage() == False ):
pass
f.convertImage(0x02)
if ( f.compareCharacteristics() == 0 ):
print ("Fingers do not match")
time.sleep(2)
return
f.createTemplate()
positionNumber = f.storeTemplate()
print('Finger enrolled successfully!')
print('New template position #' + str(positionNumber))
time.sleep(2)
def searchFinger():
try:
print('Waiting for finger...')
while( f.readImage() == False ):
#pass
time.sleep(.5)
return
f.convertImage(0x01)
result = f.searchTemplate()
positionNumber = result[0]
accuracyScore = result[1]
if positionNumber == -1 :
print('No match found!')
time.sleep(2)
return
else:
print('Found finger at position #' + str(positionNumber))
time.sleep(2)
except Exception as e:
print('Operation failed!')
print('Exception message: ' + str(e))
exit(1)
def deleteFinger():
positionNumber = 0
count=0
while gpio.input(delet) == True: # here delet key means ok
positionNumber = input('Please enter the template position you want to delete: ')
positionNumber = int(positionNumber)
if f.deleteTemplate(positionNumber) == True :
print('Template deleted!')
time.sleep(1)
print('Currently used finger templates: ' + str(f.getTemplateCount()) +'/'+
str(f.getStorageCapacity()))
time.sleep(1)
return
print ("Edkits Electronics Welcomes You ")
time.sleep(3)
flag=0
while 1:
gpio.output(led, HIGH)
if gpio.input(enrol) == 0:
gpio.output(led, LOW)
enrollFinger()
elif gpio.input(delet) == 0:
gpio.output(led, LOW)
while gpio.input(delet) == 0:
time.sleep(0.1)
deleteFinger()
else:
searchFinger()

P6 GPS interfacing
import serial #import serial pacakge
from time import sleep
import webbrowser #import package for opening link in browser
import sys #import system package
def GPS_Info():
global NMEA_buff
global lat_in_degrees
global long_in_degrees
nmea_time = []
nmea_latitude = []
nmea_longitude = []
nmea_time = NMEA_buff[0] nmea_latitude = NMEA_buff[1] nmea_longitude = NMEA_buff[3]
#extract time from GPGGA string
#extract latitude from GPGGA string
#extract longitude from GPGGA string
print("NMEA Time: ", nmea_time,'\n')
print ("NMEA Latitude:", nmea_latitude,"NMEA Longitude:", nmea_longitude,'\n')
lat = float(nmea_latitude) #convert string into float for calculation
longi = float(nmea_longitude) #convertr string into float for calculation
lat_in_degrees = convert_to_degrees(lat) #get latitude in degree decimal format
long_in_degrees = convert_to_degrees(longi) #get longitude in degree decimal format
#convert raw NMEA string into degree decimal form at
def convert_to_degrees(raw_value):
decimal_value = raw_value/100.00
degrees = int(decimal_value)
mm
_
mmmm = (decimal
_
value - int(decimal_value))/0.6
position = degrees + mm_mmmm
position = "%.4f" %(position)
return position
gpgga_info = "$GPGGA,"
ser = serial.Serial ("/dev/ttyUSB0") GPGGA_buffer = 0
NMEA_buff = 0
lat_in_degrees = 0
long_in_degrees = 0
#Open port with baud rate
try:
while True:
received_data = (str)(ser.readline ()) GPGGA_data_available =
received_data.find(gpgga_info) #read NMEA string received
#check for NMEA GPGGA string
if (GPGGA_data_available>0):
GPGGA_buffer = received_data.split("$GPGGA,",1)[1] #store data coming after "$GPGGA,"
NMEA_buff = (GPGGA_buffer.split(',')) #store comma separated data in buffer
GPS_Info() #get time, latitude, longitude
print("lat in degrees:", lat_in_degrees," long in degree: ", long_in_degrees, '\n')
map_link = 'http://maps.google.com/?q=' + lat_in_degrees + ',' + long_in_degrees
#create link to plot location on Google map
print("<<<<<<<<press ctrl+c to plot location on google maps>>>>>>\n")
#press ctrl+c to plot on map and exit
print("
------------------------------------------------------------\n")
except KeyboardInterrupt:
webbrowser.open(ma p_link) sys.exit(0)
#open current position information in google map
#end of file

You might also like