3
votes

I have connected Arduino with ESP8266 with

Arduino pin 2 connected to ESP's Tx Arduino pin 3 connected to ESP's Rx via Voltage Divider Arduino GND connected to ESP's GND Arduino 3v3 connected to ESP's CH_PD

I have powered ESP8266 using 1117 Voltage regulator

When I initially bought ESp8266 it working but now it shows an endless stream of garbage values...

The arduino is programmed with the following code

#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(9600);
  esp8266.begin(9600); // your esp's baud rate might be different
}

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
  }
}
5
are you sure this is C?Natasha Dutta
Didn't you know?The Arduino language is merely a set of C/C++ functions that can be called from your code... Visit : arduino.cc/en/Main/FAQ for more informationAngryBird
@AngryBird Around here, there is no language called "C/C++". Arduino is more C++ than C.unwind
@angrybird So what? I did not understand how that make this particular code valid for c tag.Natasha Dutta
How does the esp8266 code looks like that sends the data? I use SoftwareSerial with esp-01 and have no problems using 9600 baud.August

5 Answers

2
votes

Your esp8266 is probably working at 56000 or 115200 baud rate and not 9600. This would cause garbage to be read.

If 115200 it won't work on normal digital pins with softwareSerial.

If an older board, then you can try changing to 56000:-

 esp8266.begin(56000); // your esp's baud rate might be different

Otherwise you will need to hook the esp8266 up to the HardwareSerial port

 Serial.begin(115200);
1
votes

The code seems to be ok, but you should checkout your ESP8266 baud rate maybe different. Checkout the following:

  1. Check the ESP8266 baud rate alone, once you have it, declare the same baud rate into your Arduino.

  2. Checkout your Arduino model, some clones like nano one drive different voltages than the original one,

0
votes

Upload the code and check the serial monitor for any response with a specific baud rate,if you didn't get any response on a specific baud rate then change the baud rate till you get the response. For few modules the default baud rate would be 57600.So check according to it.

You can use the given code above and change the baud rate of esp8266.begin(56000); change the baud rate like 9600,56000,112500 etc and check the serial monitor at 9600 baud rate.

Serial.begin(9600);

you will get the response on the monitor,and also try to reset the wifi module by connecting 3.3v to RST pin for 1-2 seconds. Hope it helps.

0
votes

As a compliment of the other answers, try replacing the voltage divider with a logical level converter, because esp has 3.3v logic, and arduino 5v logic.

0
votes

Check out logic value as esp8266 works on 3.3v and serial port baud rate. In few cases ESP8266 can have internal faults and produce garbage values. As far ESP8266 is concerned, checkout here It helped me a lot