Introduction: 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
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
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..
Attachments
Step 3: 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.
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.
Attachments
Step 5: 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.
27 Comments
Question 5 years ago
I am unable to get this project working. during compilation an error comes up :
in void setup(), "Serial1" was not declared in this scope". I am a newbie and cannot figure out what is happening. When I use the IDE Serial Terminal mode what is printed is a series of AT, error, series of AT+CWMODE=3, error, etc. I am completely lost. Can anyone suggest what I should do. Thanks.
Answer 1 year ago
The same problem with me!
3 years ago
Hola que tal comprobe que el codigo esta hecho ppara Arduino Mega y unos pequeños cambios para Arduino Uno, pero que puedo hacer para utilizarlo con Arduino nano ya que me genera este error exit status 1
'Serial1' was not declared in this scope
Question 5 years ago on Step 5
Hey! Iam using arduino UNO for this but getting errors like espcomm_sync failed,espcomm_open failed, espcomm_upload_mem failed
Question 5 years ago
void Send()
{
webpage = "<h1>Welcome to Circuit Digest</h1><body bgcolor=f0f0f0>";
sendwebdata(webpage);
webpage=name;
webpage+=dat;
sendwebdata(webpage);
delay(1000);
webpage ="<a href="http://circuitdigest.com/"; // <-- arduino uno can't comiple
webpage+="\">Click Here for .....</a>"; // error before http is [ " ]
sendwebdata(webpage); // exzample works well just 1 small error
client.println("AT+CIPCLOSE=0");
}
Thanks for lesson to Author it help me a lot to start with esp8266.
5 years ago
Ok, thanks for this very complete tutorial.
I try to obtain POST data from the calling request, is that possible ? How to do this ?
Question 5 years ago
hello world if i want to use this vode for iot project for home automation how to turn on tv fan light relay using switch button in iot if code is available plz share that part
Question 5 years ago on Step 5
What are the changes need to make while using UNO R3 in this project both in circuit and code ?
5 years ago
With Arduino UNO and ESP8266, how to connect camera that should continuously monitor and analyze image via code and send images to webpage via wi-fi whenever required
5 years ago
hey Joyson96,
thanks for the help, got it working! but I can't get the temperature value refreshed every, lets say 5 seconds. have you tried such thing?
5 years ago
Hi, Works perfectly, thanks!
how can I do to send the values that I got from "pin=" in the webserver to another php page, like "http://192.168.1.123/index.php?pin=" the number that I got in the web server?
6 years ago
I've made it but i want to upload value to web server so can you help me
6 years ago
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.
Reply 6 years ago
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.
Reply 6 years ago
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.
6 years ago
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!!!!!
Reply 6 years ago
sorry, but i can't exactly get your problem. please upload your sketch. which board are you using???
Reply 6 years ago
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.
Reply 6 years ago
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
6 years ago
Hi.
Sorry to bother you again.
How do I find / determine / calculate the connectionID