0% found this document useful (0 votes)
38 views36 pages

IoT Lab Manual for MCA Students 2024-25

The document is a lab manual for the IoT Lab with Mini Project course at Atria Institute of Technology, detailing the curriculum, objectives, and experiments for the Master of Computer Applications program. It outlines the vision, mission, program educational objectives, and specific outcomes expected from graduates, along with a list of experiments that include Python programming and Raspberry Pi applications. Each experiment includes aims, required components, algorithms, coding examples, and expected results to guide students in their practical learning.

Uploaded by

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

IoT Lab Manual for MCA Students 2024-25

The document is a lab manual for the IoT Lab with Mini Project course at Atria Institute of Technology, detailing the curriculum, objectives, and experiments for the Master of Computer Applications program. It outlines the vision, mission, program educational objectives, and specific outcomes expected from graduates, along with a list of experiments that include Python programming and Raspberry Pi applications. Each experiment includes aims, required components, algorithms, coding examples, and expected results to guide students in their practical learning.

Uploaded by

UZMA TAJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ATRIA INSTITUTE OF TECHNOLOGY

(An Autonomous Institution)


Department of Master of Computer Applications

LAB MANUAL

SCHEME: 2022

COURSE: IOT LAB WITH MINI


PROJECT

LAB CODE: 22MCAL37


SEMESTER: III

PREPARED BY:
Prof. UZMA TAJ
ACADEMIC YEAR – 2024-25
AIT-MCA-Vision
To be a leading knowledge center for imparting quality education in computer
applications, inter-disciplinary research and develop competent professionals to
serve the society.

AIT-MCA Mission
Department of Master of Computer Applications (MCA) committed to –
M1: Empower graduates with knowledge, skills and attitude to develop highly
competent professionals.
M2: Interdisciplinary projects, internships and value added training programs in
cutting edge technologies.
M3: Collaborate with academia and industry for research, consultancy and
encouraging entrepreneurship.
M4: Develop competent professionals with social and ethical values to serve the
society.

AIT-MCA-PEOs
Professionals from the Master of Computer Applications (MCA) should:
PEO1: Develop the ability to plan, analyse, design, implement and maintain the
software products for real life applications.
PEO2: Practice effectively as individuals and as team members in multidisciplinary
projects by inculcating professional skills, ethical behaviour, and leadership qualities.
PEO3: Develop lifelong learning capabilities to set up their own enterprise in various
sectors of computer applications and be able to pursue higher studies.
AIT-MCA-PSOs
Upon graduation students will be able to -
PSO1: efficiently design and develop computer-based systems in the areas related to
algorithms, web design, big data analytics, database management, IOT and
networking.
PSO2: apply standard practices and strategies in software project development
using open-ended programming environments to provide quality solutions.
PSO3: inculcate modern technologies and platforms in building innovative career
paths as an entrepreneur and pursuing higher studies.

AIT-MCA-POs
Foundation Knowledge: Apply knowledge of mathematics,
programming logic and coding fundamentals for solution architecture
and problem solving.
PO1.

Problem Analysis: Identify, review, formulate and analyse problems for


primarily focussing on customer requirements using critical thinking
PO2.
frameworks.

Development of Solutions: Design, develop and investigate problems


with as an innovative approach for solutions incorporating ESG/SDG
PO3. goals.

PO4. Modern Tool Usage: Select, adapt and apply modern computational tools
such as development of algorithms with an understanding of the
limitations including human biases.

PO5. Individual and Teamwork: Function and communicate effectively as an


individual or a team leader in diverse and multidisciplinary groups. Use
methodologies such as agile.
Project Management and Finance: Use the principles of project
PO6. management such as scheduling, work breakdown structure and be
conversant with the principles of Finance for profitable project
management.

Ethics: Commit to professional ethics in managing software projects


PO7. with financial aspects. Learn to use new technologies for cyber security
and insulate customers from malware.

Life-long learning: Change management skills and the ability to learn,


keep up with contemporary technologies and ways of working.
PO8.
LIST OF EXPERIMENTS

SL. No PROGRAMS Page No

Run Python programs on Pi like:


 Read your name and print Hello message with name.
 Read two numbers and print their sum, difference,
product and division.
 Word and character count of a given string
 Area of a given shape (rectangle, triangle and circle)
1 reading shape and appropriate values from standard input 2 - 11
 Print a name ‘n’ time, where name and n are read
from standard input, using for and while loops.
 Handle Divided by Zero Exception.
 Print current time for 10 times with an interval of
10 seconds.
 Read a file line by line and print the word count of each line.

2 Get input from two switches and switch on corresponding LEDs. 12

3 Flash an LED at a given on time and off time cycle, where the two 14
times are taken from a file.

4 Switch on a relay at a given time where the relay’s contact terminals 16


are connected to a load.

5 Access an image through a Pi web cam. 18

6 Control a light source using web page. 19

7 Implement an intruder system that sends an alert to the given email. 21

8 Get the status of a bulb at a remote place (on the LAN) through web. 24

9 Get an alarm from a remote area (through LAN) if smoke is


detected. The student should have hands on experience in using
27
various sensors like temperature, humidity, smoke, light, etc. and
should be able to use control web camera, network, and relays
connected to the Pi.
PROGRAM 1. RUN PYTHON PROGRAMS ON PI

AIM:

To write a program to Read your name and print Hello message with name

COMPONENTS REQUIRED:

Nil

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

CODING:
[Link]:
name = input("Please Enter Your Name Here:\n")
print("Hello " + name)

OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

2
AIM:

To write a program to Read two numbers and print their sum, difference,
product and division.

COMPONENTS REQUIRED:

Nil

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

CODING:
[Link]:
print("Enter First
Number") num1 = input()
print("Enter Second
Number") num2 = input()
print("************************************")
print("Sum of Given numbers is : "+str(int(num1)+int(num2)))
print("Difference of Given numbers is : "+str(int(num1)-int(num2)))
print("Product of Given numbers is : "+str(int(num1)*int(num2)))
print("Division of Given numbers is : "+str(int(num1)/int(num2)))
print("************************************")

3
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

AIM:

To write a program to Word and character count of a given string

COMPONENTS REQUIRED:

Nil

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

4
CODING:
[Link]:
print("Enter a sentence ")
sentence = input()
words =
[Link]()
word_count = 0
character_count =
0 for word in
words:
word_count += 1
character_count +=
len(word)
print("Total Numbers of Words in the sentence are : ",word_count)
print("Total Numbers of characters in the sentence excluding spaces are :
",character_count)
print("Total Numbers of characters in the sentence including spaces are :
",character_count+word_count-1)

OUTPUT:

5
RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

6
AIM:

To write a program to Area of a given shape (rectangle, triangle and circle)


reading shape and appropriate values from standard input

COMPONENTS REQUIRED:

Nil

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

CODING:
[Link]:
while True:
print("*****************************************")
print("Select the Shape that you want to calculate Area")
print(""" 1. Rectangle 2. Triangle 3. Circle 4. Exit """)
choice = input()
if(choice == '1'):
print("Enter the Width of the Rectangle in meters")
width = int(input())
print("Enter the height of the Rectangle in meters")
height = int(input())
print("The area of a Given Rectangle is ", width*height , " square meters ")
continue
elif(choice == '2'):
print("Enter the Base value of the Triangle in meters")
base = int(input())
7
print("Enter the height of the Triangle in meters")
height = int(input())
print("The area of a Given Rectangle is ", 0.5*base*height , " square meters ")
continue
elif(choice == '3'):
print("Enter the Radius of the Circle in meters")
radius = int(input())
print("The area of a Given Circle is ", 3.14*radius*radius , " square meters ")
continue
elif(choice == '4'):
break
else:
print("Please enter a valid number from the menu")
continue
print("Thank You")

OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

8
AIM:

To write a program to Print a name ‘n’ time, where name and n are read from
standard input, using for and while loops.

COMPONENTS REQUIRED:
Nil
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny
Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

CODING:
[Link]:
print("Enter Your name : ")
name = input()
print("Enter How many times you want to print your name")
n = int(input())
for i in range(n):
print(name)
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired

9
results.

1
0
AIM:

To write a program to Handle Divided by Zero Exception.

COMPONENTS REQUIRED:
Nil
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.
CODING:
[Link]:
print("Enter Numerator Value : ")
num1 = int(input())
print("Enter Denominator value : ")
num2 = int(input())
try:
result = num1/num2
print("The Division of Given Numbers is : ", result)
except ZeroDivisionError:
print("Divide By zero Error. The Denominator should not be Zero")
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.
11
AIM:

To write a program to Print current time for 10 times with an interval of 10


seconds.

COMPONENTS REQUIRED:

Nil

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

CODING:
[Link]:
import time
for i in range(10):
seconds = [Link]() #it will give to you as a float values
local_time = [Link](seconds) #it will gives to you as a current local time
print("Local time:", local_time)
[Link](10)

OUTPUT:

Result:
Thus the expected program was executed successfully and obtained the desired
results.

12
AIM:

To write a program to Read a file line by line and print the word count of each
line.
COMPONENTS REQUIRED:

Nil
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for the respective program.
STEP 4: Compile the code.
STEP 5: Save the program and run the program.
STEP 6: Expected output obtained.
STEP 7: Stop the process.

CODING:
[Link]:
import time
for i in range(10):
seconds = [Link]() #it will give to you as a float values
local_time = [Link](seconds) #it will gives to you as a current local time
print("Local time:", local_time)
[Link](10)

OUTPUT:

Result:
Thus the expected program was executed successfully and obtained the desired
results.
13
PROGRAM 2. GET INPUT FROM TWO SWITCHES AND SWITCH ON
CORRESPONDING LEDS

AIM:
To write a program to get input from two switches and switch on corresponding leds.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] Bread Board
[3] Two Led
[4] Two Switch
[5] Two Resistor
[6] Jumper Wires

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the code for two switch and two led.
STEP 4: Connect raspberry pi GPIO pins to breadboard with LED & Switch
STEP 5: Save the program and run the program.
STEP 6: Stop the process.
CODING:
import [Link] as GPIO
import time
[Link](False)
[Link]([Link])
chan_list=[14,20]
chan_list2=[15,21]
[Link](chan_list,[Link])
[Link](chan_list2,[Link],pull_up_down=GPIO.PUD_UP)
while True:
if([Link](15)==False):
[Link](14,True)
print("LED ON")
[Link](1)

14
else:
[Link](14,False)
print("LED OFF")
[Link](1)
if([Link](21)==False):
[Link](20,True)
print("LED ON")
[Link](1)
else:
[Link](20,False)
print("LED OFF")
[Link](1)

OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

15
PROGRAM 3. FLASH AN LED AT A GIVEN ON TIME AND OFF TIME
CYCLE, WHERE THE TWO TIMES ARE TAKEN FROM A
FILE.

AIM:
To write a program to flash an led at a given on time and off time cycle, where the
two times are taken from a text file.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] Bread Board
[3] One Led
[4] One Resistor
[5] Jumper Wires

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to read on/off time from txt file.
STEP 4: Connect raspberry pi GPIO pins to breadboard with LED.
STEP 5: Save the program and run the program.
STEP 6: Stop the process.
CODING:
import [Link] as GPIO
import time
[Link](False)
[Link]([Link])
[Link](8,[Link])
file=open('[Link]','r')
r=[Link]()
a=int(r[4])
[Link](8,True)
[Link](a)
[Link](8,False)

16
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

17
PROGRAM 4. SWITCH ON A RELAY AT A GIVEN TIME WHERE THE
RELAY’S CONTACT TERMINALS ARE CONNECTED
TO A LOAD.

AIM:
To write a program to Switch on a relay at a given time where the relay’s contact
terminals are connected to a load.
COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] Bread Board
[3] One LED
[4] One Resistor
[5] One Relay Module
[6] Jumper Wires

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to turn the relay on and off.
STEP 4: Connect raspberry pi GPIO pins to breadboard with relay, led.
STEP 5: Save the program and run the program.
STEP 6: Stop the process.
CODING:
import [Link] as GPIO
import time
[Link]([Link])
[Link](32,[Link])
[Link](8,[Link])
[Link](8,True)
while True:
[Link](32,True)
[Link](1)
[Link](32,False)
[Link](1)
18
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

19
PROGRAM 5. ACCESS AN IMAGE THROUGH A PI WEB CAM.

AIM:
To write a program to access an image through a pi web cam.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] Pi Web Cam

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to capture image in pi cam.
STEP 4: Connect raspberry pi camera port with pi cam.
STEP 5: Save the program and run the program.
STEP 6: Stop the process.
CODING:
from picamera import PiCamera
import time
camera =
PiCamera()
[Link](2)
[Link]("/home/pi/Pictures/[Link]")
print("Done.")

OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired

20
results.

21
PROGRAM 6. CONTROL A LIGHT SOURCE USING WEB PAGE.

AIM:

To write a program to control a light source using web page.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] One LED
[3] One Resistor
[4] Jumper Wire

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to create a webpage.
STEP 4: Access the IP address of RPi to control the LED.
STEP 5: Save the program and run the program.
STEP 6: Stop the process.
CODING:
import [Link] as GPIO
import os
from [Link] import BaseHTTPRequestHandler, HTTPServer
host_name = '[Link]' # IP Address of Raspberry Pi
host_port = 8000
def setupGPIO():
[Link]([Link])
[Link](False)
[Link](18, [Link])

def getTemperature():
temp = [Link]("/opt/vc/bin/vcgencmd measure_temp").read()
return temp

class MyServer(BaseHTTPRequestHandler):
def do_HEAD(self):
22
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def _redirect(self, path):
self.send_response(303)
self.send_header('Content-type', 'text/html')
self.send_header('Location', path)
self.end_headers()
def do_GET(self):
html = '''
<html>
<body
style="width:960px; margin: 20px auto;">
<h1>Welcome to my Raspberry Pi</h1>
<form action="/"
method="POST"> Turn LED :
<input type="submit" name="submit" value="On">
<input type="submit" name="submit" value="Off">
</form>
</body>
</html>
'''
temp = getTemperature()
self.do_HEAD()
[Link]([Link](temp[5:]).encode("utf-8"))

def do_POST(self):

content_length = int([Link]['Content-Length'])
post_data = [Link](content_length).decode("utf-8")
post_data = post_data.split("=")[1]

setupGPIO()

23
if post_data == 'On':
[Link](18, [Link])
else:
[Link](18, [Link])

print("LED is {}".format(post_data))
self._redirect('/') # Redirect back to the root url

# # # # # Main # # # # #

if name == ' main ':


http_server = HTTPServer((host_name, host_port), MyServer)
print("Server Starts - %s:%s" % (host_name, host_port))
try:
http_server.serve_forever()
except KeyboardInterrupt:
http_server.server_close()
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.
24
PROGRAM 7. IMPLEMENT AN INTRUDER SYSTEM THAT SENDS AN
ALERT TO THE GIVEN EMAIL.

AIM:

To write a program to implement an intruder system that sends an alert to the


given email.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] PIR Sensor
[3] PI Cam

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to create intruder system.
STEP 4: Access the PI cam and alert the user.
STEP 5: Save the program and run the program.
STEP 6: Stop the process.
CODING:
import smtplib
import time
from [Link] import MIMEMultipart
from [Link] import MIMEText
from [Link] import MIMEImage
import [Link] as GPIO
import picamera
# Email account details
from_email = "yourmail@[Link]"
to_email = "itsgopalmail@[Link]"
password = "app key password"
# PIR sensor setup
[Link]([Link])
[Link](4, [Link])

25
# Camera setup
camera =
[Link]() while
True:
if [Link](4):
print("Motion detected!")
# Capture an image
[Link]('[Link]')
# Create the message
msg = MIMEMultipart()
msg["From"] = from_email
msg["To"] = to_email
msg["Subject"] = "Intrusion Alert"
body = "Intrusion detected! Image attached"
[Link](MIMEText(body, "plain"))
# Open the image file
with open("[Link]", "rb") as img_file:
img_data = img_file.read()
# Attach the image to the email
image = MIMEImage(img_data, name="[Link]")
[Link](image)
# Connect to the SMTP server and send the email
smtp_server = [Link]("[Link]", 587)
smtp_server.starttls()
smtp_server.login(from_email, password)
smtp_server.sendmail(from_email, to_email, msg.as_string())
smtp_server.quit()
[Link](1)

26
OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

27
PROGRAM 8. GET THE STATUS OF A BULB AT A REMOTE PLACE (ON
THE LAN) THROUGH WEB.

AIM:

To write a program to get the status of a bulb at a remote place (on the LAN) through
web.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] One LDR
[3] One Resistor
[4] Jumper Wire

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to get LED status.
STEP 4: Access the webpage to know the details of LED
STEP 5: Save the program and run the program.
STEP 6: Stop the process.

CODING:
from flask import Flask, render_template
import [Link] as GPIO
app = Flask( name )
[Link]([Link])
[Link](18, [Link])
@[Link]("/")
def index():
light_level =
[Link](18) if
light_level:
label = "Dark"
else:
label = "Bright"
28
templateData = {

29
'light_level': label
}
return render_template('[Link]',
**templateData) if name == " main ":
[Link](host='[Link]', port=8000, debug=True)

OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

30
PROGRAM 9. GET AN ALARM FROM A REMOTE AREA (THROUGH
LAN) IF SMOKE IS DETECTED. THE STUDENT SHOULD HAVE HANDS ON
EXPERIENCE IN USING VARIOUS SENSORS LIKE TEMPERATURE,
HUMIDITY, SMOKE, LIGHT, ETC. AND SHOULD BE ABLE TO USE
CONTROL WEB CAMERA, NETWORK, AND RELAYS CONNECTED TO
THE PI.

AIM:

To write a program to get an alarm from a remote area (through lan) if smoke
is detected. the student should have hands on experience in using various sensors like
temperature, humidity, smoke, light, etc. and should be able to use control web
camera, network, and relays connected to the pi.

COMPONENTS REQUIRED:
[1] Raspberry Pi – Charger with HDMI Cable
[2] Buzzer
[3] Mq2 – Smoke Sensor

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start -> Thonny Python
STEP 3: Then enter the python code to get LED status.
STEP 4: Access the webpage to know the details of LED
STEP 5: Save the program and run the program.
STEP 6: Stop the process.

CODING:
import [Link] as GPIO
import time
import Adafruit_GPIO.I2C as I2C

[Link]([Link])
[Link](False)
sensor_pin = 18
buzzer_pin = 17
31
[Link](sensor_pin, [Link])
[Link](buzzer_pin, [Link])
one=1
while True:
sensor_value = [Link](sensor_pin)
if sensor_value==one:
[Link](buzzer_pin, False)
print(sensor_value)
else:
[Link](buzzer_pin, True)
[Link](1)
print(sensor_value)

OUTPUT:

RESULT:
Thus the expected program was executed successfully and obtained the desired
results.

32

You might also like