R20 JNTUK EEE IOT LAB Manual Final Print
R20 JNTUK EEE IOT LAB Manual Final Print
For women
Internet of Things
Laboratory
LABORATORY MANUAL
INTERNET OF THINGS
(SKILL COURSE)
(By V.V.V. SATYANARAYANA)
ELECTRICAL AND ELECTRONICS
ENGINEERING
(R20 – JNTUK – KAKINADA)
1
INSTITUTE VISION
MISSION
Undertake the activities that provide value-based
knowledge in Science, Engineering, and Technology
Provide opportunities for learning through industry-
institute interaction on the state-of the-art
technologies
Create a collaborative environment for research,
innovation, and entrepreneurship Promote activities
that bring in a sense of social responsibility
2
DEPARTMENT VISION
MISSION
Impart skills both in traditional and modern areas of
Electrical & Electronics Engineering
Provide exposure to latest developments in the field
through Seminars, Industrial visits, Workshops and
Paper presentations
Prepare the young minds to apply professional
engineering practices by considering environmental
and societal needs
3
INDEX
1. LIST OF EXPERIMENTS (SYLLABUS) [5]
2. EXPERIMENTS LIST CONDUCTED IN THIS LABORATORY [6]
3. EXPT-1 INSTALLATION OF ARDUINO IDE [7-14]
4. EXPT-2 INTERFACING OF LED/BUZZER [16-17]
5. EXPT-3 INTERACING OF PUSH BUTTON/IR/LDR SENSOR [18-20]
6. EXPT-4 INTERFACING OF DHT11 HUMIDITY AND TEMPERATURE
SENSOR [21-23]
4
List of Experiments: (As per R20 regulation of JNTUK- Kakinada)
Any TEN of the following Experiments are to be conducted
1. Familiarization with Arduino/Raspberry Pi and perform necessary software
installation.
2. To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to turn ON
LED for 1 sec after every 2 seconds.
3. To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry Pi and
write a program to turn ON LED when push button is pressed or at sensor detection.
4. To interface temperature sensor with Arduino/Raspberry Pi and write a program to
print temperature and humidity readings.
5. To interface Organic Light Emitting Diode (OLED) with Arduino/Raspberry Pi
6. To interface Bluetooth with Arduino/Raspberry Pi and write a program to send sensor
data to smartphone using Bluetooth.
7. To interface Bluetooth with Arduino/Raspberry Pi and write a program to turn LED
ON/OFF when „1‟/‟0‟ is received from smartphone using Bluetooth.
8. Write a program on Arduino/Raspberry Pi to upload and retrieve temperature and
humidity data to thingspeak cloud.
9. 7 Segment Display
10. Analog Input & Digital Output
11. Night Light Controlled & Monitoring System
12. Fire Alarm Using Arduino
13. IR Remote Control for Home Appliances
14. A Heart Rate Monitoring System
15. Alexa based Home Automation System
5
EXPERIMENTS CONDUCTED IN THE IoT LAB – GVPCEW
6
EXPT 1:
https://www.arduino.cc/en/software
7
Double click on the executable file highlighted in the oval and proceed to installation.
During installation, it may ask you for permissions and throw warnings also. Surely you can
give access to all permissions.
The installation may take several minutes depending on the configuration of the system. After
successful installation, one may find the green coloured icon of Arduino on desktop.
Double click that to open a new sketch.
8
1. Setup function
2. Loop function
The code written inside setup function gets executed, line by line, only once. i.e if the users
presses the RESET button on the Arduino UNO or Nano, the code written under Setup will
get executed only once. Then directly the controller jumps to Loop function and executes
the code for ever until a RESET takes place
Under the setup function, Pin declarations like INPUT or OUTPUT, initialization of Serial
modules like Serial.begin(baud rate), initialization of OLED display, initialization of seven
segment module TM1637, initialization of DHT11 sensor etc. have to be written.
Under “loop” function, the process that is to be done for ever is written. The “loop” gets
executed line by line until it reaches the end and repeats from the first line of code written
under the “loop” and so on.
There are a total of 14 digital input and output pins marked as 0,1,2,.... 12,13 known as
Digital pins. Out of the 14, pin 0 and 1 are used for Hardware UART by the controller to
communicate with the Personal Computer used for programming. Hence pins 0 and 1 should
not be used for connecting digital input output devices.
DONOT CHANGE THE CASE OF ANY OF THE LETTER IN THE NAME OF THE
FUNCTION *****************
9
pinMode(pin, INPUT_PULLUP); // Declares the “pin” as input with pin being held at HIGH
(5volts for Arduino Nano)
There are 8 analog (INPUT) pins on Arduino named as A0,A1,A2,A3,A4,A5,A6 and A7. They
can be configured as digital input and output pins also. In addition to this they are special pins
as they can read the analog signal voltages on the pins (< 5 volts). There is a 10 bit ADC on the
controller which multiplexes with all the 8 pins on the Arduino Board. There is an internal
voltage reference of 1.1Volt which can be invoked in the setup code with the following syntax
analogReference(INTERNAL);
If no such reference is used, the controller assumes Vcc (=5 Volt) of the supply as reference
voltage and hence gives a resolution of 5/1024 = 4.88 milli Volt.
// pin refers to the pin number used as analog input, say A0,A5 etc.
Pins A4 and A5 are multiplexed with I2C communication pins (I2C = Inter Integrated
Communication protocol designed by Philips semiconductors during 1982, which is used for
communication between devices on a circuit board, A4 is serial data pin, A5 is serial
clock pin)
All analog input pins, A0 though A7 can be configured as digital pins also.
Ex:
digitalWrite(A5,OUTPUT);
digitalWrite(A2,INPUT);
10
Installation of drivers for Nano:
Arduino Nano comes with an on board TTL – USB chip name CH340G. It needs driver
software to connect to the personal computer.
11
Extract the contents of zip file named CH341SER.zip and click on install to install the
driver.
Connect the Nano board with USB cable to the Computer. Press the Windows key +R to
open the run command. Then type
devmgmt.msc
in the dialogue box. This will open the device manager of your computer
Here one may find the item “ports (Com &LPT)” and further expansion of the tab shows the
communication ports connected to the computer, in the above case it is USB-SERIAL
12
CH340 (COM4), the COM number may vary from system to system. Remember this COM
port number.
13
The port in my case is COM4.
To open the Serial monitor/Plotter one may use the Tools menu and select the option.
Or one may directly click on the lens symbol in the top-right corner of the window
highlighted below. The Serial plotter is graph plotter which graphs the serial incoming data.
One may use even the keyboard short cut keys like
ctrl+shift+M
or
ctrl+shift+L
14
A view of the serial monitor. The settings at bottom show the change of BAUD RATE,
Auto Scroll and Time stamp
Baud rate must be the same as the one written in the code while initializing the serial
module using
Serial.begin(9600); or
Serial.begin(115200);
15
Expt 2: To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to turn
ON LED for 1 sec after every 2 seconds.
Aim: To blink the Light Emitting Diode connected to Arduino Nano to blink it ON for 1
second and OFF for 2 seconds
Apparatus: Trainer board containing Arduino Nano, USB cable, LED with Series resistor
(470 Ohm), connecting jumper wires
Circuit diagram:
Use the following sketch and make the connections on the board as above.
Take a wire and connect it from D13 pin of Arduino Nano to The pin Marked as L1 on the
Board. You may use any L1, L2, L3 or L4 : L1= RED, L2=Green, L3= Yellow, L4=Blue
/*
Task 3 :
Write a program to turn ON LED when push button is pressed or at sensor detection
*/
#define pin 13 // set pin number at which this led toggle must take place: : connect the
buzzer, if required, at same pin
void setup() {
pinMode(pin,OUTPUT);// set the pin as output, define the pin number above
16
void loop() {
// this program is not suitable if one wants to execute other tasks with the controller
(arduino nano)
// rather use millis() function to avoid blocking the processor during delay function
Output:
17
Expt 3: To interface Push button/Digital sensor (IR/LDR) with Arduino/Raspberry Pi and
write a program to turn ON LED when push button is pressed or at sensor detection.
AIM: To connect the Push button to Arduino Nano and turn ON the LED when the push
button is closed
Apparatus: Trainer board containing Arduino Nano, USB cable, LED with Series
resistor(470 Ohm), Push button with 10k Ohm resistor , connecting jumper wires
Circuit diagram:
Take two wires. Connect one wire between Arduino Nano D13 and any LED, say L1.
Connect the other wire between SWTCH1 or SWTCH2 Pin and D2 pin of Arduino
Code:
/*
Task 3 :
write a program to turn ON LED when push button is pressed or at sensor detection
*/
#define pin 13 // set pin number at which this led toggle must take place: : connect the
buzzer, if required, at same pin
void setup() {
18
pinMode(pin,OUTPUT);// set the pin as output, define the pin number above
void loop() {
digitalWrite(pin,HIGH);Serial.println(“key pressed”);
Output:
19
20
EXPT4: To interface temperature sensor with Arduino/Raspberry Pi and write a program to
print temperature and humidity readings.
Aim: To interface the DHT11 sensor with Arduino Nano and write a program to print the
temperature and humidity values on Serial monitor.
Circuit diagram:
On the Arduino kit, connect the signal pin near DHT11 with Arduino Nano‟s digital pin 2.
Before uploading the code to the board, download the following libraries to Arduino
IDE. Press shift+ctrl+I on the keyboard with Arduino IDE active. Type “DHT sensor
Adafruit” in the search box. Click install on the Adafruit DHT sensor library. If it asks
for additional libraries install please click “install all”.
When prompted choose the path to the above downloaded zip files
#include <Adafruit_Sensor.h>
21
#include <DHT.h>
#include <DHT_U.h>
uint32_t delayMS;
void setup() {
Serial.begin(9600);
// Initialize device.
dht.begin();
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
void loop() {
delay(delayMS);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
22
Serial.println(F("Error reading temperature!"));
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
Output:
23
Expt 5
Aim: To interface the SSD1306 OLED with Arduino IDE and Print a name on it
Apparatus: SSD1306 OLED 0.96 inch display, Arduino Nano, Connecting wires
Circuit diagram:
On the Arduino kit , the Serial Clock and Data pins (A5, A4) are connected to the OLED
SCL and SDA pins. Hence no connections are needed to be done.
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
24
// The pins for I2C are defined by the Wire-library.
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
void loop() {
display.println(F("Hello, world!"));
display.println("HELLO WORLD");
display.setTextColor(SSD1306_WHITE);
25
display.print(F("IoT Lab"));
display.display();
delay(2000);
Output:
The Text mentioned in the above program got printed on the OLED screen
26
Experiments 6 and 7:
To interface Bluetooth with Arduino and write a program to send sensor data to smart phone
using Bluetooth.
To interface Bluetooth with Arduino and write a program to turn LED ON/OFF when
„1‟/‟0‟ is received from smart phone using Bluetooth.
Aim: To interface the HC-05 Bluetooth module with Arduino Nano and establish
bidirectional communication between smart phone and Arduino Nano.
Apparatus:
Hardware: HC-05 Bluetooth module, Arduino Nano trainer kit, connecting wires, Android
smart phone ,Thermistor sensor for sending data , on board LEDs
Circuit diagram:
1. Connect the digital pin 2 of Arduino Nano with BT_Tx pin (TX pin of HC-05)
2. Connect the digital Pin 3 of Arduino Nano with BT_RX pin (RX pin of HC-05)
3. Connect the analog output pin of Thermistor sensor to analog input pin A3 of Arduino
Nano.
4. Connect a wire between On-board LED say L1 (red LED) with digital pin 13 of Arduino
#include <SoftwareSerial.h>
27
SoftwareSerial ss(2,3);// 2 is rx, 3 is tx for Arduino
// subroutines
void setup() {
ss.begin(9600);
Serial.begin(9600);
ss.setTimeout(100);
pinMode(13,OUTPUT);
pinMode(A3,INPUT);
void loop() {
if(ss.available()>0){
dat.trim();
if(dat=="0"){
digitalWrite(13,LOW);Serial.println("led is off");//ss.println("off");
28
if(dat=="1"){
digitalWrite(13,HIGH);Serial.println("led is on");}
//ss.println("on");
x=(1.00/298.15)+(1.00/3950.00)*log(1.00*y/(1024.00-y));
temp=1.000/x;
ss.println(String(temp-273.15)+String("Celsius"));
Serial.println(String(temp-273.15)+String("Celsius"));
tim=millis();
Open the Android phone with HC-05 bluetooth terminal App from play store
Drag the menu on the Android phone and switch on the Bluetooth connection
You will find the Bluetooth with name HC-05 on the search
Try to pair it
29
Once after successful paring, open the HC-05 bluetooth terminal App to see the
available devices. You will find the HC-05 along with its MAC ID
Just select the HC-05, After few seconds it shows the device connected.
Before connecting to terminal the HC-05 BT module will blink continuously. But after
pairing it with Bluetooth terminal App, the blinking time gets slowed down indicating
the paired communication.
You will notice the temperature value getting printed on the Terminal window of App.
30
EXPT8:
Type here for search with keyword ESP8266, you will find the link
31
https://arduino.esp8266.com/stable/package_esp8266com_index.json
copy this link and paste it in the additional boards manager URL window
NOW NAVIGATE TO
32
THEN YOU GET A NEW WINDOW..
THEN TYPE NODEMCU... AND CLICK INSTALL BUTTON.. YOU WILL NOT GET THE REMOVE BUTTON
INITIALLY. AFTER YOU INSTALL THE CORE, THEN YOU WILL FIND THE REMOVE BUTTON
33
THIS COMPLETES THE CORE
INSTALLATION. NOW YOU MAY
PROCEED WITH THE EXPERIMENT.
Aim: To Post the temperature and Humidity data to cloud using NodeMCU and Arduino
IDE using Thingspeak cloud
Apparatus:
Software: Thingspeak cloud account with valid write and read API keys, NodeMCU IoT
core for Arduino IDE
Hardware: NodeMCU board, DHT11 temperature and humidity sensor connecting wires
Circuit diagram:
34
1. CONNECT THE VCC PIN ON NODEMCU TO 3.3 VOLT ON NODEMCU
2. CONNECT THE GND PIN ON NODEMCU TO GND PIN
3. CONNECT THE JUMPER CLIP ON THE BOTTOM OF THE BOARD NAMED
3V3/VCC/5V. SHORT THE CLIP WITH VCC AND 3.3V
4. CONNECT THE SIGNAL PIN TO D2 PIN ON NODEMCU
CODE:
35
Then goto File/Examples/Thingspeak/ESP8266/program board directly/write multiple
fields example sketch. (like the following screenshot)
36
Open the tab named secrets.h given in the sketch as shown below.
Use your mobile phone hot spot for connecting to internet. Switch on the data and hotspot
on your mobile phone. In the secrets.h file, enter your SSID (of your hotspot) under the
double quotations
37
#define SECRET_PASS "12345678"
Here in this example my hot spot is named as “wifihotspot” with set password 12345678.
DONOT USE “SPACES” IN THE HOT SPOT, SAY “anu galaxy”. SIMILARLY
PASSWORD MUST BE OF 8 CHARACTERS LONG. YOU MAY USE _ OR ANY
OTHER SYMBOLS FOR SSID AS WELL AS PASS WORD.
38
Create a new channel with desired name
39
CLICK ON SAVE CHANNEL.
YOU WILL GET A NEW CHANNEL DASH BOARD LIKE THE FOLLOWING
40
NOTE DOWN YOUR CHANNEL ID, THE NUMBER WILL DIFFERENT FOR
YOU (THAN WHAT IS SHOWN ABOVE)
GET YOUR WRITE API KEY FROM YOUR DASH BOARD (COVERED YELLOW
BOX IN MY CASE)
41
ENTER YOUR CHANNEL ID AND YOUR WRITE APIKEY HERE AND SAVE
THE SKETCH.
#include <ESP8266WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header
files and custom macros
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
// https://learn.adafruit.com/dht/overview
42
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
float number1 = 0;
float number2 = 0;
void setup() {
WiFi.mode(WIFI_STA);
dht.begin();
sensor_t sensor;
43
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
void loop() {
if(WiFi.status() != WL_CONNECTED){
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(5000);
Serial.println("\nConnected.");
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
44
Serial.println(F("Error reading temperature!"));
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
number2 = event.temperature;
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
number1= event.relative_humidity;
45
if(x == 200){
else{
Now upload the code by selecting the board as NODEMCU 1.0 (ESP12E) and with
correct COM port number. It takes a while to upload the code, say 2 minutes.
After successful upload the NodeMCU tries to connect first to wifi hot spot and then
posts humidity and temperature data on the thingspeak dash board for every 20
seconds delay.
46
Expt: 9
Aim: To interface TM1637 display with Arduino Nano and print numbers
Apparatus: TM1637 seven segment display, Arduino Nano board, connecting wires
Circuit diagram:
1. Take four female to male type connecting wires and make the following
connections
2. Vcc pin on TM1637 === Arduino 5V pin
3. Gnd pin on TM1637 == Arduino Gnd pin
4. CLK pin on TM1637 == Arduino Digital pin 2
5. DIO pin on TM1637 = Arduino Digital pin 3
After successful installation, use the following code to upload to Arduino Nano.
47
Code:
#include <TM1637.h>
int CLK = 2;
int DIO = 3;
TM1637 tm(CLK,DIO);
void setup() {
tm.init();
tm.set(2);
void loop() {
// example: "12:ab"
// tm.display(position, character);
tm.display(0,1);
tm.display(1,2);
tm.point(1);
tm.display(2,10);
tm.display(3,11);
48
delay(1000);
// example: "1234"
displayNumber(1234);
delay(1000);
Here
tm.display(position, character);
Ex: tm.display(0,12); // prints the charcter “C” in the ones place of the 4 digit display
49
Expt:10 Analog Input and digital Output
Aim: To interface analog sensor (LDR/Thermistor) to the Arduino and print the Analog
output on serial monitor
Circuit diagram:
Connect the output sensing pin of either LDR or Thermistor to A3 pin of Arduino
Nano.
Code:
void setup() {
void loop(){
50
Serial.println(analogvalue);
SHIFT+CTRL+M
Select the baud rate of 9600 on the serial monitor to see the printed values of analogRead on the
screen
51
Expt 11:
Aim: To control and LED based on the light intensity sensed by LDR and to print the
intensity of light on to the serial monitor.
Apparatus: Arduino Nano trainer kit, LDR sensor, LED, connecting wires
Circuit diagram:
1. Connect the analog Output of LDR sensor with A3 pin of Arduino Nano.
2. Connect a wire to one of the LEDs L1,L2,L3,L4 on the board
3. Upload the following code to board.
Code:
#define pin A3
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
void loop() {
52
int val= analogRead(pin);Serial.println(val);
if(val>700){
// fire detected
digitalWrite(13,LOW);
Output:
Cover the LDR sensor with some object like, a cap of a pen (opaque, but not
transparent cap) and create darkness. This will switch on the LED on Pin13. When
light is shined/brightness is sensed by LDR, the LED will go off.
53
Experiment 12: 12. Fire Alarm Using Arduino
Apparatus: Thermistor, Arduino Nano and connecting wires, Soldering iron/hair drier/some
hot material.
Circuit diagram:
Code:
// R is the resistance at T kelvin temperature which can be obtained from adc value
54
//R0 is the resistance of the thermsitor at 25 degree celsius, which is the resistance
printed on the thermistor
/*
* 5*R/(10000+R)=ADC*5/1024
* R= 10000*ADC/(1024-ADC)
*/
/*
* VERSION 1.0
*/
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
55
}
float temp,x,y;
void loop() {
x=(1.00/298.15)+(1.00/3950.00)*log(1*y/(1024.00-y));
if(temp>temp_threshold){
// fire detected
Serial.println("It is on fire...");
else
digitalWrite(13,LOW);
56
float get_average(int pin){
Output:
After uploading the code to Nano, bring a hot object, close to thermistor sensor, like
soldering iron/ hair drier etc and raise the temperature to see in the serial monitor that
fire happened.
57
TRAINER BOARD USED IN THIS LAB
58