Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
PRACTICAL NO: 06
AIM:- To Implement ESP-8266-12F Module as Arduino Cloud IoT
OBJECTIVES:
1. Overview of ESP8266 NOD MCU Module
2. How sensor data display on monitor using serial communication?
3. Communication protocols and Access control system in IoT Application
4. Moisture sensor and NOD MCU using HTTP application Protocol.
Introduction
The progressive development in fabrication technology offer best microcontrollers to user community.
The race has been started for producing 4 bit microcontrollers to 32 bits, 64 bits, 128 bits and still
continues. Almost all microcontrollers are embedded with peripheral supports like communication,
Timers, Memory, I/O modules and data conversion etc to enhances its operation capabilities. During
the late 1980 to 2010 embedded microcontrollers based development and design tools implemented to
various domains including aerospace to navigation system and it has captured 80% of markets. The
limitations of all these embedded controllers are the need of knowledge of sophisticated codes and
programming methods, cost as well as the barrier of paid source platform.
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino
boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it
into an output - activating a motor, turning on an LED, publishing something online.
Rationale:
Industry always updates its working environment with latest available resources. Recent development
in computing technology and supporting hardware pointed out the dot in today’s industry environment
52 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
for all the researchers and developers. Advancement in Big data, Cloud Computing and data analytics
make huge impact on Industrial environment to replace conventional operating infrastructure with
better, smarter and easily connected facilities. An Arduino based development board’s play vibrant role
in Industry as Internet of things –IoT, but it has few constrains like size, space, reliability, programming
and connectivity
.
Fig-1: Wireless Sensor Node Architecture
Recently Chinese based Espressif system introduce ESP-12 type microcontroller having a low-cost
open source IoT platform as a NodeMCU which runs on the ESP8266 WI-FI SoC.(System on Chip).
NodeMCU is an open source firmware for which open source prototyping board designs are available.
The limitation of IoT devices in Industrial application is compensated by using NodeMCU board and
identified as Industrial IoT or IIoT.
What is Firmware?
Firmware is a software program or set of instructions programmed on a hardware device. It provides
the necessary instructions for how the device communicates with the other computer hardware.
Firmware is typically stored in FLASH ROM of the hardware device and will be updated if any
changes made occur. Both the firmware and prototyping board designs are open source.
ESP8266 NODE MCU
The NodeMCU (Node MicroController Unit) is open-source software and hardware development
environment built around an inexpensive System-on-a-Chip (SoC) called the ESP8266. The ESP8266,
designed and manufactured by Espressif Systems, contains the crucial elements of a computer: CPU,
RAM, networking (Wi-Fi), and even a modern operating system and SDK. That makes it an excellent
choice for Industrial Internet of Things (IoT) projects of all kinds.
53 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
It contains a built-in 32-bit low-power CPU, ROM and RAM. The module embedded with a L106 32-
bit RISC microprocessor core and comes fitted with an AT Command firmware that can be used with
any MCU via COM port. It has 16 GPIO pins. On the memory front, it has 32 KB instruction RAM, 32
KB instruction cache RAM, 80 KB user-data RAM and 16 KB ETS system-data RAM. Other features
include WEP or WPA/WPA2 authentication.
Specification & Pin Diagram of ESP8266
ESP 8266 module embedded with 32 bit RISC microcontroller based CPU operates on 3.3 V using 7-12
V input voltage. Modules have 16 Digital I/O (DIO) pins and 1 Analog Input Pin. It also equipped with
USART, SPI and I2C comm. Protocols. 4MB Flash and 64KB SRAM Onboard memory is available.
The module clock speed is 80 MHz with USB-TTL based CP2102 is included on board enabling plug
and play operation. To communicate wirelessly module use PCB Antenna. All these feature, ultimately
clubbed in small sized module which fits smart IoT Application.
Fig-2 Pin diagram of ESP8266 Node MCU
Programming NodeMCU with Arduino IDE
The NodeMCU Development Board can be easily programmed using the Arduino IDE since it is easy
to use. Programming NodeMCU with the Arduino IDE will hardly take 10-20 minutes. All you need is
54 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
the latest version of the Arduino IDE, a USB cable, and the NodeMCU board itself. You can check
this Getting Started Tutorial for NodeMCU to prepare your Arduino IDE for NodeMCU.
NodeMCU You can also
check my getting started tutorial for ESP32 Wi-Fi + Bluetooth Module to prepare your Arduino IDE for
the ESP32 module.
Required Hardware
ESP8266-based
based board or Arduino board with internet connection (NodeMCU ESP8266-12E
ESP8266 used for
this demonstration)
Soil moisture sensor
Jumper wires (at least 4)
USB cable
Connect the Node MCU RST pin to Moisture sensor pin D0, to enable wake up from deep sleep.
Soil Moisture Sensor
The soil moisture sensor consists of two probes which are used to measure the volumetric content of
water. The two probes allow the current to pass through the soil and then it gets the resistance value to
measure the moisture value. When there is more wat
water,
er, the soil will conduct more electricity which
means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts
electricity poorly, so when there will be less water, then the soil will conduct less electricity which
whi
means that there will be more resistance. Therefore, the moisture level will be lower.
Fig-4:: Working of Soil Moisture Sensor
Fig-3:: Soil Moisture Sensor
55 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
Working of Soil Moisture Sensor
The figure-4 shows the working principle of the soil moisture sensor. Soil moisture sensor has two
conducting plates. First plate is connected to the +5Volt supply through series resistance of 10K ohm
and second plate is connected directly to the ground. It simply acts as a voltage divider bias network,
and output is taken directly from the first terminal of the sensor pin, which is shown in figure above.
The output will change in the range of 0 – 5 Volt, in proportion with change in content of water in the
soil. Ideally, when there is zero moisture in soil, the sensor acts as open circuit i.e. infinite resistance.
For this condition, we get 5V at the output.
Interfacing Diagram
The soil moisture sensor is powered by the NodeMCU pin no. 5 (GND) and pin no. 6 (3.3V). When it
output pin connect to Pin No A0 (ADC0). Here, the analog output of the soil moisture sensor is
processed using ADC.
Fig-5: Interfacing of Soil Moisture Sensor with NodeMCU
The moisture content in terms of percentage is displayed on the monitor. The output of the soil moisture
sensor changes in the range of ADC values from 0 to 1023. This can be represented as moisture value
in terms of percentage using the formula given below.
Analog Output = ADC Value / 1023
Moisture in percentage = 100 – (Analog output * 100)
For zero moisture, we get the maximum value of 10-bit ADC, i.e. 1023. This in turn gives ~0%
We can write codes for NodeMCU Development Kit in either Lua Script (ESPlorer IDE) or C/C++
language (Arduino IDE).
56 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
2. How sensor data display on monitor using serial communication?
We have to configure the UART pin for serial communication so soil moisture value to be logged in
system Monitor. We keep baud rate equal to 9600 for serial transmission. Monitor will display moisture
value in percentage. Figure 6 show the codes of the program and figure -7 gives Arduino Serial monitor
output window for Soil Moisture
Fig-6: Program Codes of Soil moisture value in Arduino IDE
Fig-7: Display Window
57 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
Communication Protocols and Access Control Systems in IoT Environments
Due to the growth of the IoT-based environments and their heterogeneity, many methods for the
communication of devices have been proposed, with different degrees of standardization.
Communication protocols can be classified using different criteria as Infrastructure Protocols, Service
Discovery Protocols and Application Protocols.
The network infrastructure can also be divided into a physical, link, and network layer. Protocols
such as Institute of Electrical and Electronics Engineers (IEEE) 802.15.4 (physical and link layer) or
Internet Protocol version 6 (IPv6) over Low power Wireless Personal Area Networks (6LoWPAN)
(network layer) can be placed in the infrastructure of IoT. Also, the IPv6 Routing Protocol for Low-
Power and Lossy Networks (RPL), a routing protocol based on IPv6 and enforced by the Internet
Engineering Task Force (IETF), is the main routing protocol for sensor and IoT networks. Service
discovery protocols, such as the multicast Domain Name System (mDNS) or Domain Name System
Service Discovery (DNS-SD) are used to discover resources and services offered by IoT devices.
Finally, application protocols are used for the exchange of data between applications on top of the
IoT infrastructure. These protocols can be classified according how they organize the communication
between devices. Many of the protocols are based on a publishing/subscription mechanism, where some
devices subscribe to a communication channel, and other devices publish data in it, which are then
transmitted to the subscribers. This mechanism is well suited for IoT environments, where usually
devices need to be able to provide data without being requested like in traditional request/response
Internet protocols. The MQTT protocol, the Advanced Message Queuing Protocol (AMQP) and the
Data Distribution Service (DDS) are the main protocols of this kind:
MQTT PROTOCOLS
MQTT (Message Queuing Telemetry Transport) is a lightweight open messaging protocol that was
developed for constrained environments such as M2M (Machine to Machine) and IoT (Internet of
Things), where a small code footprint is required. MQTT is based on the Publish/Subscribe messaging
principle of publishing messages and subscribing to topics. The protocol efficiently packs messages to
minimize overhead. The MQTT specification recommends TLS as a transport option to secure the
protocol using port 8883 (secure- MQTT), as the MQTT protocol does not provide security on its own.
58 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
Fig-8: Main entities of MQTT Protocol
In MQTT protocols (refer figure-8), broker is a central server which doing routing and managing the
MQTT messages. Publishers are the entities (IoT or IIoT device) that issue messages to subscribing
entities through the Broker. Subscribers are the entities that receive messages through the Broker.
They are subscribed to a topic in the Broker, and receive the messages related to it. An entity can be
both a publisher and subscriber.
The Hypertext Transfer Protocol (HPTT) is an application protocol for distributed, collaborative,
hypermedia information systems that allows users to communicate data on the World Wide Web.
HTTP was invented alongside HTML to create the first interactive, text-based web browser: the
original World Wide Web. Today, the protocol remains one of the primary means of using internet.
Fig-9: HTTP Protocols
59 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
4. Moisture sensor and NOD MCU using HTTP POST Requests to Channel of ThingSpeak™
Internet of Things (IoT) describes an emerging trend where a large number of embedded
devices (things) are connected to the Internet. These connected devices communicate with people and
other things and often provide sensor data to cloud storage and cloud computing resources where the
data is processed and analyzed to gain important insights. The main objective of this trend is cheap
cloud computing power and increased device connectivity.
IoT solutions are built for many vertical applications such as environmental monitoring and control,
health monitoring, vehicle fleet monitoring, industrial monitoring and control, and home automation.
What is ThingSpeak™?
ThingSpeak™ is an IoT analytics platform service that allows us to aggregate, visualize and analyze
live data streams in the cloud. ThingSpeak provides instant visualizations of data posted by your
devices to ThingSpeak. With the ability to execute MATLAB® code in ThingSpeak you can perform
online analysis and processing of the data as it comes in. ThingSpeak is often used for prototyping and
proof of concept IoT systems that require analytics.
Fig-10: Concepts of ThingSpeak™ based cloud Platform for IoT
Here we are evaluates how to post fields of data to a ThingSpeak™ channel from a device that sense by
embedded sensors. Our Soil moisture posts the information of soil moisture to a ThingSpeak channel.
ThingSpeak platform support HTTP protocols instead of MQTT in IoT communication. IoT devices
like NOD MCU 8266 post request is executed by writing to a communication client without a separate
library. Directly writing the HTTP request to the wireless network client can offer increased flexibility
and speed over the ThingSpeak™ Communication Library.
60 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
In this example, the onboard ADC reads a moisture sensor and posts the value and the elapsed time to
two fields of a ThingSpeak channel. You can modify the POST to fill up to eight fields with data.
The figure-9 shows plant with a moisture sensor wired to a Node MCU ESP8266-12. The Node MCU
provides a wireless network connection. The moisture sensor is powered by a data pin on the board,
which limits the time the sensor power is on. This design reduces power and extends the life of the
sensor. In between measurements, the whole device is put into deep-sleep mode to save power. Once
data is posted to the channel, you can set up reactions to the data. For example, you can set the React
app to notify you that the moisture level is low.
Fig-11: IoT device (Nod MCU) with Sensor
Prerequisites
1) Create a ThingSpeak channel, as shown in Collect Data in a New Channel.
2) On the Channel Settings tab, enable field 1. You can provide an informative field name such
as Moisture Value.
3) Note the write API key from the API Keys tab. You need this value in the code used for
programming your device. For additional information, see Channel Configurations and Channel
Properties.
61 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
Fig-12: Soil Monitoring on ThingSpeak™ channel
Fig-13: ThingSpeak™ channel setting
62 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
Required Hardware
ESP8266-based board or Arduino board with internet connection (NodeMCU ESP8266-12E used for
this demonstration)
Soil moisture sensor
Jumper wires (at least 4)
USB cable
Lab Assignment
The Student shall implement ESP module on Blynk IoT platform. Refer the procedure
and necessary operation for integrating the said application.
Conclusion:
Assignments:
1. Brief the limitation of HTTP protocols over IoT application.
2. List the names of at least 4 free domains which offer IoT cloud platforms.
63 | P a g e
3161716: Industry 4.0