ESP8266 Not Working after following tutorial

Hey! I recently got an ESP8266 module and attempted to set it up using this tutorial. However, I have been unable to get it to work as intended.

The first part of the tutorial works fine, where he hooks up the ESP8266 directly to the RX and TX of the Arduino. I was able to use AT commands to communicate with the module and connect it to my WiFi network. However, when I tried the second part, which involves using SoftwareSerial to talk to the module to automatically initialize it and use it as a server, I get really garbled responses in the serial monitor. I am able to see the IP address of the module however, but every time I try to connect in my browser the connection times out. This is what I see in the serial monitor (obviously network details have been censored):

WIFI C�ʪ�(UTH�WICI GOT IP
A*��U�}1
�bu�^��rrj

OKC�AT+CIFSR

Aj��R�*�Hli%MI�
AIP,"{IP ADDRESS CENSORED}"
+CIFSR=APMAC,"{CENSORED}�C��%A�r�
�U5�����
j�AT+CIPMUX=1

A*�P�H�UՊj
�j�H�AT+CIPSERVER=1,80

AT��
5-IY�R=1�8�C�jդ�

And this is the code I am running. I slightly modified it for easier debugging but other than a couple Serial.print statements its the same as the tutorial:

#include <SoftwareSerial.h>                        
SoftwareSerial esp8266(10,11);                   
#define serialCommunicationSpeed 115200               
#define DEBUG true                                 

void setup()

{
  Serial.begin(serialCommunicationSpeed);  
  Serial.println("Serial ok");         
  esp8266.begin(serialCommunicationSpeed);     
  InitWifiModule();                              
}

void loop()                                                         
{

  if(esp8266.available())                                           
 {    
    if(esp8266.find("+IPD,"))
    {
     Serial.println("Request Recieved");
     delay(1000);
 
     int connectionId = esp8266.read()-48;                                                
     String webpage = "<h1>Hello World!</h1>";
     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);
 
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";    
     sendData(closeCommand,3000,DEBUG);
    }
  }
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";                                             
    esp8266.print(command); 
    Serial.println(command);                                         
    long int time = millis();                                      
    while( (time+timeout) > millis())                                 
    {      
      while(esp8266.available())                                      
      {
        char c = esp8266.read();                                     
        response+=c;                                                  
      }  
    }    
    if(debug)                                                        
    {
      Serial.print(response);
    }    
    return response;                                                  
}

void InitWifiModule()
{
  sendData("AT+RST\r\n", 2000, DEBUG);                                                  
  sendData("AT+CWJAP=\"{WIFI NETWORK CENSORED}\",\"{WIFI PASS CENSORED}\"\r\n", 2000, DEBUG);        
  delay (5000);
  sendData("AT+CWMODE=1\r\n", 1500, DEBUG);                                             
  delay (5000);
  sendData("AT+CIFSR\r\n", 1500, DEBUG);                                             
  delay (5000);
  sendData("AT+CIPMUX=1\r\n", 1500, DEBUG);                                             
  delay (5000);
  sendData("AT+CIPSERVER=1,80\r\n", 1500, DEBUG);                                     

}

All wiring is the same as the tutorial. Any help would be much appreciated. Thank you.

Welcome to the forum

What baud rate have you got the Serial monitor set to ?

115200, that baudrate works when communicating directly to the module (see the tutorial I was following)

can you upload a schematic showing how you connected up the system
I assume you are using an ESP-01?

The schematic is in the tutorial video, here's a screenshot:

Try a lower speed

Circuit looks Ok with voltage divider etc
however, you will have problems running SoftwareSerial at 115200baud on an Arduino UNO
I would switch to an Arduino Mega or an Arduino Due which have hardware serial ports
this is how I connect a ESP-01 to a Mega


Arduino Due is similar but does not require the voltage divider as it uses 3.3V logic

I think I have to change the firmware to do that and that requires a sketchy Chinese software that you download as a .zip from google drive. I don't want to do that if I can avoid it for obvious reasons.

I was already using a Mega, thanks for letting me know about the hardware serial ports. Do I have to make any changes to the software other than the pins?

I tried that however now I am not getting any response from the ESP8266. I did change the pins in the software but I am not getting any response at all in the serial monitor.

I assume that you changed the Serial begin to use the hardware interface pins that you used and did not just change the pins used by SoftwareSerial

Shoot I did just change the pins used by softwareserial. I'm a little new to this, rookie mistake sorry

Thank you for all the help. Everything works now and I am able to connect to the ESP8266. For anyone coming to this thread, the solution was to use and Arduino Mega's hardware serial ports instead of softwareserial to communicate with the module. Here is the code if anyone needs it:

#define serialCommunicationSpeed 115200               
#define DEBUG true                                 

void setup()

{
  Serial.begin(serialCommunicationSpeed);  
  Serial.println("Serial ok");         
  Serial1.begin(serialCommunicationSpeed);     
  InitWifiModule();                              
}

void loop()                                                         
{

  if(Serial1.available())                                           
 {    
    if(Serial1.find("+IPD,"))
    {
     Serial.println("Request Recieved");
     delay(1000);
 
     int connectionId = Serial1.read()-48;                                                
     String webpage = "<h1>Hello World!</h1>";
     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);
 
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";    
     sendData(closeCommand,3000,DEBUG);
    }
  }
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";                                             
    Serial1.print(command); 
    Serial.println(command);                                         
    long int time = millis();                                      
    while( (time+timeout) > millis())                                 
    {      
      while(Serial1.available())                                      
      {
        char c = Serial1.read();                                     
        response+=c;                                                  
      }  
    }    
    if(debug)                                                        
    {
      Serial.print(response);
    }    
    return response;                                                  
}

void InitWifiModule()
{
  sendData("AT+RST\r\n", 2000, DEBUG);                                                  
  sendData("AT+CWJAP=\"WIFI NETWORK\",\"PASSWORD\"\r\n", 2000, DEBUG);        
  delay (5000);
  sendData("AT+CWMODE=1\r\n", 1500, DEBUG);                                             
  delay (5000);
  sendData("AT+CIFSR\r\n", 1500, DEBUG);                                             
  delay (5000);
  sendData("AT+CIPMUX=1\r\n", 1500, DEBUG);                                             
  delay (5000);
  sendData("AT+CIPSERVER=1,80\r\n", 1500, DEBUG);                                     

}

By the way, I am using the Keyestudio module.

any particular reason why you are adding WiFi capability to a Mega?
why not port the project to an ESP32 ?
gives you more power, flash and SRAM plus builtin WiFi and Bluetooth
if you need a mega to support exising sensors etc consider a Mega-WiFi_R3_ATmega2560_ESP8266

Because it's cheaper and what I have on hand right now :slight_smile:

good point!
if later on you wish to port the project to a Mega-WiFi_R3_ATmega2560_ESP8266 it would be simple to port the ESP-01 code to the onboard ESP8266 and the Mega communicates with it using Serial3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.