Connect ESP8266 To Wifi Using Arduino

Connect ESP8266 To Wifi Using Arduino

In this tutorial, we are going to learn on how to connect ESP8266 to wifi network by using Arduino Uno. We will setup the wifi connection through a set of AT Commands via Arduino IDE Serial Monitor.

1- Connect the circuit as shown in the figure below

2- Upload the following code to the Arduino

 #include <SoftwareSerial.h>  
 SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.  
                // This means that you need to connect the TX line from the esp to the Arduino's pin 2  
                // and the RX line from the esp to the Arduino's pin 3  
 void setup()  
  esp8266.begin(115200); // your esp's baud rate might be different  
 void loop()  
  if(esp8266.available()) // check if the esp is sending a message   
    // The esp has data so display its output to the serial window   
    char c =; // read the next character.  
   // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest  
   // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it  
   // but we want to send everything at the same time.  
   String command="";  
   while(Serial.available()) // read the command character by character  
     // read one character  
   esp8266.println(command); // send the read character to the esp8266  

3- Once you have done uploading the code, open up Serial Monitor and then type in the following AT Commands to configure the wifi. You have to press ‘Enter’ on every line and have a look at the respond from Arduino on each command. Arduino will respond to the command with “OK” indicating that there is no problem with wiring connection. Otherwise, you have to recheck the wiring connection

  1. AT
  2. AT + RST
  3. AT+CWMODE = 3
  4. AT+CWJAP = “myWifi”,”abcd1234″

You must change the 4th command with your particular Wifi ID and Wifi Password. If everything is good, you will see a text respond from Arduino saying the wifi is connected and the IP address will displayed on the Serial Monitor as well. That’s all for this tutorial. Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: