I am able to use AT command from the Serial monitor however when I run the following code nothing is sent or received from the ESP8266. Can someone advise what could be the problem.

#include <SoftwareSerial.h>;

SoftwareSerial esp8266(0,1); // 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(9600); // 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 = esp8266.read(); // 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
SoftwareSerial esp8266(0,1)

You can't use pins 0 and 1 for software serial since they are the hardware serial Serial than you use for communication with the PC.

Pick two other pins to use.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.