You are on page 1of 32

Enrollment No.

:- 202003103520101

Practical – 1
Aim:-To study introduction to internet of things, general IoT architecture. To
study internet of things and its various protocols like Wi-Fi, IPv4/IPv6,
Bluetooth, ZigBee, 6LowPAN, MQTT, AMQP, DDS, LoRAWAN.

Wi-Fi:
Wi-Fi is a family of wireless network protocols, based on the IEEE 802.11 family of standards,
which are commonly used for local area networking of devices and Internet access, allowing
nearby digital devices to exchange data by radio waves.
Wi-Fi uses multiple parts of the IEEE 802 protocol family and is designed to interwork
seamlessly with its wired sibling, Ethernet. Compatible devices can network through wireless
access points to each other as well as to wired devices and the Internet. The different versions of
Wi-Fi are specified by various IEEE 802.11 protocol standards, with the different radio
technologies determining radio bands, and the maximum ranges, and speeds that may be
achieved. Wi-Fi most commonly uses the 2.4 gigahertz (120 mm) UHF and 5 gigahertz (60 mm)
SHF radio bands; these bands are subdivided into multiple channels. Channels can be shared
between networks but, within range, only one transmitter can transmit on a channel at a time.

IPv4/IPv6:
The Internet Protocol (IP) is one of the most important communication protocols in the Internet
Protocol Suite, which is used for routing and addressing packets for networking devices such as
computers, laptops and fiber switches across a single network or a series of interconnected
networks. There are currently two versions of Internet Protocol: IPv4 (IP version 4) and IPv6 (IP
version 6).
IPv4 is the fourth version of IP, which establishes the rules for computer networks functioning
on the principle of packet exchange. It can uniquely identify devices connected to the network
through an addressing system. Whenever a device gets access to the Internet, it is assigned a
unique, numerical IP address. The IPv4 uses a 32-bit address scheme allowing to store 2^32
addresses. The increasing end-users connected to the Internet leads to the exhaustion of IPv4
addresses. That’s also why the new Internet addressing system, IPv6, is being deployed to fulfill
the need for more Internet addresses.
IPv6 was deployed in 1999 concerning that the demand for IP addresses would exceed the
available supply. It allows communication and data transfer to take place over a network. IPv6 is
a 128-bit IP address which supports 2^128 Internet addresses in total. The use of IPv6 not only
solves the problem of limited network addresses resources but also resolves the barriers for
multiple access devices to connect to the Internet.

CGPIT/CE/SEM-7/INTERNET OF THINGS    1 
 
Enrollment No.:- 202003103520101

Bluetooth:
Bluetooth is a short-range wireless technology standard that is used for exchanging data between
fixed and mobile devices over short distances and building personal area networks (PANs). It
employs UHF radio waves in the ISM bands, from 2.402 GHz to 2.48 GHz. It is mainly used as
an alternative to wire connections, to exchange files between nearby portable devices and
connect cell phones and music players with wireless headphones. In the most widely used mode,
transmission power is limited to 2.5 milliwatts, giving it a very short range of up to 10 meters.

ZigBee:
Zigbee is an IEEE 802.15.4-based specification for a suite of high-level communication
protocols used to create personal area networks with small, low-power digital radios, such as for
home automation, medical device data collection, and other low-power low-bandwidth needs,
designed for small scale projects which need wireless connection. Hence, Zigbee is a low-power,
low data rate, and close proximity wireless ad hoc network.
Its low power consumption limits transmission distances to 10–100 meters line-of-sight,
depending on power output and environmental characteristics.[1] Zigbee devices can transmit
data over long distances by passing data through a mesh network of intermediate devices to
reach more distant ones. Zigbee is typically used in low data rate applications that require long
battery life and secure networking. Zigbee has a defined rate of 250 kbit/s, best suited for
intermittent data transmissions from a sensor or input device.

6LowPAN:
6LoWPAN (acronym of "IPv6 over Low-Power Wireless Personal Area Networks") was a
working group of the Internet Engineering Task Force (IETF). It was created with the intention
of applying the Internet Protocol (IP) even to the smallest devices, enabling low-power devices
with limited processing capabilities to participate in the Internet of Things.
The 6LoWPAN group defined encapsulation, header compression, neighbor discovery and other
mechanisms that allow IPv6 to operate over IEEE 802.15.4 based networks. Although IPv4 and
IPv6 protocols do not generally care about the physical and MAC layers they operate over, the
low power devices and small packet size defined by IEEE 802.15.4 make it desirable to adapt to
these layers.

MQTT:
MQTT stands for Message Queuing Telemetry Transport. MQTT is a machine to machine
internet of things connectivity protocol. It is an extremely lightweight and publish-subscribe
messaging transport protocol.

CGPIT/CE/SEM-7/INTERNET OF THINGS    2 
 
Enrollment No.:- 202003103520101

This protocol is useful for the connection with the remote location where the bandwidth is a
premium. These characteristics make it useful in various situations, including constant
environment such as for communication machine to machine and internet of things contexts. It is
publish and subscribe system where we can publish and receive the messages as a client. It
makes it easy for communication between multiple devices.
It is a simple messaging protocol designed for the constrained devices and with low bandwidth,
so it's a perfect solution for the internet of things applications.

AMQP:
The Advanced Message Queuing Protocol (AMQP) is an open standard application layer
protocol for message-oriented middleware. The defining features of AMQP are message
orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and
security.
AMQP mandates the behavior of the messaging provider and client to the extent that
implementations from different vendors are interoperable, in the same way as SMTP, HTTP,
FTP, etc. have created interoperable systems. Previous standardizations of middleware have
happened at the API level and were focused on standardizing programmer interaction with
different middleware implementations, rather than on providing interoperability between
multiple implementations. Unlike JMS, which defines an API and a set of behaviors that a
messaging implementation must provide, AMQP is a wire-level protocol. A wire-level protocol
is a description of the format of the data that is sent across the network as a stream of bytes.
Consequently, any tool that can create and interpret messages that conform to this data format
can interoperate with any other compliant tool irrespective of implementation language.

DDS:
Data Distribution Service (DDS) enables scalable, real-time, reliable, excessive-overall
performance and interoperable statistics change via submit-subscribe technique. DDS makes use
of brokerless architecture and of multicasting to convey high-quality QoS to applications. DDS
can deploy in platforms ranging from low-footprint devices to the cloud and supports green
bandwidth usage in addition to the agile orchestration of system additives.
The DDS — IoT protocols have fundamental layers: facts centric submit-subscribe (dcps) and
statistics-local reconstruction layer (dlrl). Dcps plays the task of handing over the facts to
subscribers, and the dlrl layer presents an interface to dcps functionalities, permitting the sharing
of distributed data amongst IoT enabled objects.

CGPIT/CE/SEM-7/INTERNET OF THINGS    3 
 
Enrollment No.:- 202003103520101

LoRAWAN:
LoRaWAN is a low-power, wide area networking protocol built on top of the LoRa radio
modulation technique. It wirelessly connects devices to the internet and manages communication
between end-node devices and network gateways. Usage of LoRaWAN in industrial spaces and
smart cities is growing because it is an affordable long-range, bi-directional communication
protocol with very low power consumption — devices can run for ten years on a small battery. It
uses the unlicensed ISM (Industrial, Scientific, Medical) radio bands for network deployments.
An end device can connect to a network with LoRaWAN in two ways:

 Over-the-air Activation (OTAA): A device has to establish a network key and an


application session key to connect with the network.
 Activation by Personalization (ABP): A device is hardcoded with keys needed to
communicate with the network, making for a less secure but easier connection.

CGPIT/CE/SEM-7/INTERNET OF THINGS    4 
 
Enrollment No.:- 202003103520101

Practical – 2
Aim:- To study Arduino UNO development board with pin specification and
perform the following programs on Arduino boards.
a) To develop an application of blinking LED using Arduino. (Simulator
Tinker cad)
Components:-
 Arduino UNO
 LED

Code:-
void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    5 
 
Enrollment No.:- 202003103520101

Circuit:-

b) To develop an application of Traffic signal with LED's using Arduino Uno.


(Simulator Tinker cad)
Components:-
 Arduino UNO
 LEDs
 Resistor

Code:-
void setup()
{
pinMode(13, OUTPUT);

CGPIT/CE/SEM-7/INTERNET OF THINGS    6 
 
Enrollment No.:- 202003103520101

pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);

digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);

digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    7 
 
Enrollment No.:- 202003103520101

Circuit:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    8 
 
Enrollment No.:- 202003103520101

Practical – 3
Aim:- Perform the following programs on Arduino boards.
a) To develop an application that measures the temperature of a room.
(Simulator Tinker cad)
Components:-
 Arduino UNO
 Temperature sensor

Code:-
float temp;
int tempPin = A0;

void setup() {
Serial.begin(9600);
pinMode(tempPin,INPUT);
}

void loop() {
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.print("TEMPERATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    9 
 
Enrollment No.:- 202003103520101

Circuit:-

b) To develop an application that measures water level. (Simulator Tinker


cad)
Components:-
 Arduino UNO
 Water level sensor

Code:-
int lowerThreshold = 420;
int upperThreshold = 520;

// Sensor pins
#define sensorPower 7
#define sensorPin A0

// Value for storing water level


int val = 0;

CGPIT/CE/SEM-7/INTERNET OF THINGS    10 


 
Enrollment No.:- 202003103520101

void setup() {
Serial.begin(9600);
pinMode(sensorPower, OUTPUT);
digitalWrite(sensorPower, LOW);
}

void loop() {
int level = readSensor();

if (level == 0) {
Serial.println("Water Level: Empty");
}
else if (level > 0 && level <= lowerThreshold) {
Serial.println("Water Level: Low");
}
else if (level > lowerThreshold && level <= upperThreshold) {
Serial.println("Water Level: Medium");

}
else if (level > upperThreshold) {
Serial.println("Water Level: High");
}
delay(1000);
}

//This is a function used to get the reading


int readSensor() {

CGPIT/CE/SEM-7/INTERNET OF THINGS    11 


 
Enrollment No.:- 202003103520101

digitalWrite(sensorPower, HIGH);
delay(10);
val = analogRead(sensorPin);
digitalWrite(sensorPower, LOW);
return val;
}

Circuit:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    12 


 
Enrollment No.:- 202003103520101

Practical – 4
Aim:- Perform the following programs on Arduino boards
a) Blinking LED using Arduino Uno
Components:-
 Arduino UNO
 LED

Code:-
void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    13 


 
Enrollment No.:- 202003103520101

Circuit:-

b) Traffic signal with LED's using Ardiuno Uno


Components:-
 Arduino UNO
 LEDs
 Bread board

Code:-
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

CGPIT/CE/SEM-7/INTERNET OF THINGS    14 


 
Enrollment No.:- 202003103520101

void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);

digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);

digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    15 


 
Enrollment No.:- 202003103520101

Circuit:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    16 


 
Enrollment No.:- 202003103520101

c) Measures temperature of a room using Ardiuno Uno


Components:-
 Arduino UNO
 Temperature sensor

Code:-
float temp;
int tempPin = A0;

void setup() {
Serial.begin(9600);
pinMode(tempPin,INPUT);
}

void loop() {
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.print("TEMPERATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    17 


 
Enrollment No.:- 202003103520101

Circuit:-

Output:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    18 


 
Enrollment No.:- 202003103520101

d) Measure water level using Ardiuno Uno


Components:-
 Arduino UNO
 Water level sensor

Code:-
int lowerThreshold = 420;
int upperThreshold = 520;

// Sensor pins
#define sensorPower 7
#define sensorPin A0

// Value for storing water level


int val = 0;

void setup() {
Serial.begin(9600);
pinMode(sensorPower, OUTPUT);
digitalWrite(sensorPower, LOW);
}

void loop() {
int level = readSensor();

if (level == 0) {
Serial.println("Water Level: Empty");
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    19 


 
Enrollment No.:- 202003103520101

else if (level > 0 && level <= lowerThreshold) {


Serial.println("Water Level: Low");
}
else if (level > lowerThreshold && level <= upperThreshold) {
Serial.println("Water Level: Medium");

}
else if (level > upperThreshold) {
Serial.println("Water Level: High");
}
delay(1000);
}

//This is a function used to get the reading


int readSensor() {
digitalWrite(sensorPower, HIGH);
delay(10);
val = analogRead(sensorPin);
digitalWrite(sensorPower, LOW);
return val;
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    20 


 
Enrollment No.:- 202003103520101

Circuit:-

Output:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    21 


 
Enrollment No.:- 202003103520101

Practical – 5
Aim:- To develop an application which sense motion of an object using
Arduino and display appropriate message on LCD display.
Components:-
 Arduino UNO
 16x2 LCD display
 Bread board

Code:-
#include "LiquidCrystal.h"
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(" Hello");
lcd.setCursor(0,1);
lcd.print(" World");
}
void loop(){}

Circuit:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    22 


 
Enrollment No.:- 202003103520101

Practical – 6
Aim:- To study NodeMCU development board with pin specification and
develop an application to send and receive data with NodeMCU using HTTP
request. (LED ON/OFF application)
Components:-
 NodeMCU
 LED
 Bread board

Code:-
#include <ESP8266WiFi.h>
#define LED D2 // LED at GPIO4 D2

const char* ssid = "ram"; //enter your wi-fi name


const char* password = "meet2602"; //enter the wifi password
unsigned char status_led=0;

WiFiServer server(80);

void setup() {

Serial.begin(115200);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);

// Connect to WiFi network


Serial.println();
Serial.println();

CGPIT/CE/SEM-7/INTERNET OF THINGS    23 


 
Enrollment No.:- 202003103520101

Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");

// Start the server


server.begin();
Serial.println("Server started at...");
Serial.println(WiFi.localIP());
}

void loop() {

// Check if a client has connected


WiFiClient client = server.available();
if (!client) {
return;
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    24 


 
Enrollment No.:- 202003103520101

// Wait until the client sends some data


Serial.println("new client");
while (! client.available())
{
delay (1);
}

// Read the first line of the request


String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();

// Match the request


if (req.indexOf("/ledoff") != -1) {
status_led=0;
digitalWrite(LED, LOW);
Serial.println("LED OFF");
}
else if(req.indexOf("/ledon") != -1)
{
status_led=1;
digitalWrite(LED,HIGH);
Serial.println("LED ON");
}

// Return the response


client.println("HTTP/1.1 200 OK");

CGPIT/CE/SEM-7/INTERNET OF THINGS    25 


 
Enrollment No.:- 202003103520101

client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("");

client.println("<!DOCTYPE HTML>");
client.println("<HTML>");
client.println("<H1> LED CONTROL </H1>");
client.println("<br />");

client.println("<a href=\"/ledon\"\"> <button style='FONT-SIZE: 50px; HEIGHT:


200px;WIDTH: 300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED ON </button> </a>");
client.println("<a href=\"/ledoff\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px;
WIDTH: 300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED OFF </button> </a>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}

Circuit:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    26 


 
Enrollment No.:- 202003103520101

Output:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    27 


 
Enrollment No.:- 202003103520101

Practical – 7
Aim:- To develop an application that measures the room temperature and
post the temperature to Thingspeak platform.
Components:-
 NodeMCU
 Temperature sensor
 Bread board

Code:-
#include <ESP8266WiFi.h>
const char* ssid = "ram";
const char* password = "meet2602";
int LM35 = A0; //Analog channel A0 as used to measure temperature
WiFiServer server(80);

void setup()
{
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    28 


 
Enrollment No.:- 202003103520101

Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.print("Use this URL to connect: ");
Serial.print("http://"); //URL IP to be typed in mobile/desktop browser
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop()
{
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("new client");
while (!client.available()) {
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

float temperatureC;
float temperatureF;
int value = LOW;
if (request.indexOf("/Tem=ON") != -1) {

CGPIT/CE/SEM-7/INTERNET OF THINGS    29 


 
Enrollment No.:- 202003103520101

float reading = analogRead(LM35); //Analog pin reading output voltage by Lm35


float temperatureC = LM35 / 3.1; //Finding the true centigrate/celsius temperature
Serial.println("CENTI TEMP= ");
Serial.print(temperatureC); //Print centigrade temperature on Serial Monitor
float temperatureF = ((temperatureC ) * 9.0 / 5.0) + 32.0;
Serial.println("FARE TEMP= ");
Serial.print(temperatureF); //Print farenheight temperature on Serial Monitor

value = HIGH;
}

client.println("HTTP/1.1 200 OK");


client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");

client.print("Celcius temperature =");


client.print(temperatureC);
client.println("Farenheight temperature =");
client.print(temperatureF);

if (value == HIGH) {
client.println("Updated");
} else {
client.print("Not Updated");
}

CGPIT/CE/SEM-7/INTERNET OF THINGS    30 


 
Enrollment No.:- 202003103520101

client.println("<br><br>");
client.println("<a href=\"/Tem=ON\"\"><button>Update Temperature</button></a><br
/>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");

Circuit:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    31 


 
Enrollment No.:- 202003103520101

Output:-

CGPIT/CE/SEM-7/INTERNET OF THINGS    32 


 

You might also like