Getting started with ESP8266 Wifi Module (Arduino Interfacing)

Getting started with ESP8266 Wifi Module (Arduino Interfacing)

Hello, guys! Today in this tutorial I am going to show you how to interface ESP8266 Wifi Module.

For this tutorial we need:
                1) Arduino Uno
                2) ESP8266 Wifi Module
                3) An Arduino Cable
                4) PC or Laptop

Arduino Uno                                                                             ESP8266 Module

Arduino_uno 

 

The steps are actually quite simple but you need to be a little careful about the wiring. Hopefully, after this tutorial you will say, interfacing this module is much easier than you thought.

Here is the diagram of how to connect the wifi module to Arduino.


Code

Now upload the following code to the Arduino.

/*
 * taken from http://allaboutee.com/2014/12/27/esp8266-arduino-code-and-circuit/
 */


 
#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()
{
  Serial.begin(115200);
  esp8266.begin(115200); // your esp's baud rate might be different 
                         //try 9600 if this doesnt work
  
}
 
void loop()
{
  if(esp8266.available()) // check if the esp is sending a message 
  {
    while(esp8266.available())
    {
      // The esp has data so display its output to the serial window 
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    }  
  }
  
 
  
  if(Serial.available())
  {
    /*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.
    */
    delay(1000); 
    
    String command="";
    
    while(Serial.available()) // read the command character by character
    {
        // read one character
      command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}

 

Then go to Tools → Serial Monitor,.set your baud rate to 115200 (if that doesn’t work try 9600)  and your line endings to Both NL & CR.


Untitled

Type AT+RST in the message field and press Send. If everything went accordingly, it should respond with OK & READY with vendor name, version and some gibberish in between due to the buffer error of serial monitor .

Now you can send the required AT commands from here.


 

 

ESP8266 AT Command sets

Here is a list of basic AT Commands from an inscrutables I read.esp8266_AT_commands

Resources

So now you are good to go and develop the cool IoT projects you have in mind.

You can follow this youtube playlist to get going from here and there are a lot more other tutorials just a google away from you!!!

Things To Remember

Note that the ESP8266 is a 3.3v component and powering it from arduino 5V pin will damage the module. Although here we are connecting the Tx Rx pins of the arduino directly to the module which are 5v pins. In theory, it should harm the module as well but in practice, it does not. However, it would be best to use a 3.3v logic level converter from arduino to the module.

Feel free to comment if you face trouble following any part of this tutorial or need additional help!

Thank You!


What are your thoughts?