This tutorial demonstrates how to create a web server using Arduino and ESP8266 which is flashed with AT Firmware. ESP8266 WiFi modules come with pre flashed AT command Firmware. Before continuing with this tutorial you can go through the basics of ESP8266 and AT commands to configure it as a webserver in the following articles.
Getting started with ESP8266 and Web server using ESP8266.
Here we will connect Arduino UNO with ESP8266 using serial communication and Programming Arduino to handle the AT commands.
The code handles the ESP8266’s initialization in the setup() function such as
-
Reset the module.
-
Configure it as an access point.
-
Prints out the module’s IP address.
-
Configure it as a server on port 80 and for multiple connections.
Re flashing with AT Firmware:
This step can be skipped if you are new to the ESP8266, and you bought the module newly, Since ESP8266 modules come with preloaded AT command Firmware. If you already used the ESP8266 with NodeMCU Firmware and LUA Scripting you should flash with the Latest AT Command Firmware before continuing through the tutorial.
This Part of this tutorial will give you an idea about how to upgrade new AT Firmware on to the ESP module. You can download AT firmware here.
You can use USB-TTL converter to flash the ESP8266 with this firmware.
For detailed instructions about flashing ESP8266 refer this article. In that article you will find details about flashing ESP8266 with NodeMCU. We are going to use the same Software to Flash it with AT firmware.
Connections for Flash mode:
The normal connection details are as below:
WIFI Module |
USB-TTL
|
Vcc |
3.3v |
Gnd |
Gnd |
TX |
RX |
RX |
TX |
CH_PD |
Connected to 3.3v to enable chip firmware boot |
Don’t forget to pull up CH_PD HIGH, you won’t get a response from the module if it is not done.
In addition to the above connections. To get into the firmware flash mode, we need to make an additional connection, the easiest is to use a breadboard for this.
ESP-01 GPIO0 – Pull low by connecting to GND
You can follow all the steps in that tutorial to flash the ESP8266 except, you have to choose the Config tab and click the small gear symbol in the first and navigate to the AT Firmware you downloaded.
Fig. 1: Screenshot of AT Firmware
And click the Flash button to Flash it. You can check the working by sending AT commands.
Arduino to ESP8266 By Serial Communication:
Here is how to set up the Arduino to talk to the ESP8266.
The wiring is very similar to the FTDI.
Arduino 3.3V to ESP8266 VCC
Arduino pin 3 to ESP8266 RX
Arduino pin 2 to ESP8266 TX
Arduino GND to ESP8266 GND
You can use a simple serial in, serial out sketch. To check the working.
#include <SoftwareSerial.h> SoftwareSerial ESPserial(2, 3); // RX | TX
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(“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() ); } } |
Once everything is setup, open the serial monitor and set the baud rate to 9600, you should receive the welcome message.
Fig. 2: Screenshot of Arduino Serial Terminal
Arduino web server:
The web server can be created by setting the ESP8266 as an Access point and other devices can connect. Refer detailed article about the Web server here.
Our aim is to send all the AT commands by Arduino in the correct order to make ESP8266 as an AP and to allow other devices to access and control it.
Here we are creating a Function in the Arduino code to send the AT commands and receive the responses of the commands.
String sendData(String command, const int timeout, boolean debug)
String command – will carry the command to be sent.
Timeout – maximum time to wait for the response.
Debug – to know ESP8266 Status.
When there is data request, if the string +IPD is in the serial data, then the HTTP Responses which are HTML Codes are sent in real time to create a page with the text “HelloWorld” and a Button “LED1” which is programmed to toggle the Arduino inbuilt LED. After uploading the code open Serial monitor of the Arduino IDE. You can see the Responses from the ESP8266 module.
Connect to the Access point of the ESP8266 .
Fig. 3: Screenshot of Wi-Fi Access Points
You can see the Page Like this when you navigate to the IP address which is printed on the Serial Port.
Fig. 4: Screenshot of Webpage hosted by the Arduino Web Server
Click on the “LED1” Button to Toggle the inbuilt LED in Arduino UNO.
You can also add buttons and control any number of pins by replicating the code.
Check this video
Filed Under: Tutorials
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.