IOT Lab Manual
IOT Lab Manual
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Interfacing switch button and stepper motor with 8051 and developing
2 CO1
program to rotate it according to position of switch button.
Uploading data on Arduino IoT cloud and monitor the status of data on cloud
7 CO6
to turn ON/OFF LED.
Subject In charge
Prof. R.K. SINGH
==================================================================================
Page 1 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
EXPERIMENT NO. 1
Theory: LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very commonly used in
various devices and circuits. A 16x2 LCD means it can display 16 characters per line and there
are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two
registers, namely, Command and Data.
Commands: There are some preset commands which will do a specific task in the LCD.
These commands are very important for displaying data in LCD. The list of commands given
below:
Command Description
38H Use two lines and 5x7 matrix, 8bit data length
01H Clear the screen
0EH Display ON cursor ON
06H Increment address to move cursor to the right
80H Force cursor to bring at 1st position of 1st Line
C0H Force cursor to bring at 1st position of 2nd Line
sbit en = P1^0;
sbit rs = P1^2;
sbit rw = P1^1;
void lcd_cmd(){
en = 0;
rs = 0;
en = 1;
delay(10);
en = 0;
}
void lcd_data(){
en = 0;
rs = 1;
en = 1;
delay(10);
en = 0;
}
void main(){
rw = 0;
delay(100);
==================================================================================
Page 3 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
P2 = 0x38;
lcd_cmd();
P2 = 0x06;
lcd_cmd();
P2 = 0x0E;
lcd_cmd();
P2 = 0x01;
lcd_cmd();
P2 = 'A';
lcd_data();
P2 = 'P';
lcd_data();
P2 = 'S';
lcd_data();
P2 = 'I';
lcd_data();
P2 = 'T';
lcd_data();
while(1);
}
==================================================================================
Page 4 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Conclusion: LCDs (Liquid Crystal Displays) are used for displaying status or parameters in
embedded systems. LCD 16x2 is 16 pin device which has 8 data pins (D0-D7) and 3 control
pins (RS, RW, EN). The control pins help us configure the LCD in command mode or data
mode. C program is developed to display a string on 16x2 screen.
==================================================================================
Page 5 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
EXPERIMENT NO. 2
Title: Study of stepper motor and its interfacing with 8051 microcontroller.
Aim: Suppose a switch and stepper motor are interfaced with 8051. Write an C language
program which will monitor the status of Switch and perform following
Full Drive Mode − In this mode, two coils are energized at the same time. This mode produces
more torque. Here the power consumption is also high.
==================================================================================
Page 7 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
==================================================================================
Page 8 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
#include<reg51.h>
void main(){
int i;
button = 1;
while(1){
if(button == 0){
for(i = 0; i<4; i++)
{ P1 = 0x11<<i;
delay(50);
}
}
else
{ for(i = 0; i<4; i++)
{ P1 = 0x88>>i;
delay(50);
}
}
}
}
Conclusion:
Stepper and switch button are interfaced with microcontroller 8051. Direction of rotation of
stepper motor is controlled by switch position. Sequence of patter need to be change to change
direction of rotation.
EXPERIMENT NO. 3
==================================================================================
Page 9 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Title: Study of PWM of Arduino Uno.
Aim: Generation of PWM signal at one of the pins of Arduino Uno (ATMEGA328P) to
Theory:
Many low-cost microcontrollers have peripherals to process analog input signals, such as an
Analog-to-Digital Converter (ADC), but often do not have a Digital-to-Analog Converter
(DAC) included. most microcontrollers offer a Pulse-Width Modulation (PWM) module,
which can be combined with a low-pass filter to create an analog output. Pulse-width
modulation (PWM) is a powerful technique for controlling analog circuits with
a microcontroller's digital outputs.
PWM is commonly used to control the speed of electric motors, the brightness of lights,
in ultrasonic cleaning applications, and many more.
• Period: Period is defined by the time it takes from one rising edge to the subsequent
one.
• Pulse width: Pulse width is the lapse in time between rising and falling edges of an
individual pulse.
• Duty cycle: Duty cycle is the percentage of the logic 1 pulse width, compared to the
The percentage of time for which the signal remains “ON” is known as the duty cycle. If the
signal is always “ON,” then the signal must have a 100 % duty cycle. The formula to
Figure 2: Interfacing of DC motor and LED with Arduino to control speed and light intensity
respectively
Implementation of PWM signal using Arduino: The Arduino's programming language makes
PWM easy to use; simply call analogWrite(pin, dutyCycle), where duty Cycle is a value from
0 to 255, and pin is one of the PWM pins (3, 5, 6, 9, 10, or 11).
The ATmega168P/328P chip has three PWM timers, controlling 6 PWM outputs. By
manipulating the chip's timer registers directly, we can obtain more control than the
analogWrite function provides.
==================================================================================
Page 11 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Arduino program to control intensity of light and speed of DC motor is given below.
#define led 9
#define motor 3
int i;
void setup()
{ Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(motor, OUTPUT);
}
void loop()
{ for(i = 0; i<256; i++){
analogWrite(led, i);
analogWrite(motor, i);
delay(30);
}
Conclusion: PWM is commonly used as a way to generate an analog signal that correlates to a
digital value. In above experiment, we have generated PWM signal at two different pins of
Arduino, to control intensity of light and speed of DC motor.
EXPERIMENT NO. 4
a) Sweeps the shaft of a RC servo motor back and forth across 180 degrees.
b) Move the shaft of servo motor with angle 00, 300, 600, 900, 1200, 1500 and 1800 back
and forth.
Theory:
A servo motor is a type of motor that can rotate with great precision. Normally this type of
motor consists of a control circuit that provides feedback on the current position of the motor
shaft, this feedback allows the servo motors to rotate with great precision. If we want to rotate
an object at some specific angles or distance, then we use a servo motor. It is just made up of a
simple motor which runs through a servo mechanism.
A servo motor usually comes with a gear arrangement that allows us to get a very high torque
servo motor in small and lightweight packages. Servo motor works on PWM (Pulse width
modulation) principle, means its angle of rotation is controlled by the duration of applied pulse
to its Control PIN. Servo motor can be rotated from 0 to 180 degrees.
The position sensor provides a feedback signal corresponding to the present position of the load.
This sensor is a potentiometer that produces the voltage corresponding to the absolute angle of
the motor shaft through gear mechanism. Then the feedback voltage value applies on the input
of error amplifier.
The error amplifier is a negative feedback amplifier and it reduces the difference between its
inputs. It compares the voltage related to current position of the motor with desired voltage
related to desired position of the motor. And it produces the error either a positive or negative
voltage.
This error voltage applied to the armature of the motor. If the error is more then motor armature
gets more output. The amplifier amplifies the error voltage and powers the armature. Thus motor
rotates till the error becomes zero. If the error is negative, the armature voltage reverses and hence
the armature rotates in the opposite direction.
==================================================================================
Page 13 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
==================================================================================
Page 14 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Code-A: Sweeps the shaft of a RC servo Code-B: Move the shaft motor with angle
0
motor back and forth across 180 . 00, 300, 600, 900, 1200, 1500 and 1800 back
and forth
==================================================================================
Page 15 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
EXPERIMENT NO. 5
Aim: Interface Ultrasonics distance sensor, a LED with Arduino and develop C program to
turn on the LED if distance between object and sensor is more than 50 cm otherwise turn
off the LED.
Theory: The ultrasonic sensor (or transducer) works on the same principles as a radar system.
An ultrasonic sensor can convert electrical energy into acoustic waves and vice versa. The
acoustic wave signal is an ultrasonic wave traveling at a frequency above 18kHz. The famous
HC SR04 ultrasonic sensor generates ultrasonic waves at 40kHz frequency. Typically, a
microcontroller is used for communication with an ultrasonic sensor.
To begin measuring the distance, the microcontroller sends a trigger signal to the
ultrasonic sensor. The duty cycle of this trigger signal is 10µS for the HC-SR04 ultrasonic
sensor. When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts
and initiates a time counter. As soon as the reflected (echo) signal is received, the timer stops.
The output of the ultrasonic sensor is a high pulse with the same duration as the time difference
between transmitted ultrasonic bursts and the received echo signal.
Distance = 0.0171×t cm
==================================================================================
Page 16 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
float distance;
long duration;
void setup()
{ pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop()
{ digitalWrite(trig, LOW);
delay(20);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
delay(1000);
}
==================================================================================
Page 18 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
==================================================================================
Page 19 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
EXPERIMENT NO. 6
Aim: Interface 2 LEDs and Bluetooth HC-05 with Arduino Uno. Pair Bluetooth HC-05 with
smart phone, and Control status of LED1 and Led2 through app.
Theory:
Bluetooth is a low cost, low power, short range wireless technology for data and voice
communication. Bluetooth was developed in the late 1990s and soon achieved massive
popularity in consumer devices. Bluetooth operates at 2.4GHz of the Radio Frequency
spectrum. It supports a data rate of up to 1Mbps and a range of approximately 30 feet. Bluetooth
enabled devices essentially contain a Bluetooth wireless radio for the transmission and
reception of data.
HC-05 is a Bluetooth module which is designed for wireless communication. This module can
be used in a master or slave configuration. It has 6 pins. Description of these pins is given
below.
Pin-1 EN This pin is used to enable data mode or command mode of module.
Pin-2 VCC Connect 5 V or 3.3 V to this Pin
Pin-3 GND Ground pin of Module
Pin-4 TXD Transmit Data to which is received wirelessly.
Pin-5 RXD Receive data which is to be sent wirelessly to other Bluetooth device.
==================================================================================
Page 20 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Pin-6 State It tells whether module is connected or not.
Interfacing of HC-05 and LEDs is shown in figure 1. RXD and TXD pins of HC-05 are
interfaced with TX and RX pins of Arduino. HC-05 is power up using Vcc and GND pins.
char inByte;
#define LED1 13;
#define LED2 12;
void setup() {
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
}
void loop() {
if(Serial.available()>0)
{ inByte = Serial.read();
==================================================================================
Page 21 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
switch(inByte){
case 'a' : digitalWrite(LED1, HIGH); break;
case 'b' : digitalWrite(LED1, LOW); break;
case 'c' : digitalWrite(LED2, HIGH); break;
case 'd' : digitalWrite(LED2, LOW); break;
}
}
}
Program to Control LEDs via Bluetooth
Conclusion: HC-05 Bluetooth module and LEDs are interfaced with Arduino. HC-05 is paired
with smart phone and data is transmitted to Arduino via Bluetooth. LEDs are turned ON and
OFF through android app.
==================================================================================
Page 22 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
EXPERIMENT NO. 7
Title: Data logging and device controlling using Arduino IoT cloud.
Theory:
The Arduino IoT Cloud is an online platform that makes it easy to create, deploy and
monitor IoT projects. Connected devices around the world are increasing by billions every
year. The Arduino IoT Cloud is a platform that allows anyone to create IoT projects, with
a user-friendly interface, and an all-in-one solution for configuration, writing code,
uploading and visualization.
Below is a list of Arduino IoT Cloud features.
Data Monitoring – We can easily monitor data through dashboard.
Variable Synchronisation – Variable synchronisation allows to sync variables across
devices, enabling communication between devices with minimal coding.
Scheduler - schedule jobs to go on/off for a specific amount of time (seconds, minutes,
hours).
Webhooks - integrate your project with another service, such as IFTTT.
Dashboard Sharing - share the data with other people around the world.
To use the Arduino IoT Cloud, a cloud compatible board is required. You can choose
between using an official Arduino board, or a board based on the ESP32 / ESP8266
microcontroller. The Arduino IoT Cloud currently supports connection via Wi-Fi (via The
Things Network) and mobile networks.
==================================================================================
Page 23 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
ESP8266
The Arduino IoT Cloud supports a wide range of third-party boards based on the ESP32 and
ESP8266 microcontrollers with support for Wi-Fi. To set them up, simply choose the third-
party option in the device setup.
Setting up the Arduino IoT Cloud and accessing the different features available involves a
few simple steps.
1. Creating an Arduino Account
To starting using the Arduino IoT cloud, we first need to log in or sign up to Arduino. Link
is https://create.arduino.cc/iot/. After we have signed up, you can access the Arduino IoT
Cloud from any page on arduino.cc by clicking on the four dots menu in the top right
corner.
2. Creating a Thing
The journey always begins by creating a new Thing. In the Thing overview, we can choose
what device to use, what Wi-Fi network we want to connect to, and create variables that we
can monitor and control. This is the main configuration space, where all changes we make
are automatically generated into a special sketch file.
==================================================================================
Page 24 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
3. Configuring a Device
Devices can easily be added and linked to a Thing. The Arduino IoT Cloud requires computer
to have the Arduino Agent installed. We can choose from any board that has been configured,
or select the “Configure new device” option. Here we can manage and add new devices.
4. Creating Variables
The variables we create are automatically generated into a sketch file. There are several data
types we can choose from, such as int, float, boolean, long, char. When clicking on
the “Add variable” button, we can choose name, data type, update setting and interaction
mode.
==================================================================================
Page 25 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
5. Connecting to a Network
To connect to a Wi-Fi network, simply click the “Configure” button in the network
section. Enter the credentials and click “Save”. This information is also generated into your
sketch file!
An automatically generated sketch file can be found in the “Sketch” tab. It has the same
structure as a typical *.ino file, but with some additional code to make the connection to your
network and to the cloud. A sketch that, for example, reads an analog sensor, and use the cloud
variable to store it. When the sketch has been uploaded, it will work as a regular sketch, but
it will also update the cloud variables that we use! Additionally, each time we create a variable
that has the Read & Write permission enabled, a function is also generated, at the bottom of
sketch file. Each time this variable changes, it will execute the code within this function! This
means that we can leave most of the code out of the loop() and only run code when needed.
To upload the program to our board, simply click the "Upload" button.
==================================================================================
Page 26 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
If we click on “Create new dashboard”, we enter a dashboard editor. Here, we can create
something called widgets. Widgets are the visual representation of our variables we create,
and there are many different to choose from. Below is an example using several types of
widgets.
==================================================================================
Page 27 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
==================================================================================
Page 28 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
#include "DHT.h"
#define DHTPIN D3
#define DHTTYPE DHT11 void onLedChange() {
DHT dht(DHTPIN, DHTTYPE);
if(led == true)
void setup() { { digitalWrite(D0, LOW);
Serial.begin(9600);
Serial.println(F("DHT11 test!")); }
dht.begin();
} else
{ digitalWrite(D0, HIGH);
void loop() {
float h, t; }
delay(2000);
h = dht.readHumidity(); }
t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read Data!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("C "));
}
Program to read data from DHT-11 which Subroutine to change status of LED
is to be incorporated in sketch of cloud using switch of dashboard.
==================================================================================
Page 29 of 30
Prof. R.K. SINGH
Department of Mechanical Engineering
YEAR: 2023-24
COURSE NAME: MEL-802 Laboratory Based on IoT
Class: BE MECH SEM:VIII
=================================================================
Conclusion: We successfully upload the data on cloud and could fetch from cloud. In first part
of the experiment, we have sent Temperature and humidity data on Arduino IoT cloud and
observed on Dashboard. Whereas in second part of the experiment, we have switched ON and
Switch of the LED using switch button on dashboard via internet.
==================================================================================
Page 30 of 30
Prof. R.K. SINGH