0% found this document useful (0 votes)
18 views83 pages

Iiot Lab Manual

The document outlines a series of experiments demonstrating various IoT applications using components like LoRa modules, GSM modems, MQTT protocols, and NodeMCU for home automation and soil moisture monitoring. Each experiment includes the aim, required apparatus, circuit diagrams, code snippets, and procedures to implement the projects successfully. The results confirm successful communication and control of devices using the specified technologies.

Uploaded by

chiragchiru892
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views83 pages

Iiot Lab Manual

The document outlines a series of experiments demonstrating various IoT applications using components like LoRa modules, GSM modems, MQTT protocols, and NodeMCU for home automation and soil moisture monitoring. Each experiment includes the aim, required apparatus, circuit diagrams, code snippets, and procedures to implement the projects successfully. The results confirm successful communication and control of devices using the specified technologies.

Uploaded by

chiragchiru892
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

IIOT[20EC52I] 1

Experiment-1

Demonstration of LoRAWAN communication.

Aim: To send and receive messages from long distances using the
LoRa module.

Apparatus Required:
● LoRa module.
● Nodemcu.
● Jumpers.

Circuit Diagram:

Transmitter section:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 2

PIN configuration:
1. GND-GND.
2. NSS-D8.
3. MOSI-D7.
4. MOS0-D6.
5. SCK-D5.
6. GND-GND.
7. 3.3v-3.3v.
8. GND-GND.
9. RESET-D0.
10. DIO0-D2.

Receiver Section:

PIN configuration:
1. GND-GND.
2. NSS-D8.
3. MOSI-D7.
4. MOS0-D6.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 3

5. SCK-D5.
6. GND-GND.
7. 3.3v-3.3v.
8. GND-GND.
9. RESET-D0.
10. DIO0-D2.

CODE OF TRANSMITTER AND RECEIVER SECTION:

#include <LoRa.h>
#define SS 15
#define RST 16
#define DIO0 04
#define led 02

String data = "";


bool stringComplete = false; // Whether the string is complete

void setup()
{
Serial.begin(115200);
pinMode(led,OUTPUT);
digitalWrite(led,1);
while (!Serial);
Serial.println("Device Activated");
LoRa.setPins(SS, RST, DIO0);
if (!LoRa.begin(433E6))
{
Serial.println("LoRa Error");
delay(100);
while (1);
}
data.reserve(200); // Max Number of character Sented through a
Single message
}

void loop()

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 4

{
serialEvent();
stringComplete = false;
int packetSize = LoRa.parsePacket();
if (packetSize)
{
while (LoRa.available())
{
Serial.print("Message Received : ");
Serial.println(LoRa.readString());
}
}
}

void serialEvent() {

while (Serial.available()) {
char inChar = (char)Serial.read();
data += inChar;
if (inChar == '\n')
{
stringComplete = true;
Serial.print("Sending Message: ");
Serial.println(data);
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
data="";
digitalWrite(led,0);
delay(2000);
digitalWrite(led,1);
}
}
}

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 5

Procedure:
➢ Rig up the ckt as shown in the ckt diagram.
➢ Connect all the ground pins of NODEMCU ,either the pins used or
not.
➢ Because the grounding is important to the LoRa module .
➢ Download the LoRa library in the managed library.
➢ Upload the code to the NODEMCU.
➢ Now send the message from one LoRa to another.

Result :
Communication using the LoRa module is successfully implemented.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 6

Experiment-2

Interfacing 4G GSM Modem to communicate b/w the


devices using Arduino UNO.

AIM: To interface a GSM module to transmit SMS via Arduino UNO.

APPARATUS REQUIRED:
⦁GSM module
⦁Arduino UNO
⦁SIM
⦁Jumper wires(female to male type)

CIRCUIT DIAGRAM:

PROGRAM CODE:

#include<SoftwareSerial.h>
SoftwareSerial gsm(2,3);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 7

void setup()
{
delay(1000);
Serial.begin(9600);
gsm.begin(9600);
gsm.println("AT+CMGF=1");
delay(1000);
gsm.println("AT+CMGS=\"+919880466676\"\r"); //replace x by your
number
delay(1000);
gsm.println("Good afternoon sir");
delay(100);
gsm.println((char)26);
delay(1000);
}
void loop(){ }

PROCEDURE:
● Make the connections as per the circuit diagram.
● *Connect arduino uno gnd to GSM gnd.
● *Connect GSM TX to arduino pin2.
● *Connect GSM RX to arduino pin3.
● *Insert the SIM in GSM SIM socket.
● *Give the power supply to GSM,and connect the Arduino to the
laptop via data cable.
● *Go to Arduino ide software, copy the sketch and paste in a new
file.
● *Replace your phone number and SMS in the sketch.(where you
want to have the SMS)
● *Compile and upload the sketch to Arduino uno.

RESULT: hence ,SMS is received in the device via GSM.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 8

Experiment-3
Design a simple MQTT protocol-based system. The Cloud
application should blink the LED using the MQTT protocol.

AIM: To demonstrate an experiment on and off NodeMCU led using


mqtt lens.

APPARATUS REQUIRED:
⦁NodeMCU wifi module (esp8266)
⦁Data cable
⦁System installed with Arduino IDE Software
⦁Mobile with internet access

CIRCUIT DIAGRAM:

NOTE: NodeMCU must be connected with WiFi.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 9

PROCEDURE:
● Open Arduino IDE software.
● Erase previous program and open New
file>Examples>PubSubClient(installed library from manage
library)>esp8266.

● Erase unwanted comments.


● Enter your mobile hotspot ssid,password and IP address.
● To get an IP address, go to the command prompt window,
type ping test.mosquitto.org and then enter.
● There you will get an IP address as “91.121.93.94”.
● Copy this IP address and paste it in your program.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 10

● In void reconnect,make some changes as in the picture


below.

In Void loop

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 11

● Save
● Select nodemcu board and comport.
● Compile>upload.
● Open chrome,search for mqtt lens.
● Click on Launch and then click on add connections.
● Place the hostname,type IP address and save it.
● Make changes in out topic and in topic as per below fig.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 12

● When you type o(zero) in the message and click on publish,


the NodeMCU led should get off.
● In the same way, type 1 in message and publish, the
NodeMCU led should get on.

OUTPUT:

NOTE: You can observe here. The nodemcu led is when the message is
0.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 13

Here nodemcu is led on, when the message is one.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 14

Experiment-4

Design Arduino IoT Cloud ESP8266 NodeMCU Alexa Home


Automation system.

Aim: To control appliances using Alexa assistant in Home Automation

Apparatus Required:
● NodeMCU
● Relay
● Jumper wires
● Arduino IOT cloud
● Alexa Mobile App

Circuit Diagram:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 15

1. OPEN CHROME

2. TYPE ARDUINO IOT CLOUD

3. CLICK ON THE ARDUINO CLOUD AS SHOWN

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 16

4. CLICK ON GET STARTED

5. NOW CLICK ON SIGN IN

6. AFTER SIGN IN CLICK ON THE IOT CLOUD

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 17

7. GO TO DEVICE AND CLICK ON ADD

8. NOW CLICK ON 3RD PARTY DEVI

9. NOW SELECT ESP8266 AND SELECT THE MODEL

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 18

10. GIVE THE DEVICE NAME

11. NOTE DOWN THE DEVICE ID AND SECRET KEY , THEN


CONTINUE

12. YOU GET CONGRATS PAGE CLICK ON DONE

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 19

13. NOW GO TO THINGS AND CREATE THINGS

14. IN ASSOCIATED DEVICE SELECT THE DEVICE YOU CREATED


BEFORE

15. AFTER SETTING UP associated device NOW CONFIGURE YOUR


NETWORK PROVIDING HS,PASSWORD AND SECRET ID

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 20

16. configuring network NEXT CLICK ON ADD VARIABLE

17. GIVE THE NAME (SWITCH,BULB,LED) AND SELECT ALEXA


COMPATIBILITY AND TAKE LIGHT AND CONTINUE

18 REPEAT STEP 16 UNTIL YOU ADD YOUR REQUIRED SWITCHES


OR BULBS

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 21

19. COME TO DASHBOARDS AND CLICK ON BUILD DASHBOARD

20. NOW CLICK ON ADD OPTION

21. SELECT THE SWITCHES AS MUCH AS YOU CREATED THE

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 22

VARIABLES

22. ON WIDGET GO TO SETTINGS AND GIVE NAME YOU WANT


TO , CLICK ON LINK VARIABLE AND LINK EACH VARIABLE FOR
EACH SWITCHES

23 CLICK ON DONE

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 23

24. COME TO THINGS AND DOUBLE CLICK ON THE


MODULE

25. NOW GO TO SKETCH

26. OPEN FULL EDITOR

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 24

27. NOW COPY THE CODE AND PASTE IT ON [ARDUINO


IDE]

28. CREATE THE [H] FILE FOR THE


THINGSPROPERTIRS.H AND SECRET

29 THIS ARE THE OTHER 2 CODE TO BE [H FILED]

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 25

1. GO TO PLAYSTORE 2. SEARCH ALEXA AND


DOWNLOAD

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 26

3. OPEN APP
4. GO TO DEVICE CLICK ON SYMBOL

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 27

5. CLICK ADD DEVICE


6.SELECT SKILL STORE

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 28

7. SEARCH ARDUINO
8.CLICK ON THIS OPTION

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 29

9. LOG IN WITH THE SAME ACCOUNT U DID IN WEB


10. NOW WAIT FOR SOME TIME U WILL BE CONNECTED TO YOUR
WEB DASHBOARD.

RESULT:HOME AUTOMATION USING ALEXA AND ESP8266 IS


SUCCESSFULLY IMPLEMENTED.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 30

Experiment-5

Demonstrate SOIL MOISTURE SENSOR USING BLYNK .

Aim:To monitor the moisture content in soil.

Components Required:

● Nodemcu ESP8266 board


● Soil moisture sensor
● Relay module
● Breadboard
● Jumper wires
● Mini water pump
● Mini water pipe
● 9v battery

Circuit Diagram:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 31

Code:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h> // WIFI Library

#include <BlynkSimpleEsp8266.h> // Blynk Library

char auth[] = "";//Enter your Auth token

char ssid[] = "Redmi Note 11";//Enter your WIFI name

char pass[] = "........";//Enter your WIFI password

BlynkTimer timer;

bool Relay = 0;

//Define component pins

#define sensor A0 //A0 pin node mcu

#define waterPump D3 //D3 pin node mcu

void setup() {

Serial.begin(9600);

pinMode(waterPump, OUTPUT);

digitalWrite(waterPump, HIGH);

Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

//Call the function

timer.setInterval(100L, soilMoistureSensor);

BLYNK_WRITE(V1) {

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 32

Relay = param.asInt();

if (Relay == 1) {

digitalWrite(waterPump, LOW);

Serial.println("Motor is ON "); //To turn on&off motor

} else {

digitalWrite(waterPump, HIGH);

Serial.println("Motor is ON ");

void soilMoistureSensor() {

int value = analogRead(sensor);

value = map(value, 0, 1024, 0, 100); //Get the soil moisture values

value = (value - 100) * -1;

Blynk.virtualWrite(V0, value);

void loop() {

Blynk.run();//Run the Blynk library

timer.run();//Run the Blynk timer

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 33

Procedure:

Step 1

Firstly, identify these components.

Step 2

Second, place the Nodemcu board on the breadboard and connect the
VIN and GND pins to the breadboard.

Step 3

Thirdly, place the soil moisture sensor on the breadboard and connect it
to the Nodemcu board. For that, use the circuit diagram below.

Step 4

Now, let’s create the Blynk web dashboard for this project. For that,
follow the steps below.

● First, go to the Blynk website and create a new account using your
Gmail address. And then, sign in to your account and click the new
Template button. Next, enter your project name as you like and
click the done button.

Now, click the “Datastreams” tab and create two data streams for that.
Use the information below.

● Virtual PIN –> Name – Moisture value / PIN — V0 / MIN — 0 / MAX


— 100
● Virtual PIN –> Name – Water pump / PIN — V1 / MIN — 0 / MAX —
1

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 34

Next, click the “Web dashboard” tab and include the one button and one
Gauge widget to the dashboard. And then, arrange these widgets as you
like.

● Now, click the one-by-one settings buttons on these widgets and


select the data streams we created earlier. After, click the save
button.
● Now, click the search icon button and create a “New device”. For
that, select the template you created earlier.

Step 6

Now, connect this project to the computer, and let’s upload the program
for this project.

Result:The monitoring of the soil moisture content is successfully


demonstrated.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 35

Experiment-6

Design an IoT Based Temperature and Humidity Monitoring


over ThingSpeak using ESP8266.

Aim: Interfacing DHT11 sensor with NodeMCU & Thingspeak to monitor


the Humidity and Temperature.

Apparatus Required:

● NodeMCU
● DHT11 sensor
● USB Cable
● Bread Board
● Jumper Wires
● Arduino IDE Software

Circuit Diagram:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 36

Program Code:

#include <ESP8266WiFi.h>

#include <DHT.h>

#include <ThingSpeak.h>

const char *ssid = "TVN";

const char *pass = "ndtv@1234";

long channelID = 1916325;

const char writeAPIkey[] = "6E3CKTGZCUFRRG8H";

WiFiClient client;

DHT dht(D1, DHT11);

void setup()

Serial.begin(9600);

WiFi.begin(ssid, pass);

while(WiFi.status() != WL_CONNECTED)

delay(200);

Serial.print("..");

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 37

Serial.println();

Serial.println("NodeMCU is connected!");

Serial.println(WiFi.localIP());

dht.begin();

ThingSpeak.begin(client);

void loop()

float h = dht.readHumidity();

float t = dht.readTemperature();

Serial.println("Temperature: " + (String) t);

Serial.println("Humidity: " + (String) h);

ThingSpeak.writeField(channelID, 1, t, writeAPIkey);

ThingSpeak.writeField(channelID, 2, h, writeAPIkey);

delay(2000);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 38

Procedure to use thingspeak:

Step 1: ThingSpeak Setup for Temperature and Humidity Monitoring


For creating your channel on Thingspeak, you first need to Sign up on
Thingspeak. In case if you already have an account on Thingspeak, just sign in
using your id and password.For creating your account go to
www.thinspeak.comClick on Sing up if you don’t have account and if you
already have an account, then click on sign in. After clicking on signup, fill in
your details.

After this, verify your Email id and click on continue.

Step 2: Create a Channel for Your Data

Once you Sign in after your account verification, Create a new channel by
clicking the “New Channel” button.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 39

After clicking on “New Channel”, enter the Name and Description of the data
you want to upload on this channel. For example, I am sending my DHT11 sensor
data, so I named it DHT1interfacing.
Enter the name of your data ‘Temperature’ in Field1 and ‘Humidity’ in Field2.
If you want to use more Fields, you can check the box next to Field option and
enter the name and description of your data.
After this, click on the save channel button to save your details.

Step 3: API Key


To send data to Thingspeak, we need a unique API key, which we will use later
in our code to upload our sensor data to Thingspeak Website.
Click on “API Keys” button to get your unique API key for uploading your
sensor data.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 40

Now copy your “Write API Key”. We will use this API key in our code.
After this navigate to your Thingspeak page and open your channel at
Thingspeak and output will be shown as below:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 41

Procedure:

● Make the connections as shown in the circuit diagram.


● Go to Thinkspeak and login to your account.
● Create New channel by giving appropriate name and field names and save
the channel.
● Field chart will be displayed on private view
● Open Arduino IDE software and install the library for Thingspeak and
DHT11 sensor by going to sketch →Include library→Manage
library→Search.
● Upload the program code to Arduino IDE.
● Set your SSID and Password.
● Copy the “Write API Key” code from API key section of Thingspeak and
Paste it on th
● Arduino IDE software in “String API Key”
● Select the board and Port in Arduino IDE and upload the program to
NodeMCU and open Serial Monitor and ThingSpeak .

Result: we have successfully monitored Temperature and Humidity


data over ThingSpeak using ESP8266.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 42

Experiment-7

Build an IoT Based Colour Sorting Machine using ESP8266


and ThingSpeak software.

AIM:Interfacing color sorting sensor with thingSpeak

Apparatus required:
● NodeMCU ESP8266
● TCS3200 Colour Sensor
● Jumper Wires
● USB cable for power

Circuit diagram:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 43

Colour Sensor Pin NodeMCU Pin

Vcc 3.3V

GND GND

S0 D4

S1 D5

S2 D6

S3 D7

OUT D8

OE GND

Procedure:
Step 1: Sign up
To send data to Thingspeak, a Thingspeak account is required. To do
so, navigate to the Thingspeak website

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 44

Click on the ‘Sign up’ option in the top right corner and fill out the
required details.

After that, verify the E-mail id and click on continue.

Step 2: Create a Channel to Visualize Data

Now as you are logged in to your account, create a new channel by


clicking the “New Channel” button.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 45

After clicking on “New Channel” enter the Name and Description of the
data you want to upload on this channel.

Enter the name of data in Field1, Field2, Field3, and Field4. If you want to
use more field than two, then you can check the box next to the Field
option and enter the name and description of the channel.

After that, click on the ‘Save Channel’ button to complete the channel
creation process.

Thingspeak usually shows data in Graph format, but it also provides an


option to visualize data using different widgets. To add a widget, click on

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 46

the ‘Add Widgets’ option and choose the widget you want to use. In this
project, I am using the ‘Numeric Display’ widget.

Step 3: API Key

To send data to ThingSpeak, we need a unique API key, which we will


use later in code to send the data to ThingSpeak Website.

Click on the “API Keys” option to get a unique API key for uploading
sensor data. Now copy “Write API Key.”

Sketch:
#include <ESP8266WiFi.h>

#include <WiFiClient.h>;

#include <ThingSpeak.h>;

const char * myWriteAPIKey = "N9XH6CUX17SW6UMR"; //api key

unsigned long myChannelNumber = 2003179; //channel number

const char *ssid = "POCO M2 Pro"; // Enter your WiFi Name

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 47

const char *pass = "11223344"; // Enter your WiFi Password

WiFiClient client

const int s0 = D4;

const int s1 = D5;

const int s2 = D6;

const int s3 = D7;

const int out = D8;

int red = 0;

int green = 0;

int blue = 0;

int color=0;

int redcolor = 0;

int greencolor = 0;

int orangecolor = 0;

int yellowcolor = 0;

void setup()

Serial.begin(9600);

pinMode(s0, OUTPUT);

pinMode(s1, OUTPUT);

pinMode(s2, OUTPUT);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 48

pinMode(s3, OUTPUT);

pinMode(out, INPUT);

digitalWrite(s0, HIGH);

digitalWrite(s1, HIGH);

ThingSpeak.begin(client);

Serial.println("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)

delay(550);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected");

void loop()

digitalWrite(s2, LOW);

digitalWrite(s3, LOW);

red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 49

digitalWrite(s3, HIGH);

blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

digitalWrite(s2, HIGH);

green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

Serial.print("R Intensity:");

Serial.print(red, DEC);

Serial.print(" G Intensity: ");

Serial.print(green, DEC);

Serial.print(" B Intensity : ");

Serial.print(blue, DEC);

if(red<39 & red>29 & green<93 & green>83 &blue<78 & blue>69){

redcolor++;

Serial.print("Red");

ThingSpeak.writeField(myChannelNumber, 1,redcolor,
myWriteAPIKey);

if(green<75 & green>65 & blue<68 &blue>60){

orangecolor++;

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 50

Serial.print("Orange");

ThingSpeak.writeField(myChannelNumber, 2,orangecolor,
myWriteAPIKey);

if(red<46 & red>36 & green<46 & green>37){

greencolor++;

Serial.print("Green");

ThingSpeak.writeField(myChannelNumber, 3,greencolor,
myWriteAPIKey);

if(red<34 & red>25 & green<37 & green>28 & blue<53 & blue>43){

yellowcolor++;

Serial.print("Yellow");

ThingSpeak.writeField(myChannelNumber, 4,yellowcolor,
myWriteAPIKey);

Serial.println();

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 51

Result:Successfully interfaced color sorting sensor with thingspeak.

Output:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 52

Experiment-8

Design and analysis of IoT Based Smart Car Parking


System Using Arduino, NodeMCU& Blynk app.

Aim : Implement the car parking system using Arduino uno and IR
sensor.

Apparatus Required:
● IR Sensor
● Servo motor
● LCD Display 16x12 screen
● Arduino boar (UNO)
● Jumper wires

Circuit Diagram:

Procedure:
1. Connections to be made as per the circuit diagram

2. Open Arduino ide software

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 53

3. Paste the lcd display program on Arduino ide software we get the
address in serial monitor

1. Open serial monitor and copy the I2C address of lcd display

2. Open the main program of car parking system paste the address to the
LiquidCrystal_I2C lcd(0x27,16, 2);

3. Go to the tools select the manage library in that install the library
LiquidCrystal_I2C ,wire.h ,servo

4. After go to the board and select Arduino UNO select the serial comport

5. Then upload the program

6. Connection

LCD DISPLAY I2C 16x2 screen

Gnd ,Gnd

Vcc , 5V

SDA, A4

SCD ,A5

IR SENSOR //entering sensor

VCC ,5V

GND ,GND

DATA, 2

IR SENSOR //existing sensor

VCC ,5V

GND ,GND

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 54

DATA, 4

SERVO MOTOR

VCC, 5V

GND ,GND

DATA, 3

IR SENSOR //parking slot 1

VCC ,5V

GND ,GND

DATA, 5

IR SENSOR //parking slot 2

VCC 5V

GND GND

DATA 6

CODE // TO FIND LCD ADDRESS


#include <Wire.h> //LIBRARY TO BE INSTALLED

void setup()

Wire.begin();

Serial.begin(9600);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 55

Serial.println("\nI2C Scanner");

void loop()

byte error, address;

int Devices;

Serial.println("Scanning...");

Devices = 0;

for(address = 1; address < 127; address++ )

Wire.beginTransmission(address);

error = Wire.endTransmission();

if (error == 0)

Serial.print("I2C device found at address 0x");

if (address<16)

Serial.print("0");

Serial.print(address,HEX);

Serial.println(" !");

Devices++;

else if (error==4)

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 56

Serial.print("Unknown error at address 0x");

if (address<16)

Serial.print("0");

Serial.println(address,HEX);

if (Devices == 0)

Serial.println("No I2C devices found\n");

else

Serial.println("done\n");

delay(5000);

CODE // CAR PARKING SYSTEM


#include <Servo.h> //LIBRARY TO BE INSTALLED

#include <Wire.h> //LIBRARY TO BE INSTALLED

#include <LiquidCrystal_I2C.h> //LIBRARY TO BE INSTALLED

LiquidCrystal_I2C lcd(0x27,16, 2); ///paste the address copied

Servo myservo;

#define ir_enter 2

#define ir_back 4

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 57

#define ir_car1 5

#define ir_car2 6

#define ir_car3 7

#define ir_car4 8

int S1 = 0, S2 = 0, S3 = 0, S4 = 0;

int flag1 = 0, flag2 = 0;

int slot = 4;

void setup() {

Serial.begin(9600);

pinMode(ir_car1, INPUT);

pinMode(ir_car2, INPUT);

pinMode(ir_car3, INPUT);

pinMode(ir_car4, INPUT);

pinMode(ir_enter, INPUT);

pinMode(ir_back, INPUT);

myservo.attach(3);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 58

myservo.write(90);

lcd.init();

lcd.backlight();

lcd.setCursor (0, 1);

lcd.print(" Hi Welcome To ");

lcd.setCursor (0, 2);

lcd.print(" JustDoElectronics");

delay (5000);

lcd.clear();

lcd.setCursor (0, 0);

lcd.print(" Today's Project ");

lcd.setCursor (0, 1);

lcd.print(" Car Parking ");

lcd.setCursor (0, 2);

lcd.print(" System ");

delay (5000);

lcd.clear();

Read_Sensor();

int total = S1 + S2 + S3 + S4;

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 59

slot = slot - total;

void loop() {

Read_Sensor();

lcd.setCursor (0, 0);

lcd.print(" Available Slot: ");

lcd.print(slot);

lcd.print(" ");

lcd.setCursor (0, 1);

if (S1 == 1) {

lcd.print("S1:Full ");

else {

lcd.print("S1:Empty");

lcd.setCursor (11, 1);

if (S2 == 1) {

lcd.print("S2:Full ");

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 60

else {

lcd.print("S2:Empty");

lcd.setCursor (0, 2);

if (S3 == 1) {

lcd.print("S3:Full ");

else {

lcd.print("S3:Empty");

lcd.setCursor (11, 2);

if (S4 == 1) {

lcd.print("S4:Full ");

else {

lcd.print("S4:Empty");

if (digitalRead (ir_enter) == 0 && flag1 == 0) {

if (slot > 0) {

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 61

flag1 = 1;

if (flag2 == 0) {

myservo.write(180);

slot = slot - 1;

} else {

lcd.setCursor (0, 0);

lcd.print(" Sorry Parking Full ");

delay(1500);

if (digitalRead (ir_back) == 0 && flag2 == 0) {

flag2 = 1;

if (flag1 == 0) {

myservo.write(180);

slot = slot + 1;

if (flag1 == 1 && flag2 == 1) {

delay (1000);

myservo.write(90);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 62

flag1 = 0, flag2 = 0;

delay(1);

void Read_Sensor() {

S1 = 0, S2 = 0, S3 = 0, S4 = 0;

if (digitalRead(ir_car1) == 0) {

S1 = 1;

if (digitalRead(ir_car2) == 0) {

S2 = 1;

if (digitalRead(ir_car3) == 0) {

S3 = 1;

if (digitalRead(ir_car4) == 0) {

S4 = 1;

Result: Car parking system is implemented successfully.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 63

Experiment-9

SIMULATE THE NETWORK COMMUNICATION OF PEER


TO PEER.

AIM :To simulate peer to peer communication

APPARATUS REQUIRED :
● CISCO PACKET TRACER SOFTWARE.

Circuit Diagram:

PROCEDURE:
● Open cisco packet tracer software .
● Create a new file .
● Rig up the circuit as shown in circuit diagram.
● Select end devices and select or pick two PCs.
● Select connection( shock symbol) pick cooper cross over it will
automatically connect with two PCs.
● Click on PC0 select configure click fastethernet.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 64

● Go to IP Configure in place of IPv4 write “ 192.168.0.1” now the


subnet mask will automatically update “255.255.255.0”.
● Same procedure click on PC1 select configure click fastethernet.
● IPv4 writes “192.168.0.2” now the subnet mask will automatically
update “255.255.255.0”.
● Click on the message box drag and drop message to both PCs.
● Run the simulation.
● Now they communicate with each other.

RESULT: SIMULATING PEER TO PEER COMMUNICATION


SUCCESSFULLY DONE.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 65

Experiment-10

SIMULATE THE NETWORK COMMUNICATION OF HUB

AIM :To simulate HUB communication

APPARATUS REQUIRED :
● CISCO PACKET TRACER SOFTWARE.

Circuit Diagram:

PROCEDURE:
● Open cisco packet tracer software .
● Create a new file .
● Rig up the circuit as shown in circuit diagram.
● Select the pt-hub
● Select the different pc’s
● Select the fast ethernet 0 to pc0 fast ethernet 0
● Select the fast ethernet 1 to pc1 fast ethernet 1
● Select the fast ethernet 2 to pc2 fast ethernet 2
● Select the fast ethernet 3 to pc3 fast ethernet 3
● Select the fast ethernet 4 to pc4 fast ethernet 4
● Go to desktop select ip configuration edit ip address
● pc0=10.10.10.0

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 66

● pc1=10.10.10.1
● pc2=10.10.10.2
● pc3=10.10.10.3
● pc4=10.10.10.4
● Run the simulation.

RESULT: SIMULATING HUB SUCCESSFULLY DONE.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 67

Experiment-11

SIMULATE THE NETWORK COMMUNICATION OF HOME


AUTOMATION.

AIM :To simulate Home Automation

APPARATUS REQUIRED :
● CISCO PACKET TRACER SOFTWARE.

Circuit Diagram:

PROCEDURE:
●Open cisco packet tracer software .
●Create a new file .
●Rig up the circuit as shown in circuit diagram.
●Select the home gateway
●Select the different equipments
●And select the smartphone
●On next click on different equipments select the “HOME
GATEWAY”
● On next click on smart phone and next configure and click on
wireless0 change the SSID to HOME GATEWAY
● Go to the desktop and click on the iot monitor ..login. Analyse the
output
RESULT: SIMULATING HOME AUTOMATION SUCCESSFULLY
DONE.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 68

Experiment-12

PEER TO PEER CONNECTION USING ROUTER AND


SWITCH

AIM :TO SIMULATE PEER TO PEER CONNECTION USING


ROUTER AND SWITCH

APPARATUS REQUIRED :
● CISCO PACKET TRACER SOFTWARE.

Circuit Diagram:

PROCEDURE:
● Open cisco packet tracer software .
● Create a new file .
● Rig up the circuit as shown in circuit diagram.
● Select the 4 different PC’S
● PT- Router And PT-Switch
● And adjust the above figure
● Give default IP-Address for
● PC’S =192.168.1.0
● PC’S =192.168.2.0
● PT-Router =10.12.1.0
● Go to desktop select the IP Configuration Edit the IP Address for
IPv4 in PC’s
● PC 0=192.168.1.2

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 69

● PC 1=192.168.1.3
● PC 2=192.168.2.2
● PC 3=192.168.2.3
● Now click on subnet mask after each IP Address assigned in a PC
and even edit the Default gate address of four different pcs
● pc0=192.168.1.1
● pc1=192.168.1.1
● pc2=192.168.2.1
● pc3=192.168.2.1
● On next click on PT-Router and edit the
fastethernet0/0=192.168.1.1
● On next click on PT-Router and edit the
fastethernet0/0=192.168.2.1
● On next click on PT-Router and edit the Serial 2/0=10.12.1.1
● On next click on PT-Router and edit the Serial 2/0=10.12.1.2
● On next click on PT-Router and edit the RIP=192.168.1.0
● =10.12.1.0
● On next click on PT-Router and edit the RIP=192.168.2.0
● =10.12.2.0
● Run the simulation.

RESULT: SIMULATING PEER TO PEER CONNECTION USING


ROUTER AND SWITCH SUCCESSFULLY DONE.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 70

Experiment-13
Design an IoT based Water Level Indicator Model Using
Ultrasonic Sensor, NodeMCU and display the water level
on the web server.

Aim:To monitor the water level indicator in MQTT server using


Ultrasonic Sensor, NodeMCU.

Apparatus Required:
● NodeMCU.
● Ultrasonic Sensor.
● Jumpers.

Circuit Diagram:

Procedure:
● Open arduino Ide libraries > Pub sub client->Install
● Go to examples → Pubsub client -> MQTT ESP8266 -> Now our
codes will visible
● add Hotspot name & Password
● Which you have connect through wifi
● Assign value for trigPin as 4
● And assign value for echoPin as 5
● Go to Search → Command prompt -> Type Cmd

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 71

● In CMD → Type → Ping Test.mosquillo.ORG


● Now the IP address will visible
● 91.121.93.94
● add IP address
● Now. Go to void reconnect [in program]
● Clients publish change to "ultra", "mqtt connection successfully "
● Clients subscribe change to "ledman"
Select pinMode(echoPin i/p)
● Select pinMode(trigPin o/p)
● In snprintf change to "Ultrasonicdistancevalue:%d , distance "
● Serial.println "distance"
● Serial.publish ("ultra",msg)
● Go to Chrome → MQTT app→ launch app
● Add connection→ name....→ IP address→ save.
● And view the o/p.

Code:
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const int trigPin=4; // transmitter


const int echoPin=5; // receiver

long duration;
int distance;

// Update these with values suitable for your network.

const char* ssid = "vivo 1920";


const char* password = "ashwinims";
const char* mqtt_server = "91.121.93.94";

WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 72

char msg[MSG_BUFFER_SIZE];
int value = 0;

void setup_wifi()
{ //connect wifi to nodemcu

delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)


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

randomSeed(micros());

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length)


{ // resp for publish the data
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 73

}
Serial.println();

// Switch on the LED if an 1 was received as first character


if ((char)payload[0] == '1')
{
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that
LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
} else
{
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the
voltage HIGH
}

void reconnect()
{
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str()))
{
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("ultra", "mqtt connection is successfull");
// ... and resubscribe
client.subscribe("ledman");
}
else
{

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 74

Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void setup()
{
pinMode(echoPin,INPUT);
pinMode(trigPin,OUTPUT);
// timer.setInterval(2000L,myTimer);
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin
as an output
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}

void loop()
{

if (!client.connected())
{
reconnect();
}
client.loop();

digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 75

duration=pulseIn(echoPin,HIGH);
distance=duration*0.034/2; //0.034 velocity of sound, /2 to get one way
distance

snprintf (msg, MSG_BUFFER_SIZE, "Ultrasonic distance value : %d",


distance);
Serial.print("Publish message: ");
Serial.println(distance);
client.publish("ultra", msg);
delay(500);
}
Results : Thus, verified the o/p Ultrasonic sensor (distance Sensor or
water level controller) using MQTT platform.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 76

Experiment-14
Design home automation using Blynk IoT platform.

Aim:To remote control the home appliances or device.

Apparatus Required:
● Nodemcu board
● Relay module
● Bulb holder
● Bulb
● Plug
● Wires
● Breadboard
● Jumper wires

Circuit Diagram:

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 77

Procedure:

1. connect the Nodemcu board to the breadboard.


2. connect the bulb holders to the relay module. For that, use the
circuit diagram below.
3. connect the plug top to the 230VAC input point.
4. Now connect the relay module to the Nodemcu board using the
jumper wires. For that, use the circuit diagram above. Next,
connect it to the computer.
5. Now, let’s set up the Blynk web application step by step. For that,
follow the instructions below.
6. First, go to the Blynk official website using your browser. Then
login to this site using your email and password
7. Next, click the template button and create a new template . For
that, name it as you like. Also, select the hardware as ESP8266 and
the connection as WIFI.
8. Then, click the “Datastreams” tab and create two Data Streams as
VitualPin. Also, set the first pin and the second pin to V0 and V1.
Then, select the data type as an integer.
9. Now, click on the Web Dashboard tab. Then, drag and drop two
buttons to the dashboard. Next, click the setting icon in the button
and select the datastream we created earlier. That is, V0 for button
one and V1 for button two. Finally click the save button.
10. Next, click the Search Icon button. After, click the New
Devices button and after click the “From template” button. Finally,
select the template we created earlier.
11. OK, now let’s create the program for this project. It’s as
follows.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 78

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

//Define the relay pins

#define relay1 D0

#define relay2 D1

#define BLYNK_AUTH_TOKEN "a1mpbSOauqF3KigNd1yn6rrJETjMFvee"


//Enter your blynk auth token

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "Redmi 9 Prime";//Enter your WIFI name

char pass[] = "123456780";//Enter your WIFI password

//Get the button values

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 79

BLYNK_WRITE(V0) {

bool value1 = param.asInt();

// Check these values and turn the relay1 ON and OFF

if (value1 == 1) {

digitalWrite(relay1, LOW);

} else {

digitalWrite(relay1, HIGH);

//Get the button values

BLYNK_WRITE(V1) {

bool value2 = param.asInt();

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 80

// Check these values and turn the relay1 ON and OFF

if (value2 == 1) {

digitalWrite(relay2, LOW);

} else {

digitalWrite(relay2, HIGH);

}}

void setup() {

//Set the relay pins as output pins

pinMode(relay1, OUTPUT);

pinMode(relay2, OUTPUT);

// Turn OFF the relay

digitalWrite(relay1, HIGH);

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 81

digitalWrite(relay2, HIGH);

//Initialize the Blynk library

Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);}

void loop() {

//Run the Blynk library

Blynk.run();

● Now, copy and paste the Blynk auth token. To do this, check the
“Device Info” tab of your Blynk web application.
● Next, enter your correct WIFI name and password.
● Now, select the board and port. Then, upload this program to the
Nodemcu board.
● OK, now let’s set up the Blynk mobile dashboard. For that, follow
the instructions below.
● First, download and install the Blynk app on your phone. Then, run
this application. Now, you can see the template we created earlier.
Next, click this template and set up your dashboard.
● Now, click the upper right corner button and include the two
buttons to the dashboard. Then, arrange these widgets as you like.
● Next, click the buttons one by one and select the detastreams V0
and V1 respectively. Also, select the mode as a switch.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 82

● Now, connect the 5 VDC external power supply to the Nodemcu


board. For that, use the circuit diagram above.
● Finally, put the bulbs to the holders and connect the plug top to the
AC voltage.
● OK, now you can operate these relays using the web or mobile
dashboard.

Output:

Result:Successfully remote control of two bulbs using blynk


server.

Sri Jayachamarajendra Govt Polytechnic E&C Department


IIOT[20EC52I] 83

Sri Jayachamarajendra Govt Polytechnic E&C Department

You might also like