You are on page 1of 40

UNIVERSITY INSTITUTE OF ENGINEERING

AND TECHNOLOGY , CHANDIGARH

SUMMER TRAINING REPORT

TOPIC: IOT BASED EMBEDDED SYSTEM

SUBMITTED TO: SUBMITTED BY:

Ms. HARVINDER KAUR SANDHYA KUMARI


ROLL No-UE165101
ECE ,SEC-2
Declaration……………………………………………………………….

Acknowledgement........................................................................................................................

1. Introduction

1.1 About Electrowaves Electronics Company……………………………………2

1.2 History…………………………………………………………………….2

1.3 Research at EWE………………………………………………………2

2. Technologies Used

2.1 Internet of Things………………………………………… 3

2.1.1 How IoT works…………………………………4

3. Hardware Used

3.1 NODE MCU…………………………………………….. 5

3.2 ARDUINO UNO……………………………………………… 6

3.3 PIC MICROCONTROLLER…………………………………. 7

4. SOFTWARE USED......................................................................................................................

4.1 EMBEDDED SYSTEMS PROGRAMMING IN C LANGUAGE.................................7

4.1.1 The basic additional features of the embedded software………………. 8

4.2 microC 10

4.3 MPLAB IPE 11

5 INTRODUCTION TO UART COMMUNICATION ……………………………….. 12

5.1 HOW UART WORKS …………………………………..14

5.2 STEPS OF UART TRANSMISSION ………………………. 16

5.3 ADVANTAGES AND DISADVANTAGES OF UARTS …………………..17

6 AT COMMANDS ………………………………………………18

7 About the project at EWE Research and development centre: ……………………20


7.1 Creating a Wi-Fi Connection using ESP 8266 as an interface between Arduino Uno and
the access point:…………………………………………… 20

7.2 Creating a web server using ESP8266 …………………………. 23

7.3 PIC communication with ESP 8266 and LCD……………………………..28


5
1. INTRODUCTION

1.1 About Electrowaves Electronics Company:

Electrowaves Electronics (P) Ltd can trace its roots to the early days of power electronics in
India. Electrowaves Electronics was founded in 1999 for the manufacture of stand alone UPS
systems and Domestic Inverters at Parwanoo in the state of Himachal Pradesh. M/s
Electrowaves Electronics (P) Ltd was upgraded time to time and started to manufacture
power converters for Railway Industry, Electrical Panels, Railway Fans and LED Lights for
Rail applications during the course of time. The unit is equipped with latest CNC machines
and has the capacity and capability for manufacture of sheet metal fabrication, Magnetics,
PCB assembly, Tools and Dies etc. in house.

Electrowaves designs are backed by almost 20 years of field experience and thousands of
installations across India. The test and inspection departments are equipped with all modern
test facilities. Electrowaves has access to additional certified facilities for Environmental,
Shock & Vibration and EMI to name few for producing quality products as required by
Railways. Electrowaves entered in to manufacturing of LED lights during the year 2015 and
has emerged as a leading manufacturer of all types of LED lights including custom made
lights.

1.2 History:

Electrowaves Electronics was founded in 1999 for the manufacture of standalone UPS
systems and domestic inverters at Parwanoo in the State of Himachal Pradesh. M/s
Electrowaves Electronics (P)
Ltd. Was upgraded time to time and started to manufacture power converters for railway
Industry, Electrical panels, railway fas and LED lights for rail applications during the course
of time
1.3 Research at EWE:

At EWE, Research and Development has been the cornerstone of innovation for over a
century. Today, GE has around 500 technicians working at different centers for
different businesses to solve some of the India’s toughest problem. For operational
efficiency, EWE treats research as a separate business under the EWE Research &
Development Center situated in Industrial Area Phase-I, Panchkula. It is one of the
India’s largest and most diversified industrial research organizations, providing

6
innovative technology for all EWE’s businesses. It is now focused on developing
breakthrough innovations in areas such as power conversions systems, custom and
standard design of manufacturing facilities such as Sheet Metal Fabrication, Magnetics
and PCB assemblies. It is also extensively experienced in the design, manufacture and
testing of power conversion systems for railway industry. EWE Researchers are
leveraging decades of knowledge in medical imaging to develop provide electrical,
electronics and mechanical Construction facilities. Its various technical advantages are
high reliability architecture, modular construction, provision of superior state of art
technology, standard designs to industry specifications, custom designs to customer
requirements and rugged packing.

2. Technologies Used

2.1 Internet of Things

7
The internet of things, or IoT, is a system of interrelated computing devices,
mechanical and digital machines, objects, animals or people that are provided with
unique identifiers and the ability to transfer data over a network without requiring
human-to-human or human-to-computer interaction

2.1.1 How IoT works:

An IoT ecosystem consists of web-enabled smart devices that use embedded processors,
sensors and communication hardware to collect, send and act on data they acquire from their
environments. IoT devices share the sensor data they collect by connecting to an IoT gateway
or other edge device where data is either sent to the cloud to be analyzed or analyzed locally.
Sometimes, these devices communicate with other related devices and act on the information
they get from one another. The devices do most of the work without human intervention,
although people can interact with the devices -- for instance, to set them up, give them
instructions or access the data.

The connectivity, networking and communication protocols used with these web-enabled
devices largely depend on the specific IoT applications deployed .

8
9
3. Hardware Used

3.1 NODE MCU

NodeMCU is an open source development board and firmware based in the widely
used ESP8266 -12E WiFi module. It allows you to program the ESP8266 WiFi module with
the simple and powerful LUA programming language or Arduino IDE.
With just a few lines of code you can establish a WiFi connection and define input/output
pins according to your needs exactly like arduino, turning your ESP8266 into a web server
and a lot more. It is the WiFi equivalent of ethernet module. Now you have internet of things
(iot) real tool.

With its USB-TTL , the nodeMCU Dev board supports directly flashing from USB port. It
combines features of WIFI accesspoint and station + microcontroller. These features make
the NodeMCU extremly powerful tool for Wifi networking. It can be used as access point
and/or station, host a webserver or connect to internet to fetch or upload data.

10
3.2 ARDUINO UNO

Arduino is an open-source platform used for building electronics projects. Arduino consists
of both a physical programmable circuit board (often referred to as a microcontroller) and a
piece of software, or IDE (Integrated Development Environment) that runs on your computer,
used to write and upload computer code to the physical board.

The Arduino platform has become quite popular with people just starting out with electronics,
and for good reason. Unlike most previous programmable circuit boards, the Arduino does
not need a separate piece of hardware (called a programmer) in order to load new code onto
the board -- you can simply use a USB cable. Additionally, the Arduino IDE uses a simplified
version of C++, making it easier to learn to program. Finally, Arduino provides a standard
form factor that breaks out the functions of the micro-controller into a more accessible
package.

11
3.3 PIC MICROCONTROLLER

in the market ranging from PIC16F84 to PIC16C84. These types of PICs are affordable flash
PICs. Microchip has recently introduced flash chips with different PIC is a Peripheral
Interface Microcontroller which was developed in the year 1993 by the General Instruments
Microcontrollers. It is controlled by software and programmed in such a way that it performs
different tasks and controls a generation line. PIC microcontrollers are used in different new
applications such as smart phones, audio accessories and advanced medical devices.

There are many PICs available types, such as 16F628, 16F877 and 18F452. The 16F877 costs
twice the price of the old 16F84, but it is eight times more than the code size, with more
RAM and much more I/O pins, a UART, A/D converter and a lot more features.

4. SOFTWARE USED

4.1 EMBEDDED SYSTEMS PROGRAMMING IN C LANGUAGE

Embedded C Programming is the soul of the processor functioning inside each and
every embedded system we come across in our daily life, such as mobile phone, washing
machine, and digital camera.
Each processor is associated with embedded software. The first and foremost thing is the
embedded software that decides functioning of the embedded system. Embedded C language
is most frequently used to program the microcontroller.
Earlier, many embedded applications were developed using assembly level programming.
However, they did not provide portability. This disadvantage was overcome by the advent of

12
various high level languages like C, Pascal, and COBOL. However, it was the C language
that got extensive acceptance for embedded systems, and it continues to do so. The C code
written is more reliable, scalable, and portable; and in fact, much easier to understand.

4.1.1 The basic additional features of the embedded software

Data types
The data type refers to an extensive system for declaring variables of different types like
integer, character, float, etc. The embedded C software uses four data types that are used to
store data in the memory.
The ‘char’ is used to store any single character; ‘int’ is used to store integer value, and ‘float’
is used to store any precision floating point value.The size and range of different data types
on a 32-bit machine is given in the following table. The size and range may vary on machines
with different word sizes.

Keywords
X

There are certain words that are reserved for doing specific tasks. These words are known as
keywords. They are standard and predefined in the Embedded C.
Keywords are always written in lowercase. These keywords must be defined before writing
the main program. The basic keywords of embedded software are given below:

sbit: This data type is used in case of accessing a single bit of SFR register.
 Syntax: sbit variable name = SFR bit ;
 Ex: sbit a=P2^1;
 Explanation: If we assign p2.1 as ‘a’ variable, then we can use ‘a’ instead of p2.1
anywhere in the program, which reduces the complexity of the program.
Bit: This data type is used for accessing the bit addressable memory of RAM (20h-2fh).
 Syntax: bit variable name;
 Ex: bit c;
 Ex: bit c;
 Explanation: It is a bit sequence setting in a small data area that is used by a program
to remember something.

13
SFR: This data type is used for accessing a SFR register by another name. All the SFR
registers must be declared with capital letters.
 Syntax: SFR variable name = SFR address of SFR register;
 Ex: SFR port0=0x80;
 Explanation: If we assign 0x80 as ‘port0’, then we can use 0x80 instead of port0
anywhere in the program, which reduces the complexity of the program.
SFR Register: The SFR stands for ‘Special Function Register’. Microcontroller 8051 has
256 bytes of RAM memory. This RAM is divided into two parts: the first part of 128 bytes is
used for data storage, and the other of 128 bytes is used for SFR registers. All peripheral
devices like I/O ports, timers and counters are stored in the SFR register, and each element
has a unique address.

The Structure of an Embedded C Program

 comments
 preprocessor directives
 global variables
 main() function
{

 local variables
 statements
 …………..
 …………..
}

 fun(1)
{

 local variables
 statements
 …………..
 …………..
}

14
Comments: In embedded C programming language, we can place comments in our code
which helps the reader to understand the code easily.
C=a+b; /* add two variables whose value is stored in another variable C*/
X

Preprocessor directives: All the functions of the embedded C software are included in the
preprocessor library like “#includes<reg51.h>, #defines”. These functions are executed at the
tie of running the program.

Global variable
A global variable is a variable that is declared before the main function, and can be accessed
on any function in the program.

Local variable
A local variable is a variable declared within a function, and it is valid only to be used within
that function.

Main () function
The execution of a program starts with the main function. Every program uses only one main
() function.

Advantages of embedded C program

 Its takes less time to develop application program.


 It reduces complexity of the program.
 It is easy to verify and understand.
 It is portable in nature from one controller to another.

4.2 microC

The mikroC PRO for PIC is a powerful, feature-rich development tool for PIC
microcontrollers. It is designed to provide the programmer with the easiest
possible solution to developing applications for embedded systems, without
compromising performance or control.

15
PIC and C fit together well: PIC is the most popular 8-bit chip in the world, used in a wide
variety of applications, and C, prized for its efficiency, is the natural choice for developing
embedded systems. mikroC PRO for PIC provides a successful match featuring highly
advanced IDE, ANSI compliant compiler, broad set of hardware libraries, comprehensive
documentation, and plenty of ready-to-run examples.

Features
mikroC PRO for PIC allows you to quickly develop and deploy complex applications:

 Write your C source code using the built-in Code Editor (Code and Parameter
Assistants, Code Folding, Syntax Highlighting, Auto Correct, Code Templates,
and more.)
 Use included mikroC PRO for PIC libraries to dramatically speed up the
development: data acquisition, memory, displays, conversions, communication
etc.
 Monitor your program structure, variables, and functions in the Code Explorer.
 Generate commented, human-readable assembly, and standard HEX compatible
with all programmers.
 Use the integrated mikroICD (In-Circuit Debugger) Real-Time debugging tool
to monitor program execution on the hardware level.
 Inspect program flow and debug executable logic with the integrated Software
Simulator.
 Generate COFF(Common Object File Format) file for software and hardware
debugging under Microchip's MPLAB software.
 Active Comments enable you to make your comments alive and interactive.
 Get detailed reports and graphs: RAM and ROM map, code statistics, assembly
listing, calling tree, and more.
 mikroC PRO for PIC provides plenty of examples to expand, develop, and use
as building bricks in your projects. Copy them entirely if you deem fit – that’s
why we included them with the compiler.

4.3 MPLAB IPE


The MPLAB® Integrated Programming Environment (IPE) is a software
application that provides a simple interface to quickly access key programmer

16
features. The IPE provides a production user interface for use on the
manufacturing floor. The IPE uses the MPLAB X IDE framework, Microchip
Debugger (MDB) database, hardware tool interfaces and respective drivers to
provide programming capabilities for all Microchip programmers

5 INTRODUCTION TO UART COMMUNICATION

UART stands for Universal Asynchronous Receiver/Transmitter. It’s not a


communication protocol like SPI and I2C, but a physical circuit in a microcontroller, or a
stand-alone IC. A UART’s main purpose is to transmit and receive serial data.

In UART communication, two UARTs communicate directly with each other. The
transmitting UART converts parallel data from a controlling device like a CPU into serial
form, transmits it in serial to the receiving UART, which then converts the serial data back
into parallel data for the receiving device. Only two wires are needed to transmit data
between two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of
the receiving UART:

17
UARTs transmit data asynchronously, which means there is no clock signal to synchronize
the output of bits from the transmitting UART to the sampling of bits by the receiving UART.
Instead of a clock signal, the transmitting UART adds start and stop bits to the data packet
being transferred. These bits define the beginning and end of the data packet so the receiving
UART knows when to start reading the bits.
When the receiving UART detects a start bit, it starts to read the incoming bits at a
specific frequency known as the baud rate. Baud rate is a measure of the speed of data
transfer, expressed in bits per second (bps). Both UARTs must operate at about the same baud
rate. The baud rate between the transmitting and receiving UARTs can only differ by about
10% before the timing of bits gets too far off.
Both UARTs must also must be configured to transmit and receive the same data packet
structure

Remember when printers, mice, and modems had thick cables with those huge clunky
connectors? The ones that literally had to be screwed into your computer? Those devices
were probably using UARTs to communicate with your computer. While USB has almost
completely replaced those old cables and connectors, UARTs are definitely not a thing of the
past. You’ll find UARTs being used in many DIY electronics projects to connect GPS
modules, Bluetooth modules, and RFID card reader modules to your Raspberry Pi, Arduino,
or other microcontrollers.

UART stands for Universal Asynchronous Receiver/Transmitter. It’s not a


communication protocol like SPI and I2C, but a physical circuit in a microcontroller, or a
stand-alone IC. A UART’s main purpose is to transmit and receive serial data.
One of the best things about UART is that it only uses two wires to transmit data between
devices. The principles behind UART are easy to understand, but if you haven’t read part one
of this series, Basics of the SPI Communication Protocol, that might be a good place to start.

18
In UART communication, two UARTs communicate directly with each other. The
transmitting UART converts parallel data from a controlling device like a CPU into serial
form, transmits it in serial to the receiving UART, which then converts the serial data back
into parallel data for the receiving device. Only two wires are needed to transmit data
between two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of
the receiving UART:

UARTs transmit data asynchronously, which means there is no clock signal to synchronize
the output of bits from the transmitting UART to the sampling of bits by the receiving UART.
Instead of a clock signal, the transmitting UART adds start and stop bits to the data packet
being transferred. These bits define the beginning and end of the data packet so the receiving
UART knows when to start reading the bits.
When the receiving UART detects a start bit, it starts to read the incoming bits at a
specific frequency known as the baud rate. Baud rate is a measure of the speed of data
transfer, expressed in bits per second (bps). Both UARTs must operate at about the same baud
rate. The baud rate between the transmitting and receiving UARTs can only differ by about
10% before the timing of bits gets too far off.
Both UARTs must also must be configured to transmit and receive the same data packet
structure.

5.1 HOW UART WORKS


The UART that is going to transmit data receives the data from a data bus. The data bus is
used to send data to the UART by another device like a CPU, memory, or microcontroller.
Data is transferred from the data bus to the transmitting UART in parallel form. After the
transmitting UART gets the parallel data from the data bus, it adds a start bit, a parity bit, and
a stop bit, creating the data packet. Next, the data packet is output serially, bit by bit at the Tx
pin. The receiving UART reads the data packet bit by bit at its Rx pin. The receiving

19
UART then converts the data back into parallel form and removes the start bit, parity bit, and
stop bits. Finally, the receiving UART transfers the data packet in parallel to the data bus on
the receiving end:

UART transmitted data is organized into packets. Each packet contains 1 start bit, 5 to 9 data
bits (depending on the UART), an optional parity bit, and 1 or 2 stop bits:

START BIT
The UART data transmission line is normally held at a high voltage level when it’s
not transmitting data. To start the transfer of data, the transmitting UART pulls the
transmission line from high to low for one clock cycle. When the receiving UART detects the
high to low voltage transition, it begins reading the bits in the data frame at the frequency of
the baud rate.

DATA FRAME
The data frame contains the actual data being transferred. It can be 5 bits up to 8 bits long if a
parity bit is used. If no parity bit is used, the data frame can be 9 bits long. In most cases, the
data is sent with the least significant bit first.

PARITY
Parity describes the evenness or oddness of a number. The parity bit is a way for the receiving
UART to tell if any data has changed during transmission. Bits can be changed
by electromagnetic radiation, mismatched baud rates, or long distance data transfers. After
the receiving UART reads the data frame, it counts the number of bits with a value of 1 and

20
checks if the total is an even or odd number. If the parity bit is a 0 (even parity), the 1 bits in
the data frame should total to an even number. If the parity bit is a 1 (odd parity), the 1 bits in
the data frame should total to an odd number. When the parity bit matches the data, the
UART knows that the transmission was free of errors. But if the parity bit is a 0, and the total
is odd; or the parity bit is a 1, and the total is even, the UART knows that bits in the data
frame have changed.

STOP BITS
To signal the end of the data packet, the sending UART drives the data transmission line from
a low voltage to a high voltage for at least two bit durations.

5.2 STEPS OF UART TRANSMISSION


1. The transmitting UART receives data in parallel from the data bus:

2. The transmitting UART adds the start bit, parity bit, and the stop bit(s) to the data frame:

21
3. The entire packet is sent serially from the transmitting UART to the receiving UART. The
receiving UART samples the data line at the pre-configured baud rate:

4. The receiving UART discards the start bit, parity bit, and stop bit from the data frame:

5. The receiving UART converts the serial data back into parallel and transfers it to the data
bus on the receiving end:

22
5.3 ADVANTAGES AND DISADVANTAGES OF UARTS
No communication protocol is perfect, but UARTs are pretty good at what they do. Here are

some pros and cons to help you decide whether or not they fit the needs of your project:

ADVANTAGES
 Only uses two wires

 No clock signal is necessary

 Has a parity bit to allow for error checking

 The structure of the data packet can be changed as long as both sides are set up for it

 Well documented and widely used method

DISADVANTAGES
 The size of the data frame is limited to a maximum of 9 bits

 Doesn’t support multiple slave or multiple master systems

 The baud rates of each UART must be within 10% of each other

6 AT COMMANDS
AT commands are instructions used to control a modem. AT is the abbreviation of ATtention.
Every command line starts with "AT" or "at". That's why modem commands are called AT
commands. Many of the commands that are used to control wired dial-up modems, such as
ATD (Dial), ATA (Answer), ATH (Hook control) and ATO (Return to online data state), are

23
also supported by GSM/GPRS modems and mobile phones. Besides this common AT
command set, GSM/GPRS modems and mobile phones support an AT command set that is
specific to the GSM technology, which includes SMS-related commands like AT+CMGS
(Send SMS message), AT+CMSS (Send SMS message from storage), AT+CMGL (List SMS
messages) and AT+CMGR (Read SMS messages).
Note that the starting "AT" is the prefix that informs the modem about the start of a command
line. It is not part of the AT command name. For example, D is the actual AT command name
in ATD and +CMGS is the actual AT command name in AT+CMGS. However, some books
and web sites use them interchangeably as the name of an AT command.
Here are some of the tasks that can be done using AT commands with a GSM/GPRS modem
or mobile phone:
 Get basic information about the mobile phone or GSM/GPRS modem. For example,
name of manufacturer (AT+CGMI), model number (AT+CGMM), IMEI number
(International Mobile Equipment Identity) (AT+CGSN) and software version
(AT+CGMR).
 Get basic information about the subscriber. For example, MSISDN (AT+CNUM) and
IMSI number (International Mobile Subscriber Identity) (AT+CIMI).
 Get the current status of the mobile phone or GSM/GPRS modem. For example,
mobile phone activity status (AT+CPAS), mobile network registration status
(AT+CREG), radio signal strength (AT+CSQ), battery charge level and battery
charging status (AT+CBC).
 Establish a data connection or voice connection to a remote modem (ATD, ATA, etc).
 Send and receive fax (ATD, ATA, AT+F*).
 Send (AT+CMGS, AT+CMSS), read (AT+CMGR, AT+CMGL), write (AT+CMGW)
or delete (AT+CMGD) SMS messages and obtain notifications of newly received
SMS messages (AT+CNMI).
 Read (AT+CPBR), write (AT+CPBW) or search (AT+CPBF) phonebook entries.
 Perform security-related tasks, such as opening or closing facility locks (AT+CLCK),
checking whether a facility is locked (AT+CLCK) and changing passwords
(AT+CPWD).
(Facility lock examples: SIM lock [a password must be given to the SIM card every
time the mobile phone is switched on] and PH-SIM lock [a certain SIM card is
associated with the mobile phone. To use other SIM cards with the mobile phone, a
password must be entered.])
24
 Control the presentation of result codes / error messages of AT commands. For
example, you can control whether to enable certain error messages (AT+CMEE) and
whether error messages should be displayed in numeric format or verbose format
(AT+CMEE=1 or AT+CMEE=2).
 Get or change the configurations of the mobile phone or GSM/GPRS modem. For
example, change the GSM network (AT+COPS), bearer service type (AT+CBST),
radio link protocol parameters (AT+CRLP), SMS center address (AT+CSCA) and
storage of SMS messages (AT+CPMS).
 Save and restore configurations of the mobile phone or GSM/GPRS modem. For
example, save (AT+CSAS) and restore (AT+CRES) settings related to SMS
messaging such as the SMS center address.
Note that mobile phone manufacturers usually do not implement all AT commands, command
parameters and parameter values in their mobile phones. Also, the behavior of the
implemented AT commands may be different from that defined in the standard. In general,
GSM/GPRS modems designed for wireless applications have better support of AT commands
than ordinary mobile phones.
In addition, some AT commands require the support of mobile network operators. For
example, SMS over GPRS can be enabled on some GPRS mobile phones and GPRS modems
with the +CGSMS command (command name in text: Select Service for MO SMS
Messages). But if the mobile network operator does not support the transmission of SMS
over GPRS, you cannot use this feature.

Basic Commands and Extended Commands


There are two types of AT commands: basic commands and extended commands.
Basic commands are AT commands that do not start with "+". For example, D (Dial), A
(Answer), H (Hook control) and O (Return to online data state) are basic commands.
Extended commands are AT commands that start with "+". All GSM AT commands are
extended commands. For example, +CMGS (Send SMS message), +CMSS (Send SMS
message from storage), +CMGL (List SMS messages) and +CMGR (Read SMS messages)
are extended commands.

7 About the project at EWE Research and development


centre:

25
To interface various devices and modules , the basic interface of each and every device and
how they work using AT commands were required, hence to do so various tests were done
with Arduino Uno using Arduino IDE:

7.1 Creating a Wi-Fi Connection using ESP 8266 as an interface between Arduino Uno
and the access point:

ESP8266 Wifi Module is an integrated chip designed for communicating to the world of the
internet through Wifi radio signals. It is used as a link between a project and the internet. It
has on-board processing and memory that allows it to be integrated with electronics through
its GPIOs. The ESP8266 here is used as an interface to provide Arduino a Wi-Fi Connection.

Step 1: Connecting the ESP8266

Firstly, we need to connect our Wi-Fi Module i.e. ESP8266 to the Arduino micro-
controller board.
We connect various pins of ESP 8266 with that of Arduino Uno i.e. TXD, RXD, GND,
and the VCC pins to the pin 10(RX), pin11(TX), GND and 3.3V pins, respectively. After
that programming is done.

Step 2: Programming.
1. Then we write a program and upload to Arduino to enable serial communication
between the serial monitor and the ESP8266 through the Arduino.
2. When we enter a command on the serial monitor of the ESP8266 it will reply with
‘OK’ for a simple ‘AT’ command.
3. In our code, various AT commands have been used. In the code we have declared to
characters i.e. SID and Password and set up pin 10 and 11 as input and output,
respectively.
4. After that we initialized the ESP giving it a baud rate of 115200.
5. Then ran our code in infinite loop to run various AT commands infinitely. The AT
commands are given below.

Code :
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(10, 11); // RX | TX

26
void setup()
{
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }

// Start the software serial for communication with the ESP8266


ESPserial.begin(9600);

Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}

void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }

// listen for user input and send it to the ESP8266


if ( Serial.available() ) { ESPserial.write( Serial.read() ); }

Step 3: AT Commands

1. “AT” This command is used to check if the module is connected properly and its
functioning, the module will reply with an acknowledgment i.e. OK.

2. “AT+RST” This will reset the wifi module. We reset it before or after it has been
programmed such that in cases when it was already running the command it can reset itself.

3. “AT+GMR” This mentions the firmware version installed on the ESP8266.

4. “AT+CWLAP” This will detect the Access points and their signal strengths available
in the area, here the command means Command Wi-Fi to list all access points.

27
5. AT+CWJAP=”SSID”,”PASSWORD” This connects the ESP8266 to the specified
SSID in the AT command where the command refers to Command Wi-Fi to join access point.

6. If the user wants to disconnect from any access point then use the following AT
command AT+CWQAP=””,””, i.e. Quit the access point.

7. “AT+CWMODE=1” This sets the Wifi mode. It should be always set to Mode 1 if we
want to use the module as a node (Like our mobile’s connection to the access points).

Now we have connected your Arduino with our access point here used my mobile connection
as an access point using ESP 8266 as an interface.

7.2 Creating a web server using ESP8266 :

PROJECT WORKING:
1. Arduino web server can be accessed by the devices within that LAN to control the LED’s
or other components. ESP8266 i.e. our Wi-Fi module remembers the AP’s to which it has
been already connected

2. It will get connected to AP as soon as hotspot of my phone is turned ON.

3. Once connected a LAN will get created. Once Arduino detects a connection via ESP8266,
it will start sending the commands to ESP module to create a server.

4. I have added a LED to indicate server creation. Most of the time It will take about two
seconds from the moment ESP is connected to Wi-Fi AP by giving it a delay of 2000 ms.

5. Once the Arduino web server is ready, I opened chrome browser on my laptop connected to
the LAN and access the IP address assigned to ESP8266 module.

6. Arduino will send the piece of HTML code to the client via ESP module and a webpage is
displayed on the browser. HTML codes from the Arduino were built to display button in the
webpage or we can simply pass various heading like “Hello World” directly inside the
printline function to check if the web page has been made or not.

7. To Using these buttons user can feed input back to Arduino. Based on the received inputs
Arduino will activate/deactivate LED’s or any other devices connected to it.

28
ESP COMMANDS USED FOR CREATING ARDUINO WEB SERVER:
These are the list of commands that we are going to use to create this Arduino web server.

1.“AT” This command is used to check if the module is connected properly and its
functioning, the module will reply with an acknowledgment i.e. OK.

2.“AT+RST” This will reset the wifi module. We reset it before or after it has been
programmed such that in cases when it was already running the command it can reset
itself.

3.“AT+GMR” This mentions the firmware version installed on the ESP8266.

4. “AT+CWMODE=1” This sets the Wifi mode. It should be always set to Mode 1 if we
want to use the module as a node (Like our mobile’s connection to the access points).
5.“AT+CIPMODE=3” – This Command sets the module as both Station and AP.
6. “AT+CIPMUX=1” – This Command allows setting to allow multiple connections
7. “AT+CIPSERVER=1,80” – Creating server with port 80
8. “AT+CIPSEND=<connection ID>,<Byte count> (0,29 – in our case)

Code

#include <SoftwareSerial.h>

SoftwareSerial esp8266(10, 11); //Pin 10,11 of Arduino as RX and TX. Connect TX


and RX of ESP8266 respectively.

#define DEBUG true

#define led_pin 5 //LED is connected to Pin 11 of Arduino

int count =0;

void setup()

pinMode(led_pin, OUTPUT);

digitalWrite(led_pin, LOW);

Serial.begin(9600);

29
esp8266.begin(9600); //Baud rate for communicating with ESP8266. Your's might
be different.

esp8266Serial("AT+RST", 5000, DEBUG); // Reset the ESP8266

esp8266Serial("AT+CWMODE=3", 5000, DEBUG); //Set station mode Operation

esp8266Serial("AT+CWJAP=\"sandhya\",\"sandhya1210\"", 5000,
DEBUG);//Enter your WiFi network's SSID and Password.

while (!esp8266.find("OK"))

esp8266Serial("AT+CIFSR", 5000, DEBUG);//You will get the IP Address of the


ESP8266 from this command.

esp8266Serial("AT+CIPMUX=1", 5000, DEBUG);

esp8266Serial("AT+PING=\"192.168.43.106:800/testrequest?
q=852146\"",5000,DEBUG);

//esp8266Serial("AT+CIPSERVER=1,80", 10000, DEBUG);

//esp8266Serial("AT+CIPSEND=0,29", 5000, DEBUG);

//esp8266Serial("<h1>Hello</h1><h2>World</h2>", 5000, DEBUG);

void loop()

if (esp8266.available())

30
if (esp8266.find("+IPD,"))

String msg;

esp8266.find("?");

msg = esp8266.readStringUntil(' ');

String command1 = msg.substring(0, 3);

String command2 = msg.substring(4);

if (DEBUG)

Serial.println(command1);//Must print "led"

Serial.println(command2);//Must print "ON" or "OFF"

delay(100);

if (command2 == "ON")

digitalWrite(led_pin, HIGH);

else

digitalWrite(led_pin, LOW);

31
}

String esp8266Serial(String command, const int timeout, boolean debug)

count=count+1;

String response = "";

esp8266.println(command);

//esp8266.println(count);

long int time = millis();

while ( (time + timeout) > millis())

while (esp8266.available())

char c = esp8266.read();

response += c;

if (debug)

Serial.print(response);

32
}

return response;

CHOOSING IP ADDRESS:
I set up a static IP to my ESP8266 module , my mobile DHCP will assign IP when connecting
with it. DHCP in the mobile phone assigns IP address which is free. So i used the IP
192.168.43.253 to assign for ESP module and opened it on my chrome browser to access my
web page created within the code.

HTML WEBPAGE:
So now the server is created in ESP8266 that means our ESP8266 is ready to take client
request (that is the browser). ESP module serves only as a communicating medium here i.e.
as an interface, so it’s the Arduino here that respond with the HTML webpage when a client
request is detected.
We have created our own web page inside the code itself.

ALGORITHM:
1. Firstly, I Input “AT+RST” command and wait until ESP8266 connects with AP.
2. Then Checked for “IP\r\n” in the last four characters of ESP response, this indicate
that Wi-Fi got IP.
3. Once connected I fed the commands to activate the server mode in ESP8266
4. Then, monitored the response for each input commands.
5. Proceeded with the next command once the last four characters of response showed
“OK\r\n” throughout the Server sequence commands.
6. Arduino waits for the client request from any browser connected within the LAN.
7. Once request is received check for the connection ID provided by ESP8266 and add it
to the command “AT+CIPSEND”
8. Then the character ‘>’ showed in the response string from EP module.
9. Once correct response is verified send the webpage HTML code from Arduino
through the ESP module to client browser.
10. Webpage should have been successfully displayed in the browser now.

33
11. Our web page opens when we enter our URL generated by ESP on chrome browser.

7.3 PIC communication with ESP 8266 and LCD:

The ESP8266 modules comes with a default firmware loaded into it, hence we can program
the module using AT commands. These commands have to be sent through a serial
communication channel. This channel is established between the PIC and the ESP8266
module by using the UART module in the PIC microcontroller. The whole working has been
monitored and by using a 16x2 LCD display and in case of passing a character, displayed on
the DSO.

ALGORITHM:

1. Connect pin1 of LCD to ground and pin2 to Vdd.

2. Pin3 of LCD is used to adjust the contrast of the display. We leave it unconnected.

3. RS (pin4) of LCD is connected to RB2 of PORTB. It distinguishes between data input and
command input.

4. RW (pin5) is grounded, since we have to write the data on LCD.

5. E (pin6) is connected to RB3 of PORTB. It is a control line to inform the LCD that data
has been sent.

6. D0-D3 of the LCD are grounded, since we are using a 4-bit mode. D4-D7 are connected to
the PORTB pins (RB4-RB7) of the controller.

7. Then to interface, we define various LCD Module Connections using sbit which helps in
accessing the special function register.

8. For e.g. sbit LCD_EN at RD1_bit defines the LCD enable pin at RD1 pin on the PIC
micro- controller board.

9. Similarly, we define other LCD pins on the micro- controller board.

10. Then to provide LCD Pin direction at various bits of TRISD port.

34
11. Then we initialize the LCD as well as UART serial communication by using initialization
commands.

12. Eventually, displaying the data on the LCD.

Code

sbit LCD_RS at RD0_bit;

sbit LCD_EN at RD1_bit;

sbit LCD_D4 at RD4_bit;

sbit LCD_D5 at RD5_bit;

sbit LCD_D6 at RD6_bit;

sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD0_bit;

sbit LCD_EN_Direction at TRISD1_bit;

sbit LCD_D4_Direction at TRISD4_bit;

sbit LCD_D5_Direction at TRISD5_bit;

sbit LCD_D6_Direction at TRISD6_bit;

sbit LCD_D7_Direction at TRISD7_bit;

// End LCD module connections

char output[16];

char out1[16];

char ssid[]="\"uiet\"" ;

char pass[]="\"12345678\"";

int i=0,j=0;

35
void main() {

UART1_Init(9600);

Lcd_Init();

Lcd_cmd(_LCD_CLEAR);

Delay_ms(500);

while(1)

if(UART1_Tx_idle() == 1)

Lcd_cmd(_LCD_CLEAR);

Lcd_out(1,1,"Sending");

Delay_ms(2000);

Lcd_cmd(_LCD_CLEAR);

UART1_Write_Text("AT+CIFSR\r\n");

//UART1_Write_Text("AT");

//while (UART1_Data_Ready() == 0);

36
//while (UART1_Data_Ready() == 1)

while(UART1_Data_Ready() == 1)

//while(1)

{ // if data is received

Lcd_cmd(_LCD_CLEAR);

// reads text until 'OK' is found

Lcd_out(1,1,"recieve");

//while(J!=1)

for(i=0;i<32;i++)

while (UART1_Data_Ready() == 0);

output[i]=UART1_Read();

j=i-16;

if(i>16)

out1[j]=UART1_Read();

// Delay_ms(50);

/* if(output[i] == 'T')

37
J=J+1;

i++;*/

Delay_ms(1000);

Lcd_cmd(_LCD_CLEAR);

/*

for(J=0;J<10;J++)

Lcd_out(1,1,output[J]);

*/

Lcd_out(1,1,output);

Lcd_out(2,1,out1);

Delay_ms(10000);

38
}

AT+CIFSR.txt

Displaying AT+CIFSR.txt.

39
40

You might also like