ESP8266 01 wifi module I have a weird problem  , as I.m trying to connect to esp8266 01 with Arduino Uno when i try sending commands from the serial it doesn't work but if i send it in a function in the setup phase it works

#include &lt;SoftwareSerial.h&gt;

SoftwareSerial esp8266(2, 3);

void setup()
{
Serial.begin(9600);
esp8266.begin(9600);
delay(1000);
//sendData("AT", 1000);
//sendData("AT+CWMODE=1", 1000);
}

void loop() {
// put your main code here, to run repeatedly:
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())
  {
    delay(1000);
    String command="";
    while(Serial.available()) // read the command character by character
    {
        command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}

void sendData(String command, const int timeout) {
 String response = "";
 esp8266.println(command);
 long int time = millis();
 while ((time + timeout) &gt; millis())
   while (esp8266.available()) {
     char c  = esp8266.read();
     response += c;
    }
 Serial.println(response);
}
I take your code as a test sketch and will not comment on the terrible way you read Serial input.

The AT firmware requires \r\n as command ending characters. You can set them in Serial Monitor as option LN &amp; CR, but then use print to send the command to esp8266.

Or set in Serial Monitor "No line ending" and let in sketch the println to send the command. println adds \r\n to printed string.

If you had only "New line" set in Serial Monitor and used println the resulting command was for AT firmware disturbing "AT\n\r\n".