UNIT2
UNIT2
UNIT2
Machine-to-Machine Communications 1
Difference between IoT and M2M 4
Interoperability in IoT 8
Types of interoperability 8
HandlingApproaches
Interoperability as per NPTEL(syllabus) 18
Introduction to Arduino Programming 27
Aurdino Board 29
Built in Functions 33
Program for Blinking LED 45
Traffic system 47
Integration of Sensors and Actuators with Arduino
Sensors with Aurdino 50
Actuators with Aurdino 53
1
UNIT-2
Machine to Machine :
This is commonly known as Machine to machine communication. It is a concept
where two or more than two machines communicate with each other without
human interaction using a wired or wireless mechanism. M2M is an technology
that helps the devices to connect between devices without using internet.
Internet of Things :
IOT is known as the Internet of Things where things are said to
be the communicating devices that can interact with each other using a
communication media. Usually every day some new devices are being
integrated which uses IoT devices for its function. These devices use various
sensors and actuators for sending and receiving data over the internet. It is an
ecosystem where the devices share data through a communication media
known as the internet.
Machine-to-Machine (M2M)
• Machine-to-Machine (M2M) refers to networking of machines (or devices) for
the purpose of remote monitoring and control and data exchange.
2
Machine-to-Machine (M2M)
• An M2M area network comprises of machines (or M2M nodes) which have
embedded hardware modules for sensing, actuation and communication.
• Various communication protocols can be used for M2M local area
networks such as ZigBee, Bluetooh, ModBus, M-Bus, Wirless M-Bus, Power
Line Communication (PLC), 6LoWPAN, IEEE 802.15.4, etc.
• The communication network provides connectivity to remote M2M area
networks.
• The communication network can use either wired or wireless networks
(IPbased).
• M2M area networks use either proprietary or non-IP based
communication protocols, the communication network uses IP-based networks
M2M gateway
• Since non-IP based protocols are used within M2M area networks, the
M2M nodes within one network cannot communicate with nodes in an
external network.
• To enable the communication between remote M2M area networks,
M2M gateways are used.
3
DIFFERENCE BETWEEN IOT AND M2M
Communication Protocols
M2M and IoT can differ in how the communication between the
machines or devices happens. M2M uses either proprietary or non-IP based
communication protocols for communication within the M2M area networks.
Commonly uses m2m protocols include Zigbee, bluetooth, Modbus, M-Bus,
wireless M-bus, Power line communication, 6lowpan, IEEE 802.15.4, Z-
wave etc. The focus of communication in M2M is usually on the protocols below
the network layer. The focus of communication in IoT is usually on the protocols
above above the network layer such as HTTP, COAP, Websockets, MQTT,
XMPP, DDS, AMQP etc.
4
Machines in M2M vs things in IoT
The things in IoT refers to physical objects that have unique identifiers
and can sense and communicate with their external environment (and user
applications) or their internal physical States. The unique identifier for the things in
IoT are the IP addresses (or Mac addresses). Things have software components for
accessing, processing and storing sensor information, or controlling actuators
connected. IoT systems can have heterogeneous thing ( e.g., home automation IoT
system can include IoT system can include IoT devices of various types such as
fire alarms, door alarms, lighting control devices etc) M2M systems, in contrast
to IoT, typically have have homogeneous machine type within a and M2M
area network.
5
Hardware vs Software Emphasis
While the emphasis of M2M is more on hardware with embedded modules, the
emphasis of IoT is more on software. IoT devices run specialized software for
sensor data collection, data analysis and interfacing with the cloud through IP
based communication.
6
applications and on-premises enterprise applications. But We collect IoT Data in
the cloud and can be accessed by cloud applications such as analytics applications,
enterprise applications, remote diagnosis and management applications etc. Since
the scale of data collected in IoT is so massive, cloud based real time and batch
data analysis frameworks are used for data analysis. Communication in IoT is IP
based networks. Communication within M2M area network is based on protocols
below the network layer whereas IoT is based on protocols above the network
layer.
7
Basis of IoT M2M
INTEROPERABILITY IN IOT
Interoperability is defined by IEEE as “the ability of two or more systems or
components to exchange information and to use the information that has been
exchanged.
In IoT interoperability can be defined as the ability of two systems
to communicate and share services with each other
The interoperability issues in IoT can be seen from different perspectives
due to heterogeneity. Heterogeneity is not a new concept nor restricted to a
domain. Even in the physical world there are many types of heterogeneities for
example, people speak dissimilar languages, but they can still communicate with
each other through a translator (human/tools) or by using a common language.
similarly the diverse elements comprising IoT (devices, communication, services,
applications, etc.) should seamlessly cooperate and communicate with each other
to realize the full potential of IoT ecosystem. As shown in figure, IoT
interoperability can be seen from different perspectives such as
device interoperability
networking interoperability
syntactic interoperability
semantic interoperability and
platform interoperability.
8
Device interoperability
IoT is composed of a variety of devices which are called “smart
objects/things”, which may consist of high-end devices or low-end devices.
The high-end IoT devices have enough resources and computational capabilities
such as Raspberry Pi and smartphones. On the other hand, the low-end IoT
devices are resource-constrained in terms of energy, processing power and
communication capabilities , tiny and low-cost sensors, and actuators, Arduino.
9
Network interoperability
semantic interoperability
10
For ex: the data generated by things about the environment may have a
defined data format (e.g. JSON, XML or CSV), but the data models and schemas
used by different sources are usually dissimilar and not always compatible.
Platform interoperability
Platform interoperability issues in IoT arises due to the availability of diverse
operating systems (OSs), programming languages, data structures, architectures
and access mechanisms for things and data.
Developers need to obtain extensive knowledge of the platform specific APIs and
information models of each different platform to be able to adapt their
applications from one platform to another.
Fig. 2.
11
Interoperability handling approaches in IoT
To improve the state of IoT interoperability, researchers have leveraged
numerous approaches and technologies which we refer to interoperability handling
approaches
1.Adapters/gateways
2.Virtual networks/ overlay-based solutions
3.Networking technologies
IP based approaches
Software-defined networking (SDN)
Network function virtualization
Fog computing
4.Service oriented architecture (SOA)
5.Open API
6.Semantic web technologies
7.Open standard
12
Adapters/gateways
Gateways or adapters are the class of schemes which address
interoperability through the development of an intermediate tool sometimes
called mediators to improve interoperability between IoT devices.
13
The advantage of this approach is enabling end-to-end communication between
devices, however the key issues are scalability and binding to specific protocols.
Networking technologies
14
However, an all IP sensor network is not possible on sensor nodes
because of their resource-constraint property.
protocols at the network layer such as Routing Over Low Power and
Lossy Networks (ROLL) ,IPv6 over Low Power WPAN (6LoWPAN), Constrained
Application Protocol (CoAP) which is based on UDP, and Constrained Restful
Environment to solve the connectivity problem of resource-constrained devices. This
approach, still uses gateways to convert between standard protocols used in the
Internet and protocols used in the sensor network, e.g. IPv6 to 6LoWPAN.
One of the main idea of SDN , is to separate the control and data planes in
networking devices
15
SDN is used to allow different objects from different networks to communicate
with each other using IPv6 and at the same time simplify the management and
control operations of various objects types by adding an additional IoT
controller over the SDN controller. Thus, even so the devices have different
protocols, the forwarding devices in the router convert it in a form
understandable by the receiver. This enables the communication of diverse
devices in the network.
NFV has the potential to reduce Operational Expenditure (OPEX) and Capital
Expenditure (CAPEX) costs by sharing the network infrastructure, dynamic
scaling, on-the-fly, and flexible network function deployment
Fog computing
The cloud has been used as a medium to address interoperability called the
Fog of Things where the computing, storage and networking services are
placed at the edge of the network rather than centralized cloud servers, i.e., as
close as possible to the end user devices.
In the SOA of the IoT, the interaction with and operations of different wireless
devices are classified into different service components and the application
layer software can access resources exposed by devices as services. Exposing
each component’s functionalities as a standard service can significantly
increase the interoperability of both network and device.
16
Semantic web technologies
.
Ontology
Device ontology
Physical domain ontology
Estimation ontology
17
Open API
With the massive development of IoT platform providers a vast silo of diverse
APIs has been created that increases the difficulty of developing applications
as well as interoperability issues.
HyperCat is a specification which provides syntactic interoperability between
different APIs and services based on a Catalog that can be tagged with
metadata.
Open standards
18
What is Interoperability?
User Interoperability
Interoperability problem between a user and a device
Device Interoperability
Interoperability problem between two different devices
20
User Interoperability
21
Semantic interoperability for device interaction.
22
executable by the device
Middleware technology
Software middleware bridge
Dynamically map physical devices with different domains
Based on the map, the devices can be
discovered and controlled,remotely
Cross-context syntactic interoperability
Collaborative concept exchange
Using XML syntax
The above methodologies can achieve :
1.The interoperability between devices and device user in termof
message’s meaning
2.The device can understand the meaning of user’s instructionthat is
sent from the user to the device.
3.Similarly, the user can understand the meaning of device’s
response sent from the device
23
Object is defined based on the collaborative
concept, which is calledcosign
The representation of a collaborative sign is defined as follows:
cosign of a object = (A, B, C, D ), where A is a cosign
internal identifier, B isa natural language, C is the
context of A, and D is a definition of the object
As an example of CCTV, cosign = (1234, English,
CCTV, “Camera Type: Bullet, Communication:
Network/IP, Horizontal Resolution: 2048 TVL”)
This solution approach is applicable for different domains/contexts
Device Interoperability
24
Fig 1: The Architecture of Universal Middleware Bridge
25
26
AURDINO
What is Arduino?
Arduino is an open-source electronics platform based on easy-to-use hardware
and software. Arduino boards are able to read inputs - light on a sensor, a finger
on a button, or a Twitter message - and turn it into an output - activating a motor,
turning on an LED, publishing something online. You can tell your board what to
do by sending a set of instructions to the microcontroller on the board. To do so
you use the Arduino programming language (based on Wiring), and the Arduino
Software (IDE), based on Processing.
for example
Designers and architects build interactive prototypes, musicians and artists use it
for installations and to experiment with new musical instruments. Makers, of
course, use it to build many of the projects exhibited at the Maker Faire,
27
people wanting to understand the technical details can make the leap from
Arduino to the AVR C programming language on which it's based.
Similarly, you can add AVR-C code directly into your Arduino programs if
you want to.
Open source and extensible hardware - The plans of the Arduino boards
are published under a Creative Commons license, so experienced circuit
designers can make their own version of the module, extending it and
improving it. Even relatively inexperienced users can build the breadboard
version of the module in order to understand how it works .
28
AURDINO BOARD AND ITS COMPONENTS
Using the above image as a reference, the labeled components of the board
respectively are-
Power USB
Arduino board can be powered by using the USB cable from your computer. All you
need to do is connect the USB cable to the USB connection (1).
29
Power (Barrel Jack)
Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack (2).
Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino
board and stabilize the DC voltages used by the processor and other elements.
Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
calculate time? The answer is, by using the crystal oscillator. The number printed
on top of the Arduino crystal is 16.000H9H. It tells us that the frequency is
16,000,000 Hertz or 16 MHz.
Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning. You
can reset the UNO board in two ways. First, by using the reset button (17) on the
board. Second, you can connect an external reset button to the Arduino pin labelled
RESET (5).
Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can
read the signal from an analog sensor like the humidity sensor or temperature
sensor and convert it into a digital value that can be read by the microprocessor.
30
Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as the
brain of your board. The main IC (integrated circuit) on the Arduino is slightly
different from board to board. The microcontrollers are usually of the ATMEL
Company. You must know what IC your board has before loading up a new
program from the Arduino IDE. This information is available on the top of the IC.
For more details about the IC construction and functions, you can refer to the data
sheet.
ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting
of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI
(Serial Peripheral Interface), which could be considered as an "expansion" of the
output. Actually, you are slaving the output device to the master of the SPI bus.
TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive). They appear
in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate
the pins responsible for serial communication. Second, the TX and RX led (13).
The TX led flashes with different speed while sending the serial data. The speed of
flashing depends on the baud rate used by the board. RX flashes during the
receiving process.
Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse
Width Modulation) output. These pins can be configured to work as input digital
pins to read logic values (0 or 1) or as digital output pins to drive different modules
like LEDs, relays, etc. The pins labeled “~” can be used to generate PWM.
AREF
31
AREF stands for Analog Reference. It is sometimes, used to set an external
reference voltage (between 0 and 5 Volts) as the upper limit for the analog input
pins.
Set Up
1. Power the board by connecting it to a PC via USB cable
3. Set the board type and the port for the board
32
4.The console displays text output by the Arduino Software (IDE), including
complete error messages and other information.
5.The bottom righthand corner of the window displays the configured board
and serial port.
6.The toolbar buttons allow you to verify and upload programs, create, open,
and save sketches, and open the serial monitor.
33
The Arduino Programming Language and
Built-in Functions
Program lifecycle/structure of aurdino program
Structure
Arduino programs can be divided in three main parts: Structure, Values (variables and
constants), and Functions. In this tutorial, we will learn about the Arduino software
program, step by step, and how we can write the program without any syntax or
compilation error.
Let us start with the Structure. Software structure consist of two main functions −
Setup( ) function
Loop( ) function
Void setup ( ) {
}
PURPOSE − The setup() function is called when a sketch starts. Use it to initialize
the variables, pin modes, start using libraries, etc. The setup function will only run
once, after each power up or reset of the Arduino board.
INPUT − -
OUTPUT − -
RETURN − -
34
Void Loop ( ) {
}
PURPOSE − 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.
INPUT − -
OUTPUT − -
RETURN − -
setup() this function is called once, when the program starts, and
when the Arduino is shut down and restarted.
loop() this function is repeatedly called while the Arduino program
is running.
Handling I/O
The following functions help with handling input and output from
your Arduino device.
1.Digital I/O
35
pinMode() sets a pin to be an input, or an output. You pass the
pin number and the INPUT or OUTPUT value as parameters.
36
noTone() stops the tone() generated wave on a pin.
2.Analog I/O
analogRead() reads the value from an analog pin.
analogReference() configures the value used for the top input
range in the analog input, by default 5V in 5V boards and 3.3V in 3.3V
boards.
analogWrite() writes an analog value to a pin
analogReadResolution() lets you change the default analog bits
resolution for analogRead(), by default 10 bits. Only works on
specific devices (Arduino Due, Zero and MKR)
analogWriteResolution() lets you change the default analog
bits resolution for analogWrite(), by default 10 bits. Only works on
specific devices (Arduino Due, Zero and MKR)
Time functions
delay() pauses the program for a number of milliseconds specified
as parameter
Delay() function is one of the most common
time manipulation function usedto provide a
delay of specified time. It accepts integer value
(time in miliseconds)
37
millis() the number of milliseconds since the start of the program.
Resets after ~50 days due to overflow
Math functions
abs() the absolute value of a number
constrain() constrains a number to be within a range, see usage
map() re-maps a number from one range to another, see usage
max() the maximum of two numbers
min() the minimum of two numbers
pow() the value of a number raised to a power
sq() the square of a number
sqrt() the square root of a number
cos() the cosine of an angle
sin() the sine of an angle
tan() the tangent of an angle
Note: there are more built-in mathematical functions if you need
them, documented here.
38
isHexadecimalDigit() checks if a char is an hexadecimal digit (A-
F 0-9)
isLowerCase() checks if a char is a letter in lower case
isPrintable() checks if a char is a printable ASCII character
isPunct() checks if a char is a punctuation (a comma, a semicolon,
an exclamation mark etc)
isSpace() checks if a char is a space, form feed \f, newline \n,
carriage return \r, horizontal tab \t, or vertical tab \v.
isUpperCase() checks if a char is a letter in upper case
isWhitespace() checks if a char is a space character or an
horizontal tab \t
Data types :
Data types refers to an extensive system used for declaring
variables or functions of different types. The type of a variable determines how much space it
occupies in the storage and how the bit pattern stored is interpreted.
39
Operators : An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions
Control statement :
40
LOOP
41
42
Random numbers generation
To generate random numbers, you can use Arduino random number functions. We have
two functions −
randomSeed(seed)
random()
43
Working with bits and bytes
bit() computes the value of a bit (0 = 1, 1 = 2, 2 = 4, 3 = 8…)
bitClear() clear (sets to 0) a bit of a numeric variable. Accepts a
number, and the number of the bit starting from the right
bitRead() read a bit of a number. Accepts a number, and the
number of the bit starting from the right
bitSet() sets to 1 a bit of a number. Accepts a number, and the
number of the bit starting from the right
bitWrite() write 1 or 0 to a specific bit of a number Accepts a
number, the number of the bit starting from the right, and the value to
write (0 or 1)
highByte() get the high-order (leftmost) byte of a word variable
(which has 2 bytes)
lowByte() get the low-order (rightmost) byte of a word variable
(which has 2 bytes)
Interrupts
Interrupts stop the current work of Arduino such that some other work can be done.
44
PROGRAMS WITH AURDINO
1.
45
46
2
47
48
49
INTEGRATING SENSORS AND ACTUATORS WITH
AURDINO
Sensors
Temperature
Humidity
Compass
Light
Sound
Accelerometer
Sensor Interface with Arduino
50
DHT Sensor Library
Arduino supports a special library for the DHT11 and DHT22 sensors
Provides function to read the temperature and humidity values from
the data pin
dht.readHumidity()
dht.readTemperature()
Connection
Connect pin 1 of the DHT to the 3.3 V supply pin in the board
Data pin (pin 2) can be connected to any digital pin, here 12
Connect pin 4 to the ground (GND) pin of the board
Sketch: DHT_Sensor
51
Connect the board to the PC
Set the port and board type
Verify and upload the cod
OutPut
The readings are printed at a delay of 2 seconds as specified by the delay() function
52
Acutators
Types of Motor acutators
1.Servo Motor
2.Stepper Motor
3.Hydraulic Motor
4.Ac motor and so on
Servo Motor :
Servo Motor is a high Precision motor which provides rotary
motion 0 to 180 degree
The 3 wires in the servo motor are
Black or the darkest one is ground Red is power supply and Yellow is for signal pin
Servo Library on Aurdino
Aurdino provides separate library SERVO to operate the servo motor .
Create an instnace of servo to use it in the sketch .
Syntax : Servo myservo
53
Here ServoDemo is the instance of Servo.
Write() takes the degree value and rotates the motor accordingly.
Output :
The motor turns 0, 90 and 180 degrees with a delay of 1 second each.
54
55