Professional Documents
Culture Documents
Practicals IOT
Practicals IOT
Practical -1
LDCE 1|Page
Internet of Things 3160716 190280107010
Board Types
Various kinds of Arduino boards are available depending on different microcontrollers used.
However, all Arduino boards have one thing in common: they are programed through the
Arduino IDE.
The differences are based on the number of inputs and outputs (the number of sensors,
LEDs, and buttons you can use on a single board), speed, operating voltage, form factor etc.
Some boards are designed to be embedded and have no programming interface
(hardware), which you would need to buy separately. Some can run directly from a 3.7V
battery, others need at least 5V.
Here is a list of different Arduino boards available.
LDCE 2|Page
Internet of Things 3160716 190280107010
FTDI-Compatible
Arduino Fio 3.3V 8MHz 14 8 6 1
Header
LDCE 3|Page
Internet of Things 3160716 190280107010
LDCE 4|Page
Internet of Things 3160716 190280107010
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).
LDCE 5|Page
Internet of Things 3160716 190280107010
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.
LDCE 6|Page
Internet of Things 3160716 190280107010
Main microcontroller
The Raspberry Each Arduino board has its own microcontroller (11). You can assume it as the
header is the key brain of your board. The main IC (integrated circuit) on the Arduino is slightly
to its ability to different from board to board. The microcontrollers are usually of the ATMEL
interface with the Company. You must know what IC your board has before loading up a new
real world. The Pi program from the Arduino IDE. This information is available on the top of the IC.
either uses a 40- For more details about the IC construction and functions, you can refer to the
pin or 26-pin data sheet.
depending on the
model and it is
ICSP pin
important to
understand how Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting
those pins are of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial
arranged and Peripheral Interface), which could be considered as an "expansion" of the output.
labelled. Actually, you are slaving the output device to the master of the SPI bus.
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
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.
pins)
5V (on 2 pins)
LDCE 7|Page
Internet of Things 3160716 190280107010
Ground (on 8 pins)
General purpose input and output
PWM (pulse width modulation)
I2C
I2S
SPI
Serial
These allow a massive range of sensors, motors, LEDs and accessories to be connected to the Pi.
Practical -2
Aim: To interface LED/Buzzer with Arduino/ Raspberry Pi and write programs to turn
ON LED for 1 sec after every 5 secs.
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
LDCE 8|Page
Internet of Things 3160716 190280107010
LDCE 9|Page
Internet of Things 3160716 190280107010
Practical -3
Aim: To interface DHT11 sensor with Arduino. Write program to print temperature and humidity
reading
#include <dht.h>
dht DHT;
void setup(){
Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor
}//end "setup()"
void loop(){
//Start of Program
DHT.read11(dht_apin);
LDCE 10 | P a g e
Internet of Things 3160716 190280107010
LDCE 11 | P a g e
Internet of Things 3160716 190280107010
Practical -4
#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/
// LED Pin
const int ledPin = 4;
void setup() {
Serial.begin(115200);
status = bme.begin();
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
LDCE 12 | P a g e
Internet of Things 3160716 190280107010
pinMode(ledPin, OUTPUT);
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
if (String(topic) == "esp32/output") {
Serial.print("Changing output to ");
if(messageTemp == "on"){
Serial.println("on");
digitalWrite(ledPin, HIGH);
}
else if(messageTemp == "off"){
Serial.println("off");
digitalWrite(ledPin, LOW);
}
}
}
LDCE 13 | P a g e
Internet of Things 3160716 190280107010
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client")) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Temperature in Celsius
temperature = bme.readTemperature();
humidity = bme.readHumidity();
LDCE 14 | P a g e
Internet of Things 3160716 190280107010
Practical -5
#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
LDCE 15 | P a g e
Internet of Things 3160716 190280107010
#include <Adafruit_Sensor.h>
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/
// LED Pin
const int ledPin = 4;
void setup() {
Serial.begin(115200);
status = bme.begin();
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
pinMode(ledPin, OUTPUT);
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
if (String(topic) == "esp32/output") {
Serial.print("Changing output to ");
if(messageTemp == "on"){
Serial.println("on");
digitalWrite(ledPin, HIGH);
}
else if(messageTemp == "off"){
Serial.println("off");
digitalWrite(ledPin, LOW);
}
}
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client")) {
Serial.println("connected");
// Subscribe
client.subscribe("esp32/output");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
LDCE 17 | P a g e
Internet of Things 3160716 190280107010
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Temperature in Celsius
temperature = bme.readTemperature();
humidity = bme.readHumidity();
LDCE 18 | P a g e
Internet of Things 3160716 190280107010
Practical 6
Aim: Study any one IoT technology like fastag, or tracking and monitoring, write its detailed
communication protocols used.
ZigBee protocol provides low-cost, low power solution for remotely controlling and monitoring smart equipments, fleet
applications, home automation systems, medical devices and other compliant systems. It is used by leading
manufacturers of semiconductor devices, technology firms, wireless communication devices as the de-facto
communication protocol.
In this modern era, there are several standards that are available for high data rate transfer, but none of them seems to
be compatible for sensors and control devices communication standards. This communication not only required high
data rates but also low tenancy and power consumption at lower bandwidths. Due to the fact that all of these
specifications are present in this ZigBee technology, it is making this “a best fit” for several embedded applications,
industrial control, HA, and so on.
LDCE 19 | P a g e
Internet of Things 3160716 190280107010
System structure of ZigBee technology consists of three main components: ZigBee coordinator, Router, and end device.
Every ZigBee network has to consist one coordinator which acts as a bridge of network. The coordinator acts as a hub of
receiving and storing important information during a process of transmitting data operations. ZigBee router acts as an
intermediate between the hub of information and end devices which permits the traffic or commands to move through
them to the end device. End devices have limited access of communication with their parents nodes such that to save
useful power, energy or battery itself. The pattern in which these three components are connected with each other’s
depends on star, tree, and mesh networks.
1.
Physical layer: this layer performs the task of modulation as well as demodulation of various transmitted and
received signals, respectively. Various frequency, data rates, and channel are used with this layers depending
upon the locality.
2.
MAC Layer: the function of this layer is to enable reliable data transfer communication by accessing different
networks with the carrier sense multiple access collision avoidance (CSMA).
3.
Network Layer: this layer accompanies for all network related operations such as connection between router
and different end devices, disconnection to network, routing and various device configuration.
4.
Application support sublayer: this layer is responsible interfere ZigBee devices with different object application
device in order to communicate through network layer. It is responsible of matching to peripherals on the basis
of their services, application, and needs.
5.
Application framework: it gives two sorts of information administrations as key esteem combine and nonspecific
message administrations. Nonspecific message is a developer characterized structure, while the key esteem
match is utilized for getting properties inside the application objects. ZDO gives an interface between application
items and APS layer in ZigBee gadgets. It is in charge of distinguishing, starting and restricting different gadgets
to the system.
ZigBee data transmission technology mainly works under two modes: non-Beacon mode and Beacon mode. In first
mode, i.e., beacon mode, coordinators and routers continuously monitor any changes of flowing data; therefore, more
power is consumed. The routers and coordinators cannot sleep in this mode as at anytime node could receive any signal
to communicate and respond. Nonetheless, it requires more power supply and its general power utilization is low on
the grounds that the greater part of the gadgets are in a latent state for over long stretches in the system.
Contrary, in beacon mode the router and coordinators enters the sleeping mode when there is no data transmission.
There is a cyclic process using relays which counters, which periodically switch on and off routers to transmit data to
LDCE 20 | P a g e
Internet of Things 3160716 190280107010
multiple nodes within a network. These networks are work for available time slots which implies, they work when the
correspondence required outcomes in lower duty cycles and longer battery use.
LDCE 21 | P a g e
Internet of Things 3160716 190280107010
Practical 7
Aim: Write program on Arduino/ Raspberry Pi to upload temperature and humidity data to the
thingspeak cloud.
#include <ESP8266WiFi.h>
#define DHTPIN 0
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
Serial.println("");
Serial.println("WiFi connected");
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80))
{
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
LDCE 23 | P a g e
Internet of Things 3160716 190280107010
client.stop();
Serial.println("Waiting...");
delay(10000);
}
Output:
LDCE 24 | P a g e
Internet of Things 3160716 190280107010
Practical 8
Problem:
In education institutes taking attendance of students can be a cumbersome and redundant process.
Solution:
For solving this problem, we can use a RFID sensor attached to ID card. The sensor would be scanned
at each classroom and attendance would be uploaded to cloud on regular basis.
Sensors required:
RFID
Communication Protocols:
Gossip Protocol
State Routing Protocol
IGMP
EPCglobal Class 1 Gen 2 protocol (EPC C1G2)
LDCE 25 | P a g e
Internet of Things 3160716 190280107010
Practical 9
Aim: Develop a project on IoT application using Arduino or Raspberry Pi. with Tinkercad
simulation software tool.
LDCE 26 | P a g e
Internet of Things 3160716 190280107010
Working
1. Temperature sensor LM35 senses the temperature and converts it into an electrical (analog) signal, which
is applied to the ATmega328 microcontroller of the Arduino UNO Board.
2. The analog value is converted into a digital value. Thus the sensed values of the temperature and speed of the
fan are displayed on the LCD.
3. When the temperature exceeds 20°C the fan starts rotating.
4. A low-frequency pulse-width modulation (PWM) signal, whose duty cycle is varied to adjust the fan’s speed is
used.
5. Lm35 temperature sensor voltage to temperature conversion, now one of the most difficult thing is how to
convert the voltage generated/output by the lm35 sensor at output in Celsius or Fahrenheit scales. Well this
needs you to first go through the data sheet of temperature sensor and know about the characteristics of the
sensor.
Code
LDCE 27 | P a g e
Internet of Things 3160716 190280107010
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); float temp;
int tempPin = A1; int relayPin = 8; #define fan 9
void setup(){
pinMode(fan, OUTPUT); pinMode(relayPin, OUTPUT);
lcd.begin(16, 3); lcd.print("AUTO TEMPERATURE");
delay(2000); lcd.clear();
}
void loop()
{
lcd.setCursor(3,0); lcd.print("Recording");
lcd.setCursor(2, 1); lcd.print("Temperature.."); delay(3000);
lcd.clear(); lcd.setCursor(0,2);
temp = analogRead(tempPin); //temp = temp*0.48828125; float voltage = temp * 5.0;
LDCE 28 | P a g e
Internet of Things 3160716 190280107010
voltage /= 1024.0; // print out the voltage
lcd.print(voltage); lcd.println(" volts"); // now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
lcd.setCursor(0, 0);
lcd.print("Temperature = ");
lcd.setCursor(2,1); //lcd.print(temp);
lcd.print(temperatureC);
lcd.println(" degrees C");
delay(3000);
lcd.clear();
LDCE 29 | P a g e
Internet of Things 3160716 190280107010
{
digitalWrite(relayPin, LOW); analogWrite(fan,0);
lcd.print("Fan OFF"); delay(2000); lcd.clear();
}
Output:
LDCE 30 | P a g e
Internet of Things 3160716 190280107010
Advantages
1. This project can be used in both the home and Industry.
2. It helps in saving the time, energy and electricity.
3. Normally we use the regulator to change the speed of the fan. Here the
room temperature changes the speed varies so that according to the
temperature the fan rotates.
Disadvantages
Future
Enhancements
1. To integrate IR sensor, so that it can detect presence of people in room and
accordingly switch the fan off when no one’s around.
LDCE 31 | P a g e