Nodemcu not connecting to wifi when we initializing Digital Pins.

I am trying to connect to wifi in Nodemcu 12e it is not connecting when we initializing digital pins in setup function. With out digital pins initializing it is working. Here i am attaching the code. Please rectify it.

IOT_TOLLGATE.txt (1.74 KB)

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 <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
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+"&UID=surya");  //Specify request destination
    int httpCode = http.GET();                                                                  //Send the request
 
    if (httpCode > 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 <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
 
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+"&UID=surya");  //Specify request destination
    int httpCode = http.GET();                                                                  //Send the request
 
    if (httpCode > 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 GPIO 14, D6 is GPIO 12. GPIO 5 is D1 and GPIO 6 is not available and that is your problem

What physical GPIO pins do pin 5 and pin 6 map to? Do those GPIO pins have a special function?

Have you tried different pins? Perhaps your unspecified device is using pins 5 and 6 already.

and that is you problem

Well, that and duplicate posting.

PaulS: Well, that and duplicate posting.

triple (SE link)

@surya1993, do not cross-post. Threads merged.

groundFungus: What physical GPIO pins do pin 5 and pin 6 map to? Do those GPIO pins have a special function?

IO 6 is SDIO_CLK for the flash memory

Sorry for re-posting. I am new to this forum i am trying to edit my post but i am not find any edit option that's why i re-posted . Thanks for your answers my problem solved.