[go: up one dir, main page]

0% found this document useful (0 votes)
17 views116 pages

Unit 4-1

Uploaded by

DHRUV SHETH
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)
17 views116 pages

Unit 4-1

Uploaded by

DHRUV SHETH
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/ 116

Internet of Things

& Applications
CE0622

Raspberry Pi & Cloud Computing


IoT Architecture
IoT Architecture

▪ Perception Layer: The perception layer is a hardware layer that


consists of sensors and physical objects in different forms. These Sensors or
Actuators accepts data(physical/environmental parameters), processes data
and emits data over network.

▪ Network Layer: The network layer is a transmission layer that transfers the
information from physical objects or sensors to the processing system over
secure lines using a communication system. (IoT Gateway)
○ Advanced gateways which mainly opens up connection between Sensor networks and Internet also
performs many basic gateway functionalities like malware protection, and filtering also sometimes
decision making based on inputted data and data management services, etc.
IoT Architecture

▪ Middleware Layer: The middleware layer obtains data from the network
layer, links the system to the cloud and database, and performs data processing
and storage.

▪ Application Layer: The application layer depends on the specifics of the


different implemented IoT applications, such as smart industry, building, city, and
health applications.
Development boards

Arduino platform

❏ Open Source Platform


❏ Good for prototyping
❏ Combines HW/SW
Raspberry PI

❏ Credit card size computer board


❏ Good for prototyping
❏ Combines HW/SW
Development boards
ESP development boards
Sensors
Arduino Uno 9
ARDUINO UNO Features 10

Microcontroller ATmega328P DC Current per I/O Pin 20 mA

Operating Voltage 5V DC Current for 3.3V Pin 50 mA

Input Voltage
7-12V 32 KB (ATmega328P) of which
(recommended) Flash Memory
0.5 KB used by bootloader
Input Voltage (limit) 6-20V
SRAM 2 KB (ATmega328P)
14 (of which 6 provide PWM
Digital I/O Pins
output) EEPROM 1 KB (ATmega328P)

PWM Digital I/O Pins 6 Clock Speed 16 MHz

Analog Input Pins 6 LED_BUILTIN 13


Arduino IDE 11

▪ Download from:
http://arduino.cc/en/Main/Software
Concept: Input v/s Output 12

Input Output
Inputs is a signal / information going in Output is signal going out from the
to the board board
Examples: Examples:

Switches , Light Sensors, Temperature LED , LCD, DC Motor , Buzzer, relay


Sensors, Pressure Sensors
Concept: Analog v/s Digital 13

Analog Digital

Analog signals are signals that can Microcontroller is digital device can
have full range, have values ON or OFF

Example: Example:
Code comparison
#define __SFR_OFFSET 0x20

#include "avr/io.h"

.global start
.global forever const int LED_Pin = 8;
#define F_CPU 16000000UL
start: #include <avr/io.h> void setup()
LDI R16, 0x01 ; Setting 1st bit of PORTB as output
STS DDRB, R16 #include <util/delay.h> {
LDI R17, 0x00
STS PORTB, R17 ; Writing 0 to PORTB int main(void)
pinMode(LED_Pin, OUTPUT);
LDI R16, 0x00
STS TCCR1A, R16 ; Setting all bits of TCCR1A as 0
{ }
RET DDRB |= (1<<DDB1);
while (1)
forever: { void loop()
LDI R16, 0xC2
STS TCNT1H, R16 ; Writing 0xC2 into TCNT1H (8-bit)
PORTB |= (1<<PORTB1); {
_delay_ms(1000);
LDI R16, 0xF7
STS TCNT1L, R16 ; Writing 0xF7 into TCNT1H (8-bit) PORTB &= ~ (1<<PORTB1);
digitalWrite(LED_Pin, LOW);
LDI R16, 0x05 _delay_ms(1000); delay(1000);
STS TCCR1B, R16 ; Writing 0x05 into TCCR1B
L:LDS R0, TIFR1 ; Load the value of TIFR1 into R0
}
} digitalWrite(LED_Pin, HIGH);
SBRS R0, 0 ; Skip the next statement if overflow has occured.
RJMP L ; Loop until overflow occurs. delay(1000);
LDI R16, 0x00
STS TCCR1B, R16 ; Stop the Timer/Counter1
}
LDI R16, 0x01
STS TIFR1, R16 ; Clear the overflow flag by writing 1 to it
COM R17 ; Complement R17 register
STS PORTB, R17 ; Toggle the LED output
RET
void setup() 15

▪ The setup() function is called


when a sketch starts.

▪ Use it to initialize variables, pin


modes, start using libraries,
etc. The setup() function will
only run once, after each
power up or reset of the
ARDUINO board.
void loop() 16

▪ After creating a setup() function,


which initializes and sets the
initial values, the loop() function
does precisely what its name
suggests, and loops
consecutively, allowing your
program to change and respond.
Use it to actively control the
Arduino board.
pinMode() 17

▪ Configures the specified pin to


behave either as an input or an
output.
▪ Syntax:
▪ pinMode(pin, mode)
▪ Parameters
▪ pin: the number of the pin whose
mode you wish to set
▪ mode: INPUT, OUTPUT, or
INPUT_PULLUP.
▪ Return
▪ Nothing
digitalWrite() 18

▪ Write a HIGH or a LOW value to


a digital pin.
▪ Syntax:
▪ digitalWrite(pin, value)
▪ Parameters
▪ pin: the pin number
▪ value: HIGH or LOW
▪ Return
▪ Nothing
digitalRead() 19

▪ Reads the value from a specified


digital pin, either HIGH or LOW.
▪ Syntax:
▪ digitalRead(pin)
▪ Parameters
▪ pin: the number of the digital pin
you want to read
▪ Returns
▪ HIGH or LOW
analogWrite() 20

▪ Writes an analog value (PWM wave) to a pin. Can be used to light a


LED at varying brightness's or drive a motor at various speeds. After a
call to analogWrite(), the pin will generate a steady square wave of the
specified duty cycle until the next call to analogWrite().
▪ Syntax:
▪ analogWrite(pin, value)
▪ Parameters
▪ pin: the pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed
data types: int
▪ Returns
▪ Nothing
analogWrite() 21
analogRead() 22

▪ Reads the value from the specified analog pin. Arduino boards contain
a multichannel, 10-bit analog to digital converter.
▪ Syntax:
▪ analogRead(pin)
▪ Parameters
▪ pin: the name of the analog input pin to read from
▪ Returns
▪ The analog reading on the pin (int). Although it is limited to the resolution of
the analog to digital converter
analogRead() 23
delay() 24

▪ Pauses the program for the amount of time (in milliseconds) specified
as parameter. (There are 1000 milliseconds in a second.)
▪ Syntax:
▪ delay(ms)
▪ Parameters
▪ ms: the number of milliseconds to pause (unsigned long)
▪ Returns
▪ Nothing
delay() 25
Other delay functions 26

▪ delayMicroseconds() – Here Delay will be in micro- seconds.

▪ micros() - Returns the number of microseconds since the Arduino


board began running the current program.(unsigned long)

▪ millis() - Number of milliseconds passed since the program started


(unsigned long)
Serial.begin() 27

▪ Sets the data rate in bits per second (baud) for serial data
transmission. For communicating with the computer, use one of these
rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800,
38400, 57600, or 115200.
▪ Syntax:
▪ Serial.begin(speed , config)
▪ Parameters
▪ speed: in bits per second (baud) - long
config: sets data, parity, and stop bits
▪ Returns
▪ Nothing
Serial.begin() 28
Serial.read() 29

▪ Reads incoming serial data.


▪ Syntax:
▪ Serial.read()
▪ Parameters
▪ None
▪ Returns
▪ the first byte of incoming serial data available (or -1 if no data is available)
Serial.read() 30
Serial.write() 31

▪ Writes binary data to the serial port. This data is sent as a byte or
series of bytes; to send the characters representing the digits of a
number use the print() function instead.
▪ Syntax:
▪ Serial.write(val)
▪ Parameters
▪ None
▪ Returns
▪ the first byte of incoming serial data available (or -1 if no data is available)
Serial.write() 32
Serial.print() and prinln() 33

▪ Prints data to the serial port as human-readable ASCII text. This


command can take many forms.
▪ Syntax:
▪ Serial.print(val)
▪ Serial.print(val, format)
▪ Parameters
▪ val: the value to print - any data type
▪ format: specifies the number base (for integral data types) or number of
decimal places (for floating point types)
▪ Returns
▪ size_t (long): print() returns the number of bytes written, though reading that
number is optional
Interrupts
▪ Consider a fast-moving car, if it suddenly gets hit by another car in opposite
direction, the first thing that happens is that, the accelerometer sensor
present in the car senses a sudden deceleration and triggers an external
interrupt to the microcontroller present in the car.

▪ Then based on that interrupt the microcontroller produces an electric signal


to deploy the airbags immediately.

▪ Interrupts is a mechanism by which an I/O or instruction can suspend the


normal execution of the processor and gets itself serviced like it has higher
priority.
Types of Interrupts
▪ There are two types of interrupts:

▪ Hardware Interrupt: It happens when an external event occurs like an


external interrupt pin changes its state from LOW to HIGH or HIGH to LOW.

▪ Software Interrupt: It happens according to the instruction from the software.


For example Timer interrupts are software interrupt.
Interrupts in Arduino
▪ It has two types of interrupts:
▪ External Interrupt
▪ Pin Change Interrupt
▪ External Interrupt:
▪ These interrupt are interpreted by hardware and are very fast. These
interrupts can be set to trigger on the event of RISING or FALLING or LOW
levels.
Interrupts in Arduino
▪ Pin Change Interrupts:
▪ Arduinos can have more interrupt pins enabled by using pin change
interrupts.

▪ In ATmega168/328 based Arduino boards any pins or all the 20 signal


pins can be used as interrupt pins.

▪ They can also be triggered using RISING or FALLING edges.


Using Interrupts in Arduino
▪ Interrupt Service Routine or an Interrupt handler is an event that has small
set of instructions in it.
▪ When an external interrupt occurs, the processor first executes these code
that is present in ISR and returns back to state where it left the normal
execution.
▪ ISR has following syntax in Arduino:

Using Interrupts in Arduino
▪ digitalPinToInterrupt(pin):
▪ In Arduino Uno, NANO the pins used for interrupt are 2,3 & in mega
2,3,18,19,20,21. Specify the input pin that is used for external interrupt here.

▪ ISR:
▪ It is a function that is called when an external interrupt is done.

▪ Mode: Type of transition to trigger on, e.g. falling, rising, etc.


▪ RISING: To trigger an interrupt when the pin transits from LOW to HIGH.
▪ FALLING: To trigger an interrupt when the pin transits from HIGH to LOW.
▪ CHANGE: To trigger an interrupt when the pin transits from LOW to HIGH or HIGH to
LOW (i.e., when the pin state changes ).
Some conditions while using interrupt
▪ Interrupt Service Routine function (ISR) must be as short as possible.
▪ Delay () function doesn’t work inside ISR and should be avoided.
Example
Example
Arduino String Functions
charAt() compareTo() concat()
endsWith() equals() equalsignoreCase()
indexof() lastindexof() length()
remove() replace() setCharAt()
startsWith() substring() toLowerCase()
toUpperCase() trim()
charAt()
▪ Access a particular character of the String.
compareTo()
▪ Compares two Strings, testing whether one comes before or after
the other, or whether they’re equal.
▪ The strings are compared character by character, according to
ASCII values of the characters.
concat()
▪ myString.concat(parameter): Appends the parameter to a String.
▪ Returns: true (1) or false (0) (can be store in int or boolean)
endsWith()
▪ myString.endsWith(myString2): Checks if myString ends with the
characters of myString2. This function is case sensitive.

▪ Returns: true (1) or false (0)


▪ 1: if myString ends with the characters of myString2
▪ 0: if myString doesn’t ends with the characters of myString2
equals()
▪ myString.equals(myString2): Compares two Strings for equality. The
comparison is case-sensitive, meaning the String “apple” is not
equal to the String “APPLE”

▪ You can also use operators like == and != to check if string equals
to or not equals to
▪ Returns: true (1) or false (0)

▪ 1: if myString equals (exact match) myString2


▪ 0: if myString doesn’t match
equalsIgnoreCase()
▪ myString.equalsIgnoreCase(myString2): Compares two Strings for
equality. The comparison is not case-sensitive, meaning the String
“apple” is equal to the String “APPLE”

▪ Returns: true (1) or false (0)

▪ 1: if myString equals myString2 (not case sensitive)


▪ 0: if myString doesn’t match
indexOf()
▪ myString.indexOf(val): Locates a character or String within another
String. By default, searches from the beginning of the String, but
can also start from a given index, using myString.indexOf(val, from)

▪ Returns: The index of val within the String, or -1 if not found.


length()
▪ myString.length(): Returns length of String (number of
characters present)

▪ Returns: Integer
remove()
▪ myString.remove(index): Remove charaters of a String from index to
end

▪ myString.remove(index, n): Remove n number of charaters of a String


from the index

▪ Returns: Nothing
ESP8266 - Node MCU
Low Cost Alternative for IoT
ESPRESSIF Modules
▪ ESP8266 WiFi Module is a self contained SOC with integrated
TCP/IP protocol stack.
▪ ESP8266 is capable of either hosting an application or offloading all
WiFi networking functions from another application processor.
▪ ESP8266 comes packed with a powerful controller; no external
controller interfacing is required.
▪ ESPRESSIF provides various version of ESP modules of which
ESP12 module is very popular.
▪ Low cost chip with small PCB area and power efficiency.
Key Features of ESP8266
▪ CPU
▪ Tensilica L106 32-bit MCU
▪ Clock: 80MHz (max. 160MHz)
▪ 4MB Flash Memory
▪ 96KB data RAM; available to user less than 45KB
▪ RTOS Enabled (Supports FreeRTOS)
▪ WiFi
▪ Supports 802.11b/g/n protocol
▪ Access Point or Station
▪ WEP
▪ GPIO, UART, ADC, I2C, SPI, PWM
Different version of ESP8266
Advantages of ESP8266
▪ Integrated TCP/IP protocol stack
▪ Integrated low power 32-bit CPU could be used as application processor
▪ Wake up and transmit packets in < 2ms
▪ Standby power consumption of < 1.0mW
▪ Operates at a low voltage range: 1.8 to 3.6 V
▪ Supports three different power save modes:
1. Modem sleep: WiFi modem is shut off; CPU works; Maintains WiFi connection
without data transmission
2. Light sleep: Suspended CPU; WiFi modem turned off
3. Deep sleep: Does not maintain WiFi connection; long time lags between data
transmission
NodeMCU Pin Diagram
Software Development Using Arduino IDE

▪ There are two ways to program it, using AT commands (requires


external controller) and directly flashing.

Installing ESP8266 board in Arduino IDE

● Installation procedure for adding ESP8266 board in arduino IDE is


very simple with latest versions of Arduino IDE. Follow these steps.
Step 1: Open Arduino IDE
Go to File >> Preferences
Add additional board manager URLs:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Step 2: Open Board Manager
▪ Go to Tools >> Board >> Board Manager
Step 3: Install ESP8266 Board
Lab-6 Ultrasonic Sensor Interfacing

● Ultrasonic Module HC-SR04 works on the principle


of SONAR and RADAR system. It can be used to
determine the distance of an object in the range of
2 cm – 400 cm.
● The module has only 4 pins,
a. VCC
b. GND
c. Trig
d. Echo
Working of HC-SR04
▪ The HC-SR04 emits ultrasonic waves at 40,000 Hz. In order to make
it emit waves, we need to give a 10 microseconds HIGH pulse at the
Trigger pin.

▪ The module responds by emitting a sonic burst of 8 pulses. This


8-pulse pattern helps differentiate the pulses emitted by the module
from the ambient noise.

▪ As soon as the pulses are transmitted, the ECHO pin goes HIGH,
and stays HIGH till all the reflected pulses are received. The module
times out after 38ms, if all the reflected pulses are not received in this
duration.
Timing Diagram

Distance = (Time x SpeedOfSound) / 2.


Code
Code
Code
Access Point
▪ An access point is a device that creates a wireless local area network,
or WLAN, usually in an office or large building.

▪ An access point connects to a wired router, switch, or hub via an


Ethernet cable, and projects a Wi-Fi signal to a designated area.

▪ ESP8266 Wi-Fi Access point is mainly used for configuration purpose


such as SSID and Password.
Node MCU as an access point
▪ The Wi-Fi network established by the soft-AP will be identified with the
SSID (Service Set IDentifier) set during configuration.

▪ The network may be protected with a password. The network may be


also open, if no password is set during configuration.

Wi-Fi Modes
▪ Devices that connect to Wi-Fi network are called stations (STA).
Connection to Wi-Fi is provided by an access point (AP), which acts
as a hub for one or more stations.
Node MCU as an access point
▪ ESP8266 module can operate as a station, so we can connect it to
the Wi-Fi network. It can also operate as a soft access point (softAP),
to establish its own Wi-Fi network.
▪ Therefore we can connect other stations to such ESP module.
ESP8266 is also able to operate both in station and soft access point
mode.
Node MCU as an access point
▪ Password Protected Network
▪ WiFi.softAP(ssid, password); //With Password
▪ Open Network
▪ WiFi.softAP(ssid); //No password
Node MCU as an access point
Connecting NodeMCU to Access Point
▪ The Wi-Fi network is identified with the SSID and Password. Network
may be protected with a password.
▪ Connect to Password Protected Network
▪ WiFi.begin(ssid, password); //With Password
▪ Connect to Open Network
▪ WiFi.begin(ssid); //No password
Connecting NodeMCU to Access Point
Connecting NodeMCU to Access Point
Wi-Fi Network Scan
▪ ESP8266 NodeMCU Wi-Fi Scanner allows you to easily locate visible
wireless networks and its corresponding information.

▪ This program obtains the network name (SSID), signal strength


(RSSI) and MAC Address, security. Wi-Fi scanner can only start when
NodeMCU is not connected to any network.
Wi-Fi Network Scan
Wi-Fi Network Scan
Wi-Fi Network Scan
Static IP
▪ Static IP is required in IoT based network because we identify devices
based on their IP addresses.
▪ Configuring ESP to use Static IP address
▪ WiFi.config(staticIP, subnet, gateway, dns)
Static IP
Static IP
Static IP
Static IP
Raspberry PI
Introduction
▪ Raspberry Pi is a small single board computer. By connecting peripherals
like Keyboard, mouse, display to the Raspberry Pi, it will act as a mini
personal computer.
▪ Raspberry Pi is popularly used for real time Image/Video Processing, IoT
based applications and Robotics applications.
Raspberry pi 3
Raspberry Pi zero
Raspberry pi 4
GPIO Pins
RPi.GPIO

▪ RPi.GPIO, is a Python module to control the GPIO interface on the


Raspberry Pi.

▪ It was developed by Ben Croston and released under an MIT free


software license.

▪ The RPi.GPIO module is installed by default on recent versions of


Raspbian Linux. To use the module from Python programs, first import
it using:
import RPi.GPIO as GPIO

▪ This way you can refer to all functions in the module using the shorter
name "GPIO".

▪ RPi.GPIO supports referring to GPIO pins using either the physical pin
numbers on the GPIO connector or using the BCM channel names from
the Broadcom SOC that the pins are connected to.

▪ For example, pin 24 is BCM channel GPIO8.


GPIO.setmode()

GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BCM)

● GPIO BOARD– This type of pin ● GPIO BCM– The BCM option
numbering refers to the number refers to the pin by “Broadcom
of the pin in the plug. SOC Channel. They signify the
Broadcom SOC channel
● The advantage of this type of designation.
numbering is, it will not change
even though the version of board ● The BCM channel changes as the
changes. version number changes.
GPIO.setup()

▪ GPIO.setup(channel, GPIO.IN)

▪ GPIO.setup(channel, GPIO.OUT)

▪ Where channel is the channel number based on the numbering system


you specified when you called setmode.
GPIO.input(channel) / GPIO.output(channel, state)

▪ GPIO.input(channel)
▪ Where channel is the channel number as used in setup. It will return a
value of 0, or False (all are equivalent) if it is low and 1, or True if it was at
a high level.
▪ GPIO.output(channel, state)
▪ where channel is the channel number and state is the desired output level:
GPIO.LOW for a low value or GPIO.HIGH for a high level.
▪ GPIO.cleanup()
▪ When you are done with the library, it is good practice to free up any
resources used and return all channels back to the safe default of being
inputs.
Example
import RPi.GPIO as GPIO
import time
led = 18
switch = 31
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led, GPIO.OUT)
GPIO.setup(switch, GPIO.IN)
for i in range(10):
GPIO.output(led, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(led, GPIO.LOW)
time.sleep(0.2)
print('Switch status = ', GPIO.input(switch))
GPIO.cleanup()
WHAT IS CLOUD COMPUTING?

● Shared pool of configurable computing resources (Internet infrastructure called a


platform).

● On-demand network access (Using the Internet for communication and transport provides
hardware, software and networking services) Provisioned by the Service Provider
BASIC CLOUD CHARACTERISTICS

▪ Cloud are transparent to users and applications, they can be built in multiple
ways branded products, proprietary open source, hardware or software, or just
off-the-shelf PCs.
▪ In general, they are built on clusters of PC servers and off-the-shelf
components plus Open Source software combined with in-house applications
and/or system software.

▪ Clients can:
▪ Put their data on the platform instead of on their own desktop PCs and/or on
their own servers.
▪ They can put their applications on the cloud and use the servers within the
cloud to do processing and data manipulations etc.
Convergence Approaches of IoT and Cloud

▪ Cloud-centric IoT (Bring IoT functionalities in Cloud)

▪ IoT-Centric Cloud (Bring Cloud functionalities in IoT)

Cloud-centric IoT
● Bring IoT data in the cloud

● Processing and computing the data and deploy management tools in cloud

● This approach this good if service are provided among objects located in multiple
location
CLOUD-CENTRIC IOT PLATFORM
IOT-CENTRIC CLOUD COMPUTING

▪ IoT infrastructure will provide the opportunities to take services,


workloads, applications and large amounts of data and deliver it all to
the network.
▪ Processing and storage of data close to users/near to sources support
mobile computing and data streaming
▪ Creating dense geographical distribution
▪ This approach are useful when data coming from same location
Supporting end-users security
▪ Data process and service execute locally
CLOUD ARCHITECTURE
ADVANTAGES OF CLOUD COMPUTING

▪ Lower computer and software costs:


▪ You do not need a high-powered and high-priced computer to run
cloud computing's web-based applications.
▪ Improved performance:
▪ Computers in a cloud computing system boot and run faster
because they have fewer programs.
▪ Instant software updates
▪ Unlimited storage capacity
▪ Increased data reliability
▪ Universal document access
▪ Latest version availability
DISADVANTAGES OF CLOUD COMPUTING

▪ Requires a constant Internet connection.


▪ Stored data might not be secure.
▪ Stored data can be lost.
▪ Does not work well with low-speed connections
▪ Can be slow:
▪ Everything about the program, from the interface to the current
document, has to be sent back and forth from your computer to the
computers in the cloud.

You might also like