0% found this document useful (0 votes)
94 views96 pages

IoT Course Syllabus and Module Overview

Uploaded by

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

IoT Course Syllabus and Module Overview

Uploaded by

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

INTERNET OF THINGS

Course Code : 6131A

IoT – Module 4 1
SYLLABUS
Program : Diploma in Computer Engineering
Course Code : 6131 A Course Title : Introduction to IoT
Semester : 6 Credits : 4
Course Category : Program Elective
Periods per week : 4 (L:3 T:1 P:0) Periods per semester : 60

Course Objectives:
 Provide knowledge on the basic building blocks of IoT and its applications.
 Familiarise different protocols used in IoT.
 Introduce the relationship between IoT and cloud.
 Explore the implementations of IoT.

IoT – Module 4 2
SYLLABUS

Course Prerequisites:

Topic Course Code Course Name Semester


Embedded Systems and Real
Embedded Systems 5131 5
Tile Operating System
Computer Networking Computer Communication &
4132 4
Concepts and Protocols Networks
Programming Concepts 3132 Programming in C 3

IoT – Module 4 3
COURSE OUTCOMES
On the completion of the course student will be able to:

Duration Cogitative
COn Description
(Hours) level
Explain the fundamental concepts of Internet of Things
CO1 13 Understanding
(IoT)
CO2 Interpret the protocols used in IoT infrastructure 13 Understanding
CO3 Explain the use of cloud for IoT 12 Understanding
Illustrate the development of IoT applications with
CO4 20 Understanding
Embedded Computing Boards.
Series Test 2

IoT – Module 4 4
MODULE IV

Development of IoT Applications with


Embedded Computing Boards

IoT – Module 4 5
MODULE II - OUTCOMES
Module outcomes
On the completion of the module student will be able to:
Duratio
Module
Description n Cognitive Level
Outcomes
(Hours)
CO 4 Illustrate the development of IoT applications with embedded computing boards.
M4.01 Illustrate the working of sensors and actuators 2 Understanding
Outline the features of embedded computing boards - Arduino/Node
M4.02 2 Understanding
MCU & Raspberry PI
Illustrate the interfacing of basic sensors with embedded computing
M4.03 3 Understanding
board - Arduino/Node MCU/ESP32
M4.04 Recall the programming constructs in Python 3 Understanding
Illustrate the interfacing of basic sensors with embedded computing
M4.05 5 Understanding
board – Raspberry PI
Summarize the applications building with IoT - Smart Perishable
tracking/Smart transportation, Smart Healthcare, Smart Lavatory
M4.06 5 Understanding
maintenance, Smart water through IoT, Smart warehouse monitoring,
Smart Retail, Smart Driver assistance system 6
IoT – Module 4
MODULE II - OUTCOMES
Module outcomes
On the completion of the module student will be able to:

Contents

Sensors and Actuators - Role of Sensors and Actuators in IoT - Working of Sensors and
Actuators - Examples.
Embedded Computing Boards - features and characteristics of Arduino/Node MCU &
Raspberry PI, Interfacing basic sensors with Computing boards Python - data types,
control structures, modules, packages, input/output.
Programming Raspberry Pi with python, Interfacing sensors and actuators with Raspberry
PI.
Case Study - Applications building with IoT- Smart Perishable tracking/Smart
transportation, Smart Healthcare, Smart Lavatory maintenance, Smart water through IoT,
Smart warehouse monitoring, Smart Retail, Smart Driver assistance system.
*(sensors for applications like agricultural (temperature, humidity), pollution
(gas/pollution), industrial (fire alarm), )
IoT – Module 4 7
Sensors
• Sensors play a crucial role in the Internet of Things (IoT).
• They are responsible for collecting data from the environment, converting it into
digital signals, and transmitting it to IoT devices or platforms for analysis and action.
• Sensors serve as the foundation of IoT by providing the necessary data inputs for
monitoring, analysis and decision-making in a wide range of applications across
industries and domains.
• Some key roles of sensors in IoT are :
1. Data collection 6. Environmental monitoring
2. Asset tracking and Management 7. Health monitoring
3. Predictive Maintenance 8. Energy Management
4. Security and Surveillance 9. Smart agriculture
5. Consumer Electronics etc

IoT – Module 4 8
Sensors
Role of Sensors in IoT

1. Data Collection - Sensors gather various types of data such as temperature,


humidity, light, motion, pressure, sound, and more from the physical world.
2. Environmental Monitoring - Sensors can be deployed in various environments to
monitor conditions such as air quality, pollution levels, weather patterns, and more.
3. Asset Tracking and Management - Sensors equipped with GPS or RFID
technology can track the location and movement of assets such as vehicles,
inventory, equipment, and even people.
4. Health Monitoring: Wearable sensors can monitor vital signs, activity levels, and
other health-related parameters to provide individual's health status. This data can
be used for remote patient monitoring, fitness tracking, and early detection of health
issues.

IoT – Module 4 9
Sensors ..
Role of Sensors in IoT…..

5. Predictive Maintenance - Sensors installed in machinery and equipment can


collect data on parameters like temperature, vibration, and usage patterns.
6. Energy Management - Sensors can monitor energy consumption in buildings,
industrial processes, and infrastructure.
7. Security and Surveillance - Sensors such as cameras, motion detectors, and
door/window sensors are utilized for security and surveillance applications.
8. Smart Agriculture - Sensors deployed in fields can monitor soil moisture,
temperature, and other parameters to optimize irrigation, fertilization, and crop
management.
9. Consumer Electronics: Sensors are integral components of various consumer
devices such as smart phones, smart watches, and smart home appliances.

IoT – Module 4 10
Actuators
• An actuator is a device that converts energy into physical motion.
• An actuator is a component that can move or control a mechanism or system.
• Actuators are commonly employed in industrial automation, robotics, and other
applications requiring precise mechanical system control.
• Actuators are an essential component of the IoT applications.
• They enable gadgets to interface with the physical world.
• Sensors collect data from the environment in an IoT system, and actuators use this
data to make decisions and conduct actions.
• Eg: if a temperature sensor detects that the room is becoming too hot, an actuator
may activate the air conditioning to cool it down.

IoT – Module 4 11
Type of Sensors
1. MQ – 02/05 – Gas Sensor

• MQ2 gas sensor is used for detecting smoke and some


flammable gases like LPG, Methane, etc. MQ 02
• It changes its resistance depending on the type of the
gas.
• It is vastly used because of its quick and rapid
response
• When any flammable gas flows through this sensor
the coil inside burns and its resistance decreases
causing it to increase output voltage which can be
detected by a microcontroller
• This principle can be used to raise an alarm based on
the concentration of the gas.
IoT – Module 4 12
Type of Sensors ….
MQ – 02/05 – Gas Sensor Working

• The MQ2 sensor is a Metal Oxide Semiconductor (MOS) based sensor like a
Light-dependent resistor (LDR).
• Depending on the level of concentration of the gas, the sensor outputs a potential
difference, which changes the resistance of the material inside the sensor.
• This change is used to determine the type of gas as well as the concentration of its
presence in the atmosphere from the analog output of the sensor.
• Digital values (Digital out pin) from the sensor can be used to detect the presence
of these gases.

IoT – Module 4 13
Type of Sensors ….
Interfacing MQ-02 with Arduino

• MQ-02 has four pins .


• VCC - Power pin for gas detection sensor it can be connected to 5V
• Ground - Ground pin of sensor connected to Arduino GND pin
• Dout - Digital output pin indicates gas presence. It can output either in HIGH or LOW
state like 1 and 0.
• A out - Analog output pin indicates gas presence in analog signal. Output data gives a
continuous value between Vcc and GND based on the level of gas detected.
• Connect VCC pin of the sensor to the Arduino’s 5V pin.
• Connect the GND of the sensor to the GND of Arduino.
• Connect the digital pin of the sensor D0 to the digital pin number 8 of the Arduino.
• Connect the analog pin of the sensor to the analog pin A0 of the Arduino.
• LED will indicate if gas concentration is increased from a certain threshold.
IoT – Module 4 14
Type of Sensors ….
Interfacing MQ-02 with Arduino

IoT – Module 4 15
Type of Sensors ….
2. Interfacing Obstacle Sensor (IR Sensor)

• IR Sensors are used for detecting obstacles.


• When an obstacle is sensed it will give either 0 or 1 as digital
output.
• The IR sensor has a 3-pin connector that interfaces it to the
outside world.
1. VCC is the power supply pin for the IR sensor which
connect
to the 5V pin on the Arduino.
2. OUT pin is a 5V TTL logic output. LOW indicates no motion
is detected; HIGH means motion is detected
3. GND should be connected to the ground of the Arduino.

IoT – Module 4
16
Type of Sensors ….
Interfacing Obstacle Sensor (IR Sensor) ….

IoT – Module 4
17
Type of Sensors ….
3. Heartbeat Sensor
• Used to monitor the heartbeat of a person accurately.
• It consists of a light-emitting diode and a detector like a light
detecting resistor or a photodiode.
• The heartbeat pulses cause a variation in the flow of blood to
different regions of the body.
• When tissue is illuminated with the light source, i.e. light
emitted by the led, it either reflects (a finger tissue) or
transmits the light (earlobe).
• Some of the light is absorbed by the blood and the transmitted
or the reflected light is received by the light detector.
• The amount of light absorbed depends on the blood volume in
that tissue.
• The detector output is in the form of the electrical signal and is
proportional to the heartbeat rate. IoT – Module 4
18
Type of Sensors ….
Interfacing Heartbeat Sensor
• 24″ flat ribbon cable with three male header connectors
• Signal is the signal output. Connects to analog input of an Arduino.
• + (VCC) is the VCC pin. Connects to 3.3 or 5V.
• (GND) is the Ground pin.

IoT – Module 4
19
Type of Sensors ….
4. Ultrasonic Sensor (HC – SR04)
• It can only measure the distance from
the object.
• It cannot determine the type of object.
• These sensors emanate ultrasonic
sound which travels and hits the
surrounding object.
• The received ultrasonic pulse is
captured by the sensor.
• The sensor produces an output pulse
whose width is proportional to the
distance of the object in front.
• This sensor cannot determine what
type of object.
IoT – Module 4
20
Type of Sensors ….
Interfacing Ultrasonic Sensor (HC – SR04)
• VCC supplies power to the HC-SR04 ultrasonic
sensor. Connect it to the 5V output from Arduino.
• Trig (Trigger) pin is used to trigger ultrasonic sound
pulses. By setting this pin to HIGH for 10µs, the
sensor initiates an ultrasonic burst.
• Echo pin goes high when the ultrasonic burst is
transmitted and remains high until the sensor receives
an echo, after which it goes low. By measuring the
time the Echo pin stays high, the distance can be
calculated.
• GND is the ground pin. Connect it to the ground of
the Arduino.
• Connect the trig and echo pins to digital pins #9 and
#10 (#11 and #12) of Arduino respectively.
IoT – Module 4
21
Type of Sensors ….
Interfacing Ultrasonic Sensor (HC – SR04) ….

IoT – Module 4
22
Type of Sensors ….
5. LDR Sensor

• Light Dependent Resistor(LDR) or a photo resistor is


a component that is used to detect light.
• It detects the light intensity.
• It is a variable resistor and changes its resistance in a
proportion to the light exposed to it.
• has a resistance which changes with the light
intensity that falls upon it
• It’s resistance decreases with the intensity of light.

IoT – Module 4
23
Type of Sensors ….
Interfacing LDR Sensor

Connections of LDR Sensor


• First terminal of LDR should be connected to analog pin O (A0) of Arduino.
• Second terminal should be connected to one leg of the resistor.
• Another leg of the resistor should be connected to GND of Arduino.
LED Connections
• Positive lead should be connected to digital pin 5 of Arduino.
• Negative lead should be connected to any one lead of the resistor.
• Another lead of the resistor should be connected to GND of Arduino.

IoT – Module 4
24
Type of Sensors ….
Interfacing LDR Sensor ….

IoT – Module 4
25
Type of Sensors ….
6. GPS Sensor
• GPS sensors are used for acquiring the location
data of the place where the sensor is present
How does GPS work?
• GPS is a system of 30+ navigation satellites
orbiting the earth.
• They constantly transmit information about
their position and current time to Earth in the
form of radio signals.
• A GPS receiver listens to these signals.
• Once the receiver calculates its distance from
at least three GPS satellites.
• This process is known as Trilateration.

IoT – Module 4
26
Type of Sensors ….
Interfacing the GPS module (NEO-6M)
• GPS modules are compact devices designed to
simplify the process of integrating GPS
functionality.
• It includes GPS receiver, an antenna and processing
unit.
• The processing unit handles the tasks such as
decoding the signals, calculating the position,
providing information to an external microcontroller
etc.
• GPS module communicate with the Arduino through
serial communication.
• Connect an active GPS antenna to the antenna
connector to the GPS module which increases the
receiving of GPS signals. IoT – Module 4
27
Type of Sensors ….
Interfacing the GPS module (NEO-
6M) ….
• Connect 5V from the Arduino to Vin
on the GPS Breakout
• Connect GND to GND
• Connect the Rx Pin from the GPS
Module to Digital Pin 2 on the
Arduino
• Connect the Tx Pin from the GPS
Module to Digital Pin 3 on the
Arduino

IoT – Module 4
28
Type of Sensors ….
7. Colour Sensor (TCS3200)

• They are used to detect the RGB coordinates of a particular colour.


• When white light falls on any surface, some wavelengths of light are absorbed and
some are reflected, depending on the properties of the surface material.
• The photodiodes detect the light reflected from the object.
• Each photodiode is sensitive to a particular color due to its color filter.
• The sensor modulates this information into signals based on the absorbed color
intensity.
• By analyzing these signals to determine the color of an object.

IoT – Module 4
29
Type of Sensors ….
Interfacing Colour Sensor (TCS3200)

IoT – Module 4
30
Type of Sensors ….
Interfacing Colour Sensor (TCS3200)

• VCC (Voltage Supply): The pin provides power to the sensor which can be 5 volts
• GND (Ground): This pin is used to connect the sensor to the ground (0V).
• S0 and S1: These pins are used to set the frequency scaling factor. By toggling
these pins between high and low states, we can select different frequency scales,
which in turn affect the sensitivity of the sensor to different colors. (power down,
2%, 20%, and 100%)
• S2 and S3: These pins are used to select the type of color filtering applied by the
sensor.(Red, Blue, Clear (No filter), Green)
• OE (Output Enable): Control the Sensor output pin. Making it LOW will enable
the sensor output.
• OUT: Provides the Signal Output.

IoT – Module 4
31
Type of Sensors ….
Interfacing Colour Sensor
(TCS3200) ….

• Connect the OUT pin of


sensor to Arduino digital pin
D8.
• Connect S2,S3 to Pin D7,D6.
• Connect S1,S0 to Pin D5,D4
• Connect the sensor Vcc to 5V
and Gnd to Gnd pins.

IoT – Module 4
32
Type of Sensors ….
8. pH Sensor

• Used to detect the hydrogen ion(H+) concentration of a liquid, thus indicating its
acidity or alkalinity
• When this sensor is immersed in a solution the smaller ions are able to penetrate the
boundary area of the glass membrane and the larger ions remain in the solution.
• This creates a potential difference
• The pH meter measures the difference in electrical potential between the pH
electrodes
• It returns different analog values for different liquids

IoT – Module 4
33
Type of Sensors ….
Interfacing pH Sensor
• Connect the VCC of the sensor to the 5V of the
Arduino.
• Connect the GND of the sensor to the GND of the
Arduino
• Connect the signal pin of the sensor to the A0 of the
Arduino.
• Interface the I2C module with a display properly.
• Connect 5V and GND of the display to the 5V and
GND of the Arduino.
• Connect CLK of the display to the A5 pin of
Arduino.
• Connect the DAT pin to the A4 pin of the Arduino.

IoT – Module 4
34
Type of Sensors ….
Interfacing pH Sensor ……

IoT – Module 4
35
Embedded Computing Boards
• Embedded boards are boards with processors, multiple integrated circuits,
interfaces and other essential components assembled on them to serve a dedicated
function.
• Embedded boards comprise of multiple to provide functionality and performance
for embedded system design applications.
• In a system all of these sub components would work together to form one central
processing system.
• Embedded development boards are specialized computer hardware designed for a
specific task or tasks within a larger system.
• In IoT (Internet of Things), these boards function as the brains of all the IoT
devices, from relatively simple smart doorbells to advanced manufacturing robots.

• Eg: Arduino, Raspberry Pi etc

IoT – Module 4
36
Arduino
• Arduino is an open-source electronics platform based on easy-to-use hardware and
software.
• It consists of a circuit board, which can be programed (referred to as a
microcontroller) and a ready-made software called Arduino IDE (Integrated
Development Environment), which is used to write and upload the computer code
to the physical board.
• The board includes digital I/O, a power jack, analog I/P, ceramic resonator, USB
connection, an RST button, and an ICSP (In-circuit serial programming) header.
• All these can support the microcontroller for further operation by connecting this
board to the computer.
• The power supply of this board can be done with the help of an AC to DC adapter,
a USB cable, otherwise a battery.

IoT – Module 4
37
Arduino

IoT – Module 4
38
Features of Arduino
• The operating voltage is 5V.
• The recommended input voltage will range from 7V to 12V
• 14 Digital input/output pins.
• 6 Analog input pins.
• DC current for each input/output pin is 40mA
• Flash Memory size is 32KB
• SRAM size is 2KB
• 1KB EEPROM.
• The USB interface is also used to provide power supply to the board. USB enables
the board to acts as a serial device.
• The microcontroller used is ATMega328.
• The board has also one LED fitted inboard to make the debugging process easy and
help to find the bugs in the code.
• The board has also one reset button that helps to restart the program using the board.
IoT – Module 4
39
Raspberry PI
• Raspberry Pi is developed by Raspberry Pi Foundation in the United Kingdom in
2012.
• Raspberry Pi is known as a single-board computer similar to a desktop, laptop, or
smartphone.
• It is constructed from a single printed circuit board.
• Raspberry Pi is small, about the size of a credit card.
• It have been several iterations and variations released.
• They all have GPIO (General Purpose Input/Output) pins that allow users to
connect and control external devices such as sensors, motors, and cameras.
• They can run various operating systems, including Linux based Raspberry Pi OS.
• Different variants of Pi are : 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 Zero (2015), Pi 3 Model
B (2016), Pi Zero W (2017), Pi 3 Model B+ (2018), Pi 3 Model A+ (2019), Pi 4
Model A (2019), Pi 4 Model B (2020), Pi 400 (2021)
IoT – Module 4
40
Raspberry PI ….

IoT – Module 4
41
Raspberry PI ….

IoT – Module 4
42
Features of Raspberry Pi
1. CPU
• It is the brain and carries out instructions using
logical and mathematical operations. In
raspberry Pi, the ARM11 series processor is used
as CPU.

2. HDMI Port
• Raspberry Pi board has an HDMI or High
Definition Multimedia Interface port.
• It has video output options which are on the
computer.
• An HDMI cable connects the Raspberry Pi to a
display device such as TV.
• It also has an RCA port for other display options.
IoT – Module 4
43
Features of Raspberry Pi ….
3. Graphic Processing Unit (GPU)
• Its primary purpose is to fasten the speed of image calculations.
4. Memory (RAM)
• It is where real-time information is stored for easy access.
• The Raspberry Pi had an initial 256MB RAM size.
• The latest model (Raspberry Pi 4) with the maximum capacity is 8GB RAM .
5. Wi fi
• Wi-Fi allows devices such as mobile devices, computers, wearables, and other
equipment to interface with the Internet wirelessly using radio waves.
• Raspberry Pi supports 2.4/5 GHz dual-band Wi-Fi.
6. Bluetooth
• Bluetooth is a high-speed wireless connectivity technology that is used to transfer
data within a small range.
• It is used to connect one device with other devices wirelessly. The latest version of
Raspberry supports Bluetooth 5 connectivity.
IoT – Module 4
44
Features of Raspberry Pi ….
7. Ethernet Port
• Use Ethernet Port to establish an internet connection for the Raspberry Pi.
• With the help of Ethernet ports, we can establish a wired internet connection to the
Raspberry Pi.
• Ue the RJ45 Ethernet Jack for the Ethernet port.

8. SD Card Slot
• The Raspberry Pi boards contains SD card to act as a hard drive, and it can also
contain the operating system necessary for turning the system on.

IoT – Module 4
45
Python

IoT – Module 4 46
Introduction to Python
• Python is a popular programming language.
• It was created by Guido van Rossum, and released in 1991.
• It is used for:
 Web development (server-side),
 Software development,
 Mathematics,
 System scripting.

IoT – Module 4
47
Python Input/Output
Python Input

• input() function is used to input data from the user.


• Syntax is : input(prompt)
prompt is the string to display on the screen.

Example :
# using input() to take user input
num = input('Enter a number: ')

Here, the input() function to take input from the user and stored the user input in
the num variable.

IoT – Module 4
48
Python Input/Output …..
Python Output
• print() function is used to print output.
• Syntax is : print(object = separator = end = file = flush=)
 object - value(s) to be printed.
 sep (optional) - To separate multiple objects inside print().
 end (optional) - To add specific values like new line "\n", tab "\t"
 file (optional) - where the values are printed. It's default value
is [Link] (screen)
 flush (optional) - boolean specifying if the output is flushed or buffered.
Default: False
Example :
print('Good Morning!')
# print with end whitespace
print('Good Morning!', end= ' ')
IoT – Module 4
49
Python Data Types
• Data types specify the type of data that can be stored inside a variable.
Example : num = 24, here 24 (an integer) is assigned to the num variable. So the
data type of num is of the int class.
Python Data Types
Data Types Classes Description
Numeric int, float, complex Holds numeric values
String str Holds sequence of characters
Sequence list, tuple, range Holds collection of items
Mapping dict Holds data in key-value pair form
Boolean bool Holds either true or false
Set set, frozenset Holds collection of unique items
• Data types are classes and variables are instances (object) of these classes
IoT – Module 4
50
Python Data Types …..
Numeric Data Types
• Numeric data type is used to hold numeric values.
• Integers, floating-point numbers and complex numbers . They are defined
as int, float and complex classes in Python.
• int - holds signed integers of non-limited length.
• float - holds floating decimal points and it's accurate up to 15 decimal places.
• complex - holds complex numbers.
• Use type() function to know which class a variable or a value belongs to.
Example
num1 = 5
print(num1, 'is of type', type(num1))
num2 = 2.0
print(num2, 'is of type', type(num2))
num3 = 1+2j
print(num3, 'is of type', type(num3))
IoT – Module 4
51
Python Data Types …..
List Data Types
• List is an ordered collection of similar or different types of items separated by
commas and enclosed within brackets [ ].
• Example : languages = [“C++", "Java", "Python"]
• To access items from a list, use the index number (0, 1, 2 ...).

Example,
languages = ["Swift", "Java", "Python"]
# access element at index 0
print(languages[0]) # Swift

# access element at index 2


print(languages[2]) # Python

IoT – Module 4
52
Python Data Types …..
Tuple Data Types
• Tuple is an ordered sequence of items same as a list.
• The only difference is that tuples are immutable. Tuples once created cannot be
modified.
• Use parentheses () to store items of a tuple.
Example : product = ('Xbox', 499.99)Here, product is a tuple with a string
value Xbox and integer value 499.99.
• Use the index number to access tuple items in Python .
Example,
# create a tuple
product = ('Microsoft', 'Xbox', 499.99)
# access element at index 0
print(product[0]) # Microsoft
# access element at index 1
print(product[1]) IoT – Module 4
# Xbox
53
Python Data Types …..

String Data Types

• String is a sequence of characters represented by either single or double quotes.


Example :
name = 'Python'
print(name)
message = 'Python for beginners'
print(message)

IoT – Module 4
54
Python Data Types …..

Set Data Types

• Set is an unordered collection of unique items.


• Set is defined by values separated by commas inside braces { }.

Example,
# create a set named student_id
student_id = {112, 114, 116, 118, 115}
# display student_id elements
print(student_id)
# display type of student_id
print(type(student_id)) # display <class ‘set’>

IoT – Module 4
55
Python Data Types …..

Dictionary Data Types


• Dictionary is an ordered collection of items.
• It stores elements in key/value pairs.
• Here, keys are unique identifiers that are associated with each value.
Example,
# create a dictionary named capital_city
capital_city = {'Nepal': 'Kathmandu', 'Italy': 'Rome', 'England': 'London'}
print(capital_city)
• Use keys to retrieve the respective value.
Example,
# create a dictionary named capital_city
capital_city = {'Nepal': 'Kathmandu', 'Italy': 'Rome', 'England': 'London'}
print(capital_city['Nepal']) # prints Kathmandu

IoT – Module 4
56
Control Structure in Python

• Control structures that enables the flow of control.


• Control flow refers to the sequence of a program during its execution.
• There are three types of control structures in python.
 Sequential - The default working of a program
 Selection - This structure is used for making decisions by checking conditions
and branching
 Repetition - This structure is used for looping, i.e., repeatedly executing a
certain piece of a code block.

IoT – Module 4
57
Control Structure in Python ….
Sequential
• Sequential statements are a set of statements whose execution process happens in a
sequence.
• In this, if the logic has broken in any one of the lines, then the complete source
code execution will break.

Example:
a = 20
b = 10
c=a-b
d=a+b
print("The result of the subtraction is: ", c)
print("The result of the addition is: ", d)

IoT – Module 4
58
Control Structure in Python ….

Selection/Decision Control
• They are also referred as branching statements or decision control statements.
• A program can test many conditions using these selection statements depending
on whether the given condition is true or not, it can execute different code blocks.
• Commonly used decision control structures are :
 if
 if-else
 nested if
 if-elif-else

IoT – Module 4
59
Control Structure in Python ….
Selection/Decision Control ….
1. if Statement
•An if statement executes a block of code only if the specified condition is met.

Syntax
if condition:
# body of if statement

Example
if number > 0:
print('Number is positive')

IoT – Module 4
60
Control Structure in Python ….
Selection/Decision Control ….
2. if .. else Statement
• An if statement can have an optional else clause.
• The else statement executes if the condition in the if statement is False.
Syntax
if condition:
# body of if statement
else:
# body of else statement
Example
number = 10
if number > 0:
print('Positive number')
else:
print('Negative number')
print('This statement always executes') IoT – Module 4
61
Control Structure in Python ….
Selection/Decision Control ….
3. if…elif…else Statement
• The if...else statement execute a block of code among two alternatives.
• If we need to make a choice between more than two alternatives, use
the if...elif...else statement.
Syntax
if condition1:
# code block 1
elif condition2:
# code block 2
else:
# code block 3

IoT – Module 4
62
Control Structure in Python ….
Selection/Decision Control ….
3. if…elif…else Statement

Example

number = 0
if number > 0:
print('Positive number')
elif number <0:
print('Negative number')
else:
print('Zero')
print('This statement is always executed')

IoT – Module 4
63
Control Structure in Python ….
Selection/Decision Control ….
4. Nested if Statements
• It is possible to include an if statement inside another if statement.
Syntax
if condition1:
# code block 1
if condition2:
# code block 2
# if Block is end here
# if Block is end here

IoT – Module 4
64
Control Structure in Python ….
Selection/Decision Control ….
4. Nested if Statements …
Example
number = 5
# outer if statement
if number >= 0:
# inner if statement
if number == 0:
print('Number is 0')
# inner else statement
else: print('Number is positive')
# outer else statement
else:
print('Number is negative')
IoT – Module 4
65
Control Structure in Python ….

Repetition

• To repeat a certain set of statements, use the repetition structure.


• There are generally two loop statements to implement the repetition structure:
 while loop
 for loop

IoT – Module 4
66
Control Structure in Python ….
Repetition ….
while Loop
• In Python, use the while loop to repeat a block of code until a certain condition is
met.
Syntax
while condition:
# body of while loop
Example
number = 1
while number <= 3:
print(number) number = number + 1

IoT – Module 4
67
Control Structure in Python ….
Repetition ….
for Loop
• In Python, a for loop is used to iterate over sequences such as lists, strings, tuples
etc.
Syntax
for val in sequence:
# statement(s)
• val accesses each item of the sequence on each iteration.
• The loop continues until we reach the last item in the sequence.
Example1
languages = ['Swift', 'Python', 'Go']
# access elements of the list one by one
for i in languages:
print(i)
IoT – Module 4
68
Control Structure in Python ….
Repetition ….
for Loop ….

Example 1
language = 'Python'
# iterate over each character in language
for x in language:
print(x)

Example 2
# iterate from i = 0 to i = 3
for i in range(4):
print(i)

IoT – Module 4
69
Modules in Python
• A module is a file containing Python definitions and statements to perform a
specific task.
• The file name is the module name with the suffix .py appended.
• Within a module, the module’s name (as a string) is available as the value of the
global variable __name__
Create a Python Module
• To create a Python module, write the desired code and save that in a file with .py
extension.
• Example: To create a module [Link] having two functions add and subtract.
# A simple module, [Link]
def add(x, y):
return (x+y)
def subtract(x, y):
return (x-y)
IoT – Module 4
70
Modules in Python …
Import modules in Python
• Use import statement to import the functions and classes defined in a module to
another module.
• Syntax is : import module
• To access the function inside the module the dot(.) operator is used.

• Example : importing calc module to perform add operation

# importing module [Link]


import calc
print([Link](10, 2))

IoT – Module 4
71
Modules in Python …
Python Import From Module
• Python’s from statement lets to import specific attributes from a module without
importing the module as a whole.
• To import specific attributes sqrt and factorial from the math module.
• Example
# importing sqrt() and factorial from the module math

from math import sqrt, factorial

# if we simply do "import math", then, [Link]() and [Link]() are


required.
print(sqrt(16))
print(factorial(6))

IoT – Module 4
72
Modules in Python …
Import all Names
• * symbol is used with import statement to import all the names from a module to a
current name space.
• Syntax : from module_name import *
• Example
# importing sqrt() and factorial from the module math

from math import *

# if we simply do "import math", then, [Link]() and [Link]() are


required.
print(sqrt(16))
print(factorial(6))

IoT – Module 4
73
Modules in Python …
Locating Python Modules
• Whenever a module is imported in Python the interpreter looks for several
locations.
• First, it will check for the built-in module, if not found then it looks for a list of
directories defined in the [Link].
• Python interpreter searches for the module in the following manner :
• First, it searches for the module in the current directory.
• If the module isn’t found in the current directory, Python then searches each
directory in the shell variable PYTHONPATH. The PYTHONPATH is an
environment variable, consisting of a list of directories.
• If that also fails python checks the installation-dependent list of directories
configured at the time Python is installed.

IoT – Module 4
74
Modules in Python …
Directories List for Modules
• [Link] is a built-in variable within the sys module. It contains a list of directories
that the interpreter will search for the required module.
• Example
• # importing sys module
import sys
• # importing [Link]
print([Link])
• Renaming the Python Module while importing it using the keyword.
• Syntax: Import Module_name as Alias_name
• Example : import math as mt
Built-in modules
import math
import random
import datetime IoT – Module 4
75
• Package in Python is a folder that contains various modules as files.
• Packages allow for a hierarchical structuring of the module namespace
using dot notation.

• Choose a name for your package and create a directory with that name.
• Create an [Link] file in the package directory. ...
• Create one or more Python modules (i.e., . ...
• Define the package's API in the [Link] file. ...
• Write documentation for your package, describing what it does and how to use
it.
• Choose a name for your package and create a directory with that name.
• Create an [Link] file in the package directory. This file can be empty, but it
signals to Python that this directory should be considered a package.
• Create one or more Python modules (i.e., .py files) in the package directory,
containing the functions and classes you want to include in your package.
• Define the package’s API in the [Link] file.
IoT – Module 4 This can include importing 76
IoT – Module 4 77
Interfacing of sensor with RPi
Simple IoT Architecture

IoT – Module 4
78
Interfacing of sensor with RPi
GPIO Pin Layout

IoT – Module 4
79
Interfacing of LED with RPi
Circuit Diagram Code
import [Link] as GPIO
import time
[Link]([Link])
[Link](False)
[Link](21,[Link])
print "LED on"
[Link](21,[Link])
[Link](10)
print "LED off"
[Link](21,[Link])

BCM : Broadcom SOC channel

IoT – Module 4
80
Interfacing buzzer with RPi
Circuit Diagram Code
import [Link] as GPIO
import time
[Link]([Link])
[Link](False)
[Link](21,[Link])
print "LED on"
[Link](21,[Link])
[Link](10)
print "LED off"
[Link](21,[Link])

BCM : Broadcom SOC channel

IoT – Module 4
81
Interfacing of Buzzer with RPi
Circuit Diagram Code

IoT – Module 4
82
Smart Perishable Tracking
Advantages

• The system helps in monitoring deterioration in the quality of the


food/vegetables during transportation.
• This helps to deliver them before they get spoiled.
• The system helps to reduce loss due to wastage of agricultural products between
source and destination.
• The system is very easy to be managed by delivery people.

IoT – Module 4
83
Smart Perishable Tracking …

IoT – Module 4
84
Smart Perishable Tracking ….
Data Acquisition
• Temperature, humidity and odour data collected from boxes in the truck through
sensors.
• Computing boards (NodeMCU, Arduino etc) deployed for transferring data to cloud
Cloud & Data Analytics
• Data received in cloud
• From cloud, transferred to google sheets through IFTTT
• Data analytics done.
Display the grade in Mobile App
• Processed data is sent to driver which shows the grade of the perishable and the
location where it is to be delivered.

IoT – Module 4
85
Smart Healthcare – Elderly Fall Detection System
Advantages
• The system reduces number of deaths of elderly people.
• The system relieves tension of caretakers of the elderly people.
• The caretakers need not have to be present 24 x 7 with the elderly people and hence
it saves time.
• The system does not cost much due to availability of cheaper components.
• The system provides immediate first aid by alerting caretakers immediately.

IoT – Module 4
86
Smart Healthcare – Elderly Fall Detection System

IoT – Module 4
87
Smart Healthcare – Elderly Fall Detection System

IoT – Module 4
88
Smart Healthcare – Elderly Fall Detection System
• The accelerometer sensor and gyroscope sensor are attached to the wearable.
• The wearable has to be worn on both the hands of the elderly people.
• It can also be worn like watch.
• With deliberate falling, threshold values of the sensors are derived and stored.
• The data acquired from the sensor are transmitted bluetooth low energy and wifi
and are pushed to the cloud storage server such as adafruit.
• Based on the comparison between realtime sensor data and stored threshold
values the caretaker is being alerted either through call or sms based on his/her
registered mobile number.

IoT – Module 4
89
Smart Inflight Lavatory Maintenance

IoT – Module 4
90
Smart Inflight Lavatory Maintenance
• The system uses two types of sensors - one gas sensor and two IR sensors.
• The gas sensor MQ-05 is used to assess methane level present in the lavatory.
• Threshold methane level for clean lavatory is identified.
• IR sensors are used for feedback by passenger which functions as touch sensors.
• The collected sensor data is uploaded to the cloud for storage and analysis.
• Based on the comparison between collected real-time sensor data and threshold
value of gas sensor, aircraft support staff is alerted for cleaning the lavatories.
• The alert is sounded when real-time methane level exceeds the threshold value.
• Moreover an alert is send to the crew when negative feedback is being given by
passenger.

IoT – Module 4
91
Smart Inflight Lavatory Maintenance …
Advantages

• It saves time of aircraft maintenance staff and can attend more number of aircrafts
to clean the lavatories.
• The passengers feel comfortable as they can have access to the lavatory most of the
time.
• The crew members also feel comfortable as they can concentrate on other services
inside the cabin.
• The system is very cheap and can be easily deployed.
• It does not require any maintenance once installed.

IoT – Module 4
92
Smart Water Quality Monitoring

IoT – Module 4
93
IoT based Smart Water Quality Monitoring ….

• Water sensor kit consists of many sensors used to measure water quality.
• They include pH sensor, temperature sensor, conductivity sensor, dissolved oxygen
sensor and so on.
• The data collected by sensors from various locations of the water body such as river
or lake are uploaded to cloud storage server.
• The data are being analyzed using machine learning techniques and appropriate
reports are being generated in different formats
• End users of the system can monitor the reports and results of water samples
collected from various locations using mobile or web app developed.
• GPS coordinates of the collected samples are also integrated in the reports to
understand level of contamination at particular locations.

IoT – Module 4
94
IoT based Smart Water Quality Monitoring ….

Advantages
• Large number of samples are easily collected from different locations in less time.
• The system is very cheap as the hardware and software does not cost much.
• Machine learning techniques have made it very easy to plot the data collected in
various formats for proper analysis.
• Cloud storage platforms helps in storing the sensor data immediately and wirelessly
to the robust servers.

IoT – Module 4
95
IoT based Smart Warehouse Monitoring

Advantages

IoT – Module 4
96

You might also like