Introduction: Simple Webserver Using Arduino and ESP8266

Picture of Simple Webserver Using Arduino and ESP8266

The main aim of this instructable is to show how you can create a simple web server using Arduino and Wi-Fi module which displays the sensor data in the webpage.

Enjoy this instructables........

Step 1: Things You Need

Picture of Things You Need

Hardware

1. Arduino UNO or Mega.

2. WiFi module ESP8266- 01/12.

3. 3.3V voltage regulator. (LM390/LD117)

4. LM35 Temperature Sensor.

5. Jumper wires.

6. External 5V source (optional)..

7. Breadboard.

8. Capacitors (0.47uF, 22uF).

Software:

1 .Arduino IDE.

2. Web browser.

Step 2: Pin Configurations and Preparing ESP8266

Picture of Pin Configurations and Preparing ESP8266

Things to know before starting with ESP8266
The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino device and get about as much WiFi-ability as a WiFi Shield offers.

Before you go for programming we have to prepare ESP module to work with arduino.

For ESP8266-01 the VCC pin and CH_PD pin should be short-circuit as shown in the image above.

Same way in ESP8266-12 there a certain pins which are to be short i.e CH_PD and GPIO0 with VCC, GPIO15 with GND

For ESP8266-12 without base board we have to solder it on perfboard or with connecting wires for making it breadboard compatible.

AT commands for ESP8266 is attached below..

Step 3: Circuit Connections

Picture of Circuit Connections

Voltage Regulator

The circuit for voltage regulator is shown in the above diagram. Capacitors are connected at the input and output terminal of regulator for smoothing. The capacitors used is ceramic type connected at input side and electrolytic type at the output side.

NOTE: It is not advisable to give 5v source from Arduino as ESP requires more current for its operation. Doing so can cause malfunction of Wi-Fi module. Schematics shown above is just for representation.

ESP8266 connections

VCC should be connected to the 3.3v voltage regulator and GND should be common for both Arduino and for ESP same follows for any sensors used.

ESP RxD----------------->Arduino Tx

ESP TxD------------------>Arduino Rx

If using Arduino Mega we can use Serial Port 1, i.e. Pin 18 and 19, for connecting to ESP as Serial Port 0 is used by serial monitor.

For Arduino UNO we have to assign software serial which is declared in the program. Here we are using Arduino pin 2 and 3 as Rx and Tx

Temperature Sensor

the VCC of the sensor is connected to 5v source from Arduino and GND is connected to the common ground. the Output pin is connected to Arduino's analog pin (A0).

Step 4: Arduino Sketch and Explanation.

Picture of Arduino Sketch and Explanation.

Arduino sketch for this tutorial is attached below, Program is self-explanatory and contains comments for all operations.

If you are using Arduino Uno then follow this...

#include<SoftwareSerial.h>

#define DEBUG true

SoftwareSerial esp8266(2,3);

REPLACE the above text in bold with the content above the void setup() ,and also Serial1 with esp8266 in program.

The above Code is to assign UNO pins 2 and 3 as RX and TX. This means that you need to connect the TX line from the esp to to Arduino's pin 2 and the RX line from the ESP to the Arduino's pin 3.

Step 5: Final Outcome.

Picture of Final Outcome.

As we are using ESP8266 in Mode 2 i.e. Access Point ,it will create a Wi-Fi hotspot with ssid AI-THINKER.

By default there is no password for the network. We can change SSID and PASSWORD by sending the AT commands from the program.

Accessing the Web page

First connect to the network by your device.

Open a web browser such as Google Chrome.

Go to the Address bar and enter the IP Address of your ESP8266 then press Enter. By default the IP address is 192.168.4.1 .Now you will get the webpage as shown in the image.

This is just the basic work with ESP8266,but you can get more out of it, just be creative and Think out of the Box :)

Thank you.

Comments

FrazA2 (author)2017-09-08

I've made it but i want to upload value to web server so can you help me

sanglems (author)2017-03-29

Hi.

I am trying to use ESP8266 with Arduino UNO R3. But I can’t sent the AT command as I am getting loop of FatalException(0) as below as soon as I connect to ESP8266 module: (Can’t make out what does this mean)

Fatal exception 0(IllegalInstructionCause):
epc1=0x40201364, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000 ets
Jan 8 2013,rst cause:2,
boot mode:(3,6) load 0x40100000,
len 1856,
room 16 tail 0
chksum 0x63
load 0x3ffe8000,
len 776,
room 8 tail 0
chksum 0x02
load 0x3ffe8310,
len 552,
room 8 tail 0
chksum 0x79
csum 0x79
2nd boot version : 1.5
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run
user1 @ 1000

Following are my ESP8266 connection details:
1. Vcc – 3.3v external supply (GND connected to GND of 3.3v and GND of 5v of Arduino)
2. CH_PD – 3.3v
3. GPIO0 – Tried keeping 3.3v (Same Error)
disconnected (Same Error)
GND (Same Error)–(Just tried. I know this will be the programming mode)
4. Rx – Rx of Arduino UNO via voltage divider
5. Tx – Tx of Arduino
(Tried with exchanging Rx and TX)
6. RST – Disconnected (Same Error)
3.3v (Same Error)
(Used the GND pulse to reset the ESP8266)

I also tried connecting RESET of Arduino UNO to GND with no success ;( .

I checked the output with all the baud rates keeping “Both NL & CR” option selected. For baud rate 115200 I am getting the above exception. For rest it showing some garbage values.

I have uploaded bareMinimum example in the Arduino UNO to start with.

Any suggestion, pointer will be really appreciated.

Is my module damaged? Never used it with anything other than 3.3v though.

Thanks.

Joyson96 (author)sanglems2017-03-30

try this..

Rx of ESP to Tx of Arduino

Tx of ESP to Rx of Arduino

if there is no use of ATmega328 then take it out and try.

sanglems (author)Joyson962017-03-30

Thanks for your reply.

I tried exchanging Rx and Tx but no success.

Sorry for dumb questions! What do you mean by take out ATmega328? Do i need to desolder it? I tried connecting RESET of Arduino to GND so that Arduino will act as just path. Is it same what do u mean?

Thanks.

GrahamB17A (author)2017-02-03

Hi

Read Datasheet and inputting link with and without <>. Still getting either link not valid and error, or error report. What do I enter and where? tried all links in close command, but have put it in send command also. Have 8 to 10 hours trying to get this to work. Going mad!!!!!

Joyson96 (author)GrahamB17A2017-02-03

sorry, but i can't exactly get your problem. please upload your sketch. which board are you using???

GrahamB17A (author)Joyson962017-02-06

Am using UNO. Possibly have found a problem at my end. Tried another sketch and see a report there was a problem downloading library, and it refers to joyson. Will reload, and let you know what happens.

GrahamB17A (author)GrahamB17A2017-02-07

Hi

Have sorted it out at last. Brilliant!!! Slowed down ESP baud to 9600, as UNO cannot keep up with ESP speed. After find ("+IPD,") I changed delay to 10000 and it worked. Tested this and works fine at delay 3000, but not at 2000.

Incidentally, in your description you state changes in #include for the UNO. I have entered #include<SoftwareSerial.h>. I assume this is correct. If so you may want to update your description. I noticed this early on, so was not the problem I had getting this running.

Could this be altered to auto-refresh? Maybe I can do something on my Tablet to do this. I will try to figure this out myself. Thanks for all the responses. Love It, Love It, Love It.

Graham.B17A

GrahamB17A (author)2017-01-31

Hi.

Sorry to bother you again.

How do I find / determine / calculate the connectionID

GrahamB17A (author)2017-01-23

Thanks for the response. New to this. Trying to enter SSID and password for over 2 hours, but no success. What is the correct way to do it & where in the sketch does it go? Going Mad at attempting to do it.!!

Joyson96 (author)GrahamB17A2017-01-31

There are specific commands for entering these, those commands will be given in data sheet.U have to enter these under Void Setup().

GrahamB17A (author)2017-01-23

Password - SSID

Hi. Brilliant Idea. Tried it out, but am on a password protected Router.

How and where do I enter command in Program.

Have bee trying to enter it in various places in code, but keep getting error messages when I try to verify.

Joyson96 (author)GrahamB17A2017-01-23

hello,If u want to connect it to router then you have to change the operating mode of the ESP in command program. Refer the datasheet for the commands...

mnur ali (author)2016-11-30

hi , can i add lcd 2x16 to display the temperature ?

i wanna display it on lcd and web browser :)

seamster (author)2016-08-18

Nicely done, very good info. Thanks!

Joyson96 (author)seamster2016-08-21

Welcome...:)