Final IOT Labmaual SMP-DTE
Final IOT Labmaual SMP-DTE
Internet of Things
(3171108)
B.E. Semester 7
(Electrical Engineering)
Institute (GTU Code:028 ) has satisfactorily completed the Practical for the subject
Place: _____________________
Date: _________________
Head of Department
Preface
Main motto of any laboratory/practical/field work is to enhance required skills as well as to create ability
amongst students to solve any real time problem by developing relevant competencies in psychomotor
domain. To fulfil these requirements, competency focused outcome-based curriculum is designed for
engineering degree programs where sufficient weightage is given to the practical work.
Each experiment in the laboratory manual is keenly designed to serve as a tool to develop and
enhance relevant competency required by various industries among every student. Each experiment is
mapped with Course Outcome which in turn will help satisfying each Course Outcome and to achieve
certain level of attainment. The experiment covers the fundamental theory to understand and perform the
experiment, followed by an apparatus required to perform the experiment. The step-by-step procedure is
described to help students in setting-up and configuring the experimental test bench for performance.
Necessary tables for observations, plots, figures and conclusion are kept in flow with required guidelines.
The laboratory manual also provides the guidelines for the subject faculty member to facilitate
student centric laboratory activities through each experiment by arranging and managing necessary
resources. The evaluation rubrics are well-defined and have been given a certain Weightage for fair
assessment.
The Internet of Things (IoT) course deals with the numbers of devices connected together using
Internet to interact with each other and to exchange certain data of current status of activities to monitor and
control the devices remotely using Website or Mobile Applications over Internet. IoT makes devices smarter
to work automatically as well as to be controlled remotely which makes functionalities quite efficient. IoT
is a combination of sensors, actuators, networking hardware and software which are connected to each other
The following industry relevant competencies are expected to be developed in the student by undertaking the
practical work of this laboratory.
1. Installing and using various softwares used in industries.
2. To get familiar with variety of hardware used in industries.
3. To interface hardware and software to develop various applications.
4. To develop variety of operating and controlling applications using hardware and software.
5. To gain skills of troubleshooting the hardware, software and interfacing parts.
COURSE OUTCOMES
Sr. No Outcomes Domain of Learning
CO1 Understand IoT architecture Cognitive Domain
CO2 Program Embedded IoT devices Cognitive Domain
Implement IoT protocol to upload sensor data and to control Psychomotor/
CO3
devices Attitudinal Domain
Psychomotor Domain
CO4 Design IoT application
Affective
INDEX
5. Operating System
Installation and
Configuration of
Raspberry Pi
Date:
Relevant CO:
Objectives: To get familiar with Arduino UNO Board, its functionalities, operating
guidelines, its software Arduino IDE Installation and programming environment.
Apparatus: Arduino UNO Board, Computer, Arduino UNO Board USB Data Cable,
Arduino IDE Software
This experiment will introduce and discuss about the Arduino UNO Board, its components,
features and various functions, as shown in Figure-1.1.
Overview:
The Arduino Uno is a microcontroller board based on the ATmega328. It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz
ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. It
contains everything needed to support the microcontroller; simply connect it to a computer
with a USB cable or power it with an AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in a way that it does not use the FTDI USB-to-
serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2)
programmed as a USB-to-serial converter. Revision 2 of the Uno board has a resistor pulling
the 8U2 HWB line to ground, making it easier to put into DFU mode. Revision 3 of the board
has the following new features:
• 1.0 pinout: Added SDA and SCL pins that are near to the AREF pin and two other new pins
placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage
provided from the board. In future, shields will be compatible both with the board that uses
the AVR, which operate with 5V and with the Arduino Duo that operate with 3.3V. The
second one is a not connected pin that is reserved for future purposes.
• "Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The
Uno and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is
the latest in a series of USB Arduino boards, and the reference model for the Arduino
platform.
Summary:
• Microcontroller ATmega328
• Operating Voltage 5V
• Input Voltage (recommended) 7-12V
• Input Voltage (limits) 6-20V
• Digital I/O Pins 14 (of which 6 provide PWM output)
• Analog Input Pins 6
• DC Current per I/O Pin 40 mA
• DC Current for 3.3V Pin 50 mA
• Flash Memory 32 KB (ATmega328) of which 0.5 KB used by boot loader
• SRAM 2 KB (ATmega328)
• EEPROM 1 KB (ATmega328)
• Clock Speed 16 MHz
Power:
The Arduino Uno can be powered via the USB connection or with an external power supply.
The power source is selected automatically. External (non-USB) power can come either from
an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a
2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted
in the GND and Vin pin headers of the POWER connector. The board can operate on an
external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may
supply less than five volts and the board may be unstable. If using more than 12V, the voltage
regulator may overheat and damage the board. The recommended range is 7 to 12 volts.
The power pins are as follows:
• VIN: The input voltage to the Arduino board when it's using an external power source (as
opposed to 5 volts from the USB connection or other regulated power source). You can
supply voltage through this pin, or, if supplying voltage via the power jack, access it through
this pin.
• 5V: This pin outputs a regulated 5V from the regulator on the board. The board can be
supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or
the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the
regulator, and can damage your board.
• 3V3: A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50
mA.
• GND: Ground pins.
Memory:
The ATmega328 has 32 KB (with 0.5 KB used for the boot loader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM library).
The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of
resolution (i.e. 1024 different values). By default they measure from ground to 5 volts,
though is it possible to change the upper end of their range using the AREF pin and the
analogReference() function. Additionally, some pins have specialized functionality:
• TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire
library. There are a couple of other pins on the board:
• AREF. Reference voltage for the analog inputs. Used with analogReference().
• Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button
to shields which block the one on the board.
Communication:
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on
the board channels this serial communication over USB and appears as a virtual com port to
software on the computer. The '16U2 firmware uses the standard USB COM drivers, and no
external driver is needed. However, on Windows, an .inf file is required. The Arduino
software includes a serial monitor which allows simple textual data to be sent to and from the
Arduino board. The RX and TX LEDs on the board will flash when data is being transmitted
via the USB-to-serial chip and USB connection to the computer (but not for serial
communication on pins 0 and 1).
A Software Serial library allows for serial communication on any of the Uno's digital pins.
The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software
includes a Wire library to simplify use of the I2C bus. For SPI communication, use the SPI
library.
Programming:
The Arduino Uno can be programmed with the Arduino software. Select "Arduino Uno from
the Tools > Board menu (according to the microcontroller on your board).
The ATmega328 on the Arduino Uno comes pre-burned with a boot loader that allows you to
upload new code to it without the use of an external hardware programmer. It communicates
using the original STK500 protocol.
You can also bypass the boot loader and program the microcontroller through the ICSP (In-
Circuit Serial Programming) header. The ATmega16U2 (or 8U2 in the rev1 and rev2 boards)
firmware source code is available. The ATmega16U2/8U2 is loaded with a DFU boot loader,
which can be activated by:
• On Rev1 boards: connecting the solder jumper on the back of the board (near the map of
Italy) and then resetting the 8U2.
• On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to ground,
making it easier to put into DFU mode.
One can use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X and
Linux) to load a new firmware, or one can use the ISP header with an external programmer
(overwriting the DFU boot loader). Following is the default basic structure on any Arduino
program.
References/Sources:
• https://www.farnell.com/datasheets/1682209.pdf
• Arduino Programming Series (ह द
िं ी में ):
https://www.youtube.com/playlist?app=desktop&list=PLV3C-t_tgjGFyXP_-
AF37AoIuxM9jzELM
• Arduino Series (ह दिं ी में ):
https://www.youtube.com/playlist?app=desktop&list=PLV3C-
t_tgjGE1USbPg2jrrDMu26F_M7K-
Relevant CO:
Objectives: To get familiar with NodeMCU, its functionalities, operating guidelines, its
software Arduino IDE Installation and programming environment.
Apparatus: NodeMCU Board, Computer, Micro USB to USB Cable, Arduino IDE Software
This experiment will introduce and discuss about the NodeMCU Board, its pin configurations
and its functions.
Figure-2.1 demonstrates the NodeMCU Board and its group wise pin functions. Functions are
grouped for ease of understanding and remembrance.
Figure-2.2: NodeMCU with detailed Pin Diagram and functional details
Figure-2.2 explores the NodeMCU with detailed Pin Diagram and functional details. As it
can be seen, most of the pins have multiple functionalities. Details explanation of each pin is
given below:
Power Pins There are four power pins viz. one VIN pin & three 3.3V pins. The VIN pin can
be used to directly supply the ESP8266 and its peripherals, if you have a regulated 5V
voltage source. The 3.3V pins are the output of an on-board voltage regulator. These pins can
be used to supply power to external components.
I2C Pins are used to hook up all sorts of I2C sensors and peripherals in your project. Both
I2C Master and I2C Slave are supported. I2C interface functionality can be realized
programmatically, and the clock frequency is 100 kHz at a maximum. It should be noted that
I2C clock frequency should be higher than the slowest clock frequency of the slave device.
GPIO Pins ESP8266 NodeMCU has 17 GPIO pins which can be assigned to various
functions such as I2C, I2S, UART, PWM, IR Remote Control, LED Light and Button
programmatically. Each digital enabled GPIO can be configured to internal pull-up or pull-
down, or set to high impedance. When configured as an input, it can also be set to edge-
trigger or level-trigger to generate CPU interrupts.
ADC Channel The NodeMCU is embedded with a 10-bit precision SAR ADC. The two
functions can be implemented using ADC viz. Testing power supply voltage of VDD3P3 pin
and testing input voltage of TOUT pin. However, they cannot be implemented at the same
time.
UART Pins ESP8266 NodeMCU has 2 UART interfaces, i.e. UART0 and UART1, which
provide asynchronous communication (RS232 and RS485), and can communicate at up to 4.5
Mbps. UART0 (TXD0, RXD0, RST0 & CTS0 pins) can be used for communication. It
supports fluid control. However, UART1 (TXD1 pin) features only data transmit signal so, it
is usually used for printing log.
ESP8266 features two SPIs (SPI and HSPI) in slave and master modes. These SPIs also
support the following general-purpose SPI features:
SDIO Pins ESP8266 features Secure Digital Input/Output Interface (SDIO) which is used to
directly interface SD cards. 4-bit 25 MHz SDIO v1.1 and 4-bit 50 MHz SDIO v2.0 are
supported.
PWM Pins The board has 4 channels of Pulse Width Modulation (PWM). The PWM output
can be implemented programmatically and used for driving digital motors and LEDs. PWM
frequency range is adjustable from 1000 μs to 10000 μs, i.e., between 100 Hz and 1 kHz.
Control Pins are used to control ESP8266. These pins include Chip Enable pin (EN), Reset
pin (RST) and WAKE pin.
• EN pin – The ESP8266 chip is enabled when EN pin is pulled HIGH. When pulled
LOW the chip works at minimum power.
• RST pin – RST pin is used to reset the ESP8266 chip.
• WAKE pin – Wake pin is used to wake the chip from deep-sleep.
References/Sources:
Aim: Interfacing of ultra-sonic sensor with IOT controller and programing the same for
distance calculation with respect to obstacles.
Apparatus: NodeMCU, HC-SR04 (Ultra-sonic Sensor). Bread Board, Jumper Wires, Micro
USB Cable
Theory:
Hcsr04 ultrasonic sensor is composed of ultrasonic transmitter, ultrasonic receiver and a control
circuit. Hscr04 ultrasonic transmitter transmits ultrasound waves at 40,000 Hz. Transmitted
waves bounce back if they hit any flat surface/object in their path. Bounced back waves reaches
the ultrasonic receiver. Ultrasonic receiver receives the bounced back waves and notifies the
control circuit about it. Control circuit than calculates the time taken by waves to reach back
after transmission. Time is than manipulated to approximate the distance traveled by waves or
what is the distance between the sensor and the object? from which ultrasound waves bounced
back.
Hcsr04 can measure distance between an active range of 2 cm to 4 meters. Hcsr04 requires 5
volts and 15 mA of power for operation. Hcsr04 has four pins. Two are power pins. Vcc is +ve
pin apply 5v to this pin and Gnd is ground pin connect -ve of 5v power source with it. The
other two pins are Trigger and Echo.
Code:
// defines pins numbers
const int trigPin = 2; //D4
const int echoPin = 0; //D3
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
Output:
Conclusion:
Experiment No: 4
Introduction to Raspberry Pi
Date:
Relevant CO:
Objectives: To get familiar with Raspberry Pi Board and its functionalities, operating
guidelines and programming environment.
This experiment will introduce and discuss the NodeMCU Board, its pin configurations and
various functions. Figure-10.1 shows major components of Raspberry Pi which are useful for
interfacing and controlling devices through programming.
• Experiment Video:
https://www.youtube.com/watch?v=5D_Nn5NmmrI&list=PL0s3O6GgLL5cteXH7CJ
K7kc2Ar5wR7M81&index=3
Date:
Relevant CO:
The experiment will demonstrate the Installation of Raspbian Operating System and
Configuration of Raspberry Pi.
The Figure-11.1 lists various available operating systems for Raspberry Pi.
First of all, select and download Raspbian OS on memory card as shown in Figure-11.2.
Figure-11.2: Raspberry Pi Operating System source
Once done, insert OS installed memory card into Raspberry Pi board and boot from the same.
The following screen should appear first, as shown in Figure-11.3.
Select Raspberry Pi configuration from Preferences menu. Follow the steps as shown in
following figures, collaboratively named as Figure-11.4.
Figure-11.4: Raspberry Pi Configuration
References/Sources:
• Experiment Videos:
https://www.youtube.com/watch?v=ePPBivLqlOE&list=PL0s3O6GgLL5cteXH7CJK
7kc2Ar5wR7M81&index=2
https://www.youtube.com/watch?v=D4y_i-
m5rK4&list=PL0s3O6GgLL5cteXH7CJK7kc2Ar5wR7M81&index=4
References used by the students:
Date:
Relevant CO:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.IN)
GPIO.setup(5, GPIO.OUT)
while True:
val = GPIO.input(3)
print (val)
if val == 1:
GPIO.output(5, GPIO.LOW)
else:
GPIO.output(5, GPIO.HIGH)
References/Sources:
• Experiment Videos:
https://www.youtube.com/watch?v=qQTQcN44UWg&list=PL0s3O6GgLL5cteXH7C
JK7kc2Ar5wR7M81&index=7
Interfacing IOT Controller for controlling Brightness of LED using Raspberry Pi with PWM
technique.
Date:
Relevant CO:
Objectives: To configure and program Raspberry Pi Board for controlling brightness of LED
using PWM technique.
Code:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
P = GPIO.PWM(3,100)
P.start(0)
while True:
for x in range (100):
P.start(x)
time.sleep(0.1)
References/Sources:
• Experiment Videos:
https://www.youtube.com/watch?v=F0Ip8zubQlA&list=PL0s3O6GgLL5cteXH7CJK
7kc2Ar5wR7M81&index=8
Relevant CO:
Interface the DHT-11 temperature sensor and 16x2 LCD with Raspberry Pi as shown in
Figure-17.1
Figure-17.3 shows the output when the program code is written in python 3, compiled and
executed without errors. Temperature and Humidity is displayed on LCD.
Figure-17.3: Temperature sensor data displayed on LCD
Code:
GPIO.setmode(GPIO.BCM)
lcd1 = 12
lcd2 = 7
lcd3 = 8
lcd4 = 25
lcd5 = 24
lcd6 = 23
while True:
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11,
2)
lcd.clear()
lcd.message("Temp: " + str(temperature) + "C\nHumidity: " +
str(humidity) + "%")
time.sleep(1)
References/Sources:
• Experiment Videos:
https://www.youtube.com/watch?v=tICT98WwYxI&list=PL0s3O6GgLL5cteXH7CJ
K7kc2Ar5wR7M81&index=10
Aim: To Implement interfacing and programming of IOT controller for uploading real time
DHT22 sensor data on a mobile dashboard.
Procedure:
Hardware Setup:
Place the NodeMCU on the breadboard. The rest of the instructions assume the front (
with the holes ) of the DHT22 is facing you.
The left-most pin of the DHT22 is the positive pin. You should connect it to 3v3 or Vin
on the MCU.
The second pin of the DHT22 (from the left) is the data pin. You should connect it to
D2 on the MCU.
The third pin of the DHT22 (from the left) does nothing.
The last pin of theDHT22 (from the left) is the Ground pin. It should be connected
GND.
Software Setup:
Before starting to upload the program make sure all the necessary library files have been imported
in the Arduino IDE.
Code:
#define BLYNK_TEMPLATE_ID "TMPLwSnJ1Io0"
#define BLYNK_DEVICE_NAME "TempHumidity"
BlynkTimer timer1;
float h , t;
void sendSensor()
{
h = dht.readHumidity();
t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V1, t);
}
void setup()
{
Serial.begin(115200);
delay(100);
dht.begin();
BlynkEdgent.begin();
timer1.setInterval(2000L, sendSensor);
}
void loop()
{
BlynkEdgent.run();
timer1.run();
h = dht.readHumidity();
t = dht.readTemperature();
delay(800);
}
As discussed in previous practical, All the steps should be taken to create the blynk template
on the blynk cloud website. Here instead of only one virtual pin, We will create two virtual pin
to receive the data for humidity as well as temperature.
In mobile dashboard, instead of switch, we will use gauges to indicate the value of temperature
and humidity.
After that, Code which is shown above will be uploaded on NodeMCU.
Conclusion: