How to Connect ESP8266 to WiFi
Hello People. This article discusses how to connect ESP8266 to WiFi. Before connecting to wifi, you should have a basic knowledge on ESP8266 WiFi Module. How to get started with ESP8266 and Arduino, what is the pin configuration of the ESP8266 ESP-01 Module and how to program the ESP8266 using Arduino as USB-to-Serial Interface.
ESP8266 WiFi Module can be interfaced to any other microcontroller. In order to use the ESP8266 WiFi Module in our Internet related projects, we need to first connect ESP8266 to WiFi and then access it from the internet.
You need to know the WiFi modes of operation of the ESP8266 Module before going into the details of how to connect ESP8266 to WiFi.
Are you looking to start your business in the electric vehicle industry? We provide software development, web application development, mobile application development, charging stations management app, electric vehicle fleet management software development, cyber security and all software services. Please check our home page here https://iwheels.co/
Ok. Let's get back to the article.
WiFi Modes of Operation of ESP8266
There are three modes of WiFi Operation in the ESP8266 WiFi Module. They are:
- Station Mode (STA)
- Soft Access Point (AP)
- Soft AP + Station
Station Mode (STA)
In Station Mode (STA), the ESP8266 WiFi Module will be connected to a WiFi Network that is already setup by an Access Point, like a WiFi Router.
Soft Access Point (AP)
The second mode of operation is Access Point (AP) Mode. In this mode, the ESP8266 Module acts as an access point and provide WiFi Network to other stations (like mobile or laptop).
Usually, an access point can provide internet through a wired network to its stations but as there is no wired interface, this Access Point mode is called Soft Access Point.
The ESP Module is first setup as Soft AP mode before configuring it in Station Mode. This is helpful when the username (SSID) and password of the WiFi network is unknown.
Soft AP + Station
In the third mode, the ESP8266 WiFi Module is configured to act in both Station Mode and Soft AP Mode.
All these Modes of Operation are set using AT Commands. In this tutorial, I will discuss about the AT Commands that are required to connect ESP8266 to WiFi Network. In a separate tutorial, I’ll talk about some of the important and useful ESP8266 AT Commands.
Components Required to setup the wifi connection
- ESP8266 (ESP-01) WiFi Module
- Arduino UNO (an USB-to-Serial Adapter is sufficient)
- Push Button
- Slide Switch
- 1 KΩ Resistor (1/4 Watt)
- 2.2 KΩ Resistor (1/4 Watt)
- Connecting wires
How to Connect ESP8266 to WiFi Network?
You can program for the ESP8266 WiFi Module. The code for this is shown below.
#include "ESP8266WiFi.h" | |
const char* ssid = "ssid"; //Enter SSID | |
const char* password = "password"; //Enter Password | |
void setup(void) | |
{ | |
Serial.begin(115200); | |
// Connect to WiFi | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(500); | |
Serial.print("*"); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connection Successful"); | |
Serial.print("The IP Address of ESP8266 Module is: "); | |
Serial.print(WiFi.localIP());// Print the IP address | |
} | |
void loop() | |
{ | |
// EMPTY | |
} |
Attention: In the code, enter the details of your WiFi Network in place of “ssid” and “password”.
Before programming, select the “Generic ESP8266 Module” from boards and also select the correct COM Port.
Now, connect the GPIO0 to GND and reset the ESP and hit the upload button. The ESP8266 WiFi Module will be automatically connected to the specified WiFi Network and it also responds with the IP Address.
Hope this article on How to Connect ESP8266 to WiFi is useful to you. Please read about What is Arduino IOT cloud