Nodemcu connecting to Wi-Fi Problem I am trying to connect to Wi-Fi with Digital pin declaration in setup() function it's not connecting to wi-fi. But connecting to wi-fi without digital pin diclaration. `

#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266HTTPClient.h&gt;
int m1 = 5;
int m2 = 6;
const char* ssid = "KS Infotech";
const char* password = "kalamsalam";
String readc = ""; 
void setup () {
pinMode(m1, OUTPUT);
digitalWrite(m1, LOW);
pinMode(m2, OUTPUT);
digitalWrite(m2, LOW);
Serial.begin(9600);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print("Connecting..");

}

}

void loop() {
while (Serial.available()){  //Check if there is an available byte to read
delay(10); //Delay added to make thing stable 
char c = Serial.read(); 
String T = String(readc);
    Serial.println(T); 
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

HTTPClient http;  //Declare an object of class HTTPClient

http.begin("http://ksinfotech.co/kslab/write_to_database.php?incoming="+T+"&amp;UID=surya");  //Specify request destination
int httpCode = http.GET();                                                                  


if (httpCode &gt; 0) { //Check the returning code

  String payload = http.getString();   //Get the request response payload
  Serial.println(payload);                     //Print the response payload
  if (payload == 'N');
  {
  digitalWrite(m1, HIGH);
  digitalWrite(m2, LOW);
  delay(2000);
  digitalWrite(m1, LOW);
  digitalWrite(m1, LOW);
}
      if (payload == 'F');
  {
  digitalWrite(m1, LOW);
  digitalWrite(m2, HIGH);
  delay(2000);
  digitalWrite(m1, LOW);
  digitalWrite(m1, LOW);
}

http.end();   //Close connection

}

delay(30000);    //Send a request every 30 seconds

}


The above code not working but the below code working.

#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266HTTPClient.h&gt;

const char* ssid = "KS Infotech";
const char* password = "kalamsalam";
String readc = ""; 
void setup () {

Serial.begin(9600);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print("Connecting..");

}

}

void loop() {
while (Serial.available()){  //Check if there is an available byte to read
delay(10); //Delay added to make thing stable 
char c = Serial.read(); 
if (c == '#'){
  break;                   //Stop the loop once # is detected after a word
}//Conduct a serial read
readc += c; //build the string- "forward", "reverse", "left" and "right"
} 
String T = String(readc);
    Serial.println(T); 
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

HTTPClient http;  //Declare an object of class HTTPClient

http.begin("http://ksinfotech.co/kslab/write_to_database.php?incoming="+T+"&amp;UID=surya");  //Specify request destination
int httpCode = http.GET();                                                                  
 //Send the request

if (httpCode &gt; 0) { //Check the returning code

  String payload = http.getString();   //Get the request response payload
  Serial.println(payload);                     //Print the response payload

}

http.end();   //Close connection

}

delay(30000);    //Send a request every 30 seconds

}
use D5 and D6, not 5 and 6. D5 is IO 14, D6 is IO 12. IO 5 is D1 and IO 6 is SDIO_CLK for the flash memory and that is your problem. 

the reference