Unable to turn off Only 1 Relay (From 2 Relay)

Hi,

Im having problem to turn off only 1 Relay from 2. So the logic im trying to do is:

IF relay1 button is pressed: turn on relay1, IF relay 2 button is also pressed: turn on relay1 and relay2

IF relay2 button is pressed: turn on relay2, IF relay 1 button is also pressed: turn on relay2 and relay1

with this code Im able to turn on the relay, but the problem is I cant turn off only 1 relay. The relay will only turned off if I pressed both relay1 and relay2 button.

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

const char ssid[] = "Pratama";
const char pass[] = "123454321";
const char servername[] = "http://172.20.10.2/skripsi/esp-post-data.php";
WiFiClient client;
int device1_pin = 12;                            // NodeMCU pin D6/GPIO12 konek ke relay 1
int device2_pin = 14;                            // NodeMCU pin D5/GPIO14 konek ke relay 2
int device_status1;                         // Relay 1 status
int device_status2;                         // Relay 2 status

void setup() 
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT); 
  pinMode(device1_pin, OUTPUT);
  pinMode(device2_pin, OUTPUT);
  
  //setting koneksi wifi
  WiFi.hostname("NodeMCU");
  WiFi.persistent(false);
  WiFi.begin(ssid, pass);
  
  //cek koneksi WiFi
  while(WiFi.status() != WL_CONNECTED)
  {
    //nodemcu terus mencoba koneksi
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.println("PROTOTIPE MONITORING SUHU DAN SENSOR GERAK");
    Serial.println();
    Serial.println(".");
    delay(1000);
  }
  
  //apabila berhasil terkoneksi
  digitalWrite(LED_BUILTIN, LOW);
  Serial.println("WiFi Connected");

  //memulai server
  Serial.println("Server started");
  Serial.print(WiFi.localIP());
  delay(1000);
  Serial.println("connecting...");  
}

void relay() {
  if (WiFi.status() == WL_CONNECTED) 
  { 
    //Check WiFi connection status
    
    HTTPClient http;  //Declare an object of class HTTPClient
    /*----------------------------------------------*/

    http.begin("http://172.20.10.2/skripsi/device_status.php?did=1");  //Specify request destination
    int httpCode1 = http.GET();                                          //Send the request
    if (httpCode1 > 0) 
    { 
      //Check the returning code
      String payload = http.getString();   //Get the request response payload
      device_status1 = payload.toInt();
    }
    
    
    /*----------------------------------------------*/
    
    http.begin("http://172.20.10.2/skripsi/device_status.php?did=2");  //Specify request destination
    int httpCode2 = http.GET();                                          //Send the request
    if (httpCode2 > 0) 
    { 
      //Check the returning code
      String payload = http.getString();   //Get the request response payload
      device_status2 = payload.toInt();
    }
    
    
    http.end();   //Close connection
  }
  
  if(device_status1 == 1)
  {
     digitalWrite(device1_pin,LOW);
     Serial.println("Relay 1 ON");
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload 
     Serial.println(); 

     if(device_status2 == 1)
     {
     digitalWrite(device2_pin,LOW); 
     Serial.println("Relay 2 ON"); 
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload
     }
  }
  else if(device_status2 == 1)
  {
     digitalWrite(device2_pin,LOW);
     Serial.println("Relay 2 ON");
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload 
     Serial.println(); 

     if(device_status1 == 1)
     {
     digitalWrite(device1_pin,LOW); 
     Serial.println("Relay 1 ON"); 
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload
     }
  }
  
  else {
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload 
     Serial.println();
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload 
     Serial.println();
     fuzzy(); 
  }
  
    
    Serial.println("----------------------------------------------------");
    
}

void fuzzy() {
    //RUN FUZZY LOGIC
}

void loop() 
{
    relay();
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    delay(10000); 
}

Your logic seems overly complicated.

Isn't this equivalent to saying:

IF relay1 button is pressed: turn on relay1
IF relay2 button is pressed: turn on relay2

Tried to change IF part to:

if(device_status1 == 1)
  {
     digitalWrite(device1_pin,LOW);
     Serial.println("Relay 1 ON");
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload 
     Serial.println(); 
  }
  
  if(device_status2 == 1)
  {
     digitalWrite(device2_pin,LOW);
     Serial.println("Relay 2 ON");
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload 
     Serial.println(); 
  }
  
  else 
  {
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload 
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload 
     Serial.println();
     fuzzy(); 
  }

what happen is:

  1. When I pressed relay1 button, this shows in serial monitor:
Serial.println("Relay 1 ON");
Serial.print("Relay (Tombol) 1 Status=");
Serial.println(device_status1); //Print the response payload

but this part not working:

digitalWrite(device1_pin,LOW);

and void fuzzy() function is still running.

  1. When I pressed relay 2 button, this part works fine:
digitalWrite(device2_pin,LOW);
Serial.println("Relay 2 ON");
Serial.print("Relay (Tombol) 2 Status=");
Serial.println(device_status2); //Print the response payload 
Serial.println(); 

also relay 1 part that is not working earlier:

digitalWrite(device1_pin,LOW);

its working now when I pressed relay 2 button. And fuzzy() function is stopped to as expected.

Are you certain you have the correct pin connected?

Maybe the relay module is faulty. Can you post your new code in full, and a schematic/pic of how you have everything connected.

Here's the fullcode and the breadboard wiring scheme


:

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <DHT.h>

//setting variable sensor
#define DHTTYPE DHT11     
#define DHTPIN 10          // NodeMCU pin SD3/GPIO 10 konek ke DHT-11 Signal pin
DHT dht(DHTPIN, DHTTYPE);

// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /esp-post-data.php also needs to have the same key
String apiKeyValue = "tPmAT5Ab3j7F9";
String sensorName = "DHT11";
String sensorLocation = "Office";


//setting jaringan 
const char ssid[] = "Pratama";
const char pass[] = "123454321";
const char servername[] = "http://172.20.10.2/skripsi/esp-post-data.php";
WiFiClient client;

float Val,Val1  ;                           // Inisialilasasi Input
float m_suhu, m_jarak;                      // Inisialilasasi Derajat Keanggotaan 
float dingin, hangat, panas;                // Inisialilasasi Membership Function suhu
float dekat, sedang, jauh;                  // Inisialilasasi Membership Function jarak
float dingin_1, hangat_1, panas_1;          // Inisialilasasi Membership yang aktif
float dekat_1, sedang_1, jauh_1;            // Inisialilasasi Membership yang aktif
float Lmax=0, Mmax=0, Hmax=0;               // Inisialilasasi Defuzzification
float fsmax=0;                              // Inisialilasasi nilai maksimum
float num, den, output;                     //Inisialilasasi defuzzification
int device1_pin = 12;                            // NodeMCU pin D6/GPIO12 konek ke relay 1
int device2_pin = 14;                            // NodeMCU pin D5/GPIO14 konek ke relay 2
int device_status1;                         // Relay 1 status
int device_status2;                         // Relay 2 status
unsigned int EchoPin = 13;                  // NodeMCU pin D7/GPIO13 konek ke US-100 echo/RX
unsigned int TrigPin = 15;                  // NodeMCU pin D8/GPIO15 konek ke US-100 Trig / TX
unsigned long Time_Echo_us = 0; 
//unsigned long jaraksensor  = 0;  
float jaraksensor;                          
float suhusensor;
float suhumanual;
float jarakmanual;

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;

// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 30 seconds (30000)
unsigned long timerDelay = 30000;



// ------------------------------------------------- Fuzzification ------------------------------------------------------------

                                                                                                                                            
void setup() 
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT); 
  pinMode(device1_pin, OUTPUT);
  pinMode(device2_pin, OUTPUT);
  pinMode(EchoPin, INPUT);    //  The set EchoPin input mode.
  pinMode(TrigPin, OUTPUT);   //  The set TrigPin output mode.
  dht.begin();
  
  
  
  //setting koneksi wifi
  WiFi.hostname("NodeMCU");
  WiFi.persistent(false);
  WiFi.begin(ssid, pass);
  
  //cek koneksi WiFi
  while(WiFi.status() != WL_CONNECTED)
  {
    //nodemcu terus mencoba koneksi
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.println("PROTOTIPE MONITORING SUHU DAN SENSOR GERAK");
    Serial.println();
    Serial.println(".");
    delay(1000);
  }
  
  //apabila berhasil terkoneksi
  digitalWrite(LED_BUILTIN, LOW);
  Serial.println("WiFi Connected");

  //memulai server
  Serial.println("Server started");
  Serial.print(WiFi.localIP());
  delay(1000);
  Serial.println("connecting...");  
}

void suhu()
{
  suhusensor = dht.readTemperature();  
  suhumanual = 38;
}

void jarak() 
{
  digitalWrite(TrigPin, HIGH);                         // Send pulses begin by Trig / Pin
  delayMicroseconds(50);                               // Set the pulse width of 50us (> 10us)
  digitalWrite(TrigPin, LOW);                          // The end of the pulse    
  Time_Echo_us = pulseIn(EchoPin, HIGH);               // A pulse width calculating US-100 returned
  if((Time_Echo_us < 60000) && (Time_Echo_us > 1)) 
  {   
  // Pulse effective range (1, 60000).
  // jaraksensor = (Time_Echo_us * 0.34mm/us) / 2 (mm) 
  jaraksensor = (Time_Echo_us*34/100)/2;                   // Calculating the distance by a pulse width.   
  }
  jarakmanual = 400 ;
}

void relay() {
  if(device_status1 == 1)
  {
     digitalWrite(device1_pin,LOW);
     Serial.println("Relay 1 ON");
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload 
     Serial.println(); 
  }
  
  if(device_status2 == 1)
  {
     digitalWrite(device2_pin,LOW);
     Serial.println("Relay 2 ON");
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload 
     Serial.println(); 
  }
  
  else 
  {
     Serial.print("Relay (Tombol) 1 Status=");
     Serial.println(device_status1); //Print the response payload 
     Serial.print("Relay (Tombol) 2 Status=");
     Serial.println(device_status2); //Print the response payload 
     Serial.println();
     fuzzy(); 
  }
  
    
    Serial.println("----------------------------------------------------");
    
}
 
void fuzzy() 
{
// ----------------------------------------- Membership Function ---------------------------------------------

/*
 //SUHU DAN JARAK MENGGUNAKAN INPUT MANUAL

 if(suhumanual <= 25)
    {
      dingin=1; 
      hangat=0; 
      panas=0;
    }
 else if(suhumanual >= 35)
    {
      panas=1; 
      dingin=0; 
      hangat=0;
    }
 else if(suhumanual == 30)
    {
      hangat=1; 
      dingin=0; 
      panas=0;
    }   
 else if((suhumanual > 25)&&(suhumanual <30))   
     {
      hangat = (suhumanual-25)/5;
      dingin = 1-(suhumanual-25)/5;
      panas = 0;
     }
 else if((suhumanual > 30)&&(suhumanual < 35))
     {
     panas = (suhumanual-30)/5;
     hangat = 1-(suhumanual-30)/5;
     dingin = 0; 
     }
 
                                                                                                                                              
 if(jarakmanual<150)
    {
      dekat = 1;
      sedang = 0;
      jauh = 0;
    }
 else if(jarakmanual >= 350)
    {
      jauh = 1;
      dekat = 0;
      sedang = 0; 
    }
 else if(jarakmanual == 250)
    {
      sedang = 1;
      dekat = 0;
      jauh = 0;
    }
 else if((jarakmanual > 150)&&(jarakmanual < 250))
    {
      sedang = (jarakmanual-150)/100;
      dekat = 1-(jarakmanual-150)/100;
      jauh = 0;
    }
 else if((jarakmanual > 250)&&(jarakmanual < 350))
    {
      jauh = (jarakmanual-250)/100;
      sedang = 1-(jarakmanual-250)/100;
      dekat = 0;
    }
*/


 //SUHU DAN JARAK MENGGUNAKAN INPUT DARI SENSOR

 
 if(suhusensor <= 25)
    {
      dingin=1; 
      hangat=0; 
      panas=0;
    }
 else if(suhusensor >= 35)
    {
      panas=1; 
      dingin=0; 
      hangat=0;
    }
 else if(suhusensor == 30)
    {
      hangat=1; 
      dingin=0; 
      panas=0;
    }   
 else if((suhusensor > 25)&&(suhusensor <30))   
    {
      hangat = (suhusensor-25)/5;
      dingin = 1-(suhusensor-25)/5;
      panas = 0;
    }
 else if((suhusensor > 30)&&(suhusensor < 35))
    {
     panas = (suhusensor-30)/5;
     hangat = 1-(suhusensor-30)/5;
     dingin = 0; 
    }
 
                                                                                                                                              
    {
      dekat = 1;
      sedang = 0;
      jauh = 0;
    }
 else if(jaraksensor >= 350)
    {
      jauh = 1;
      dekat = 0;
      sedang = 0; 
    }
 else if(jaraksensor == 250)
    {
      sedang = 1;
      dekat = 0;
      jauh = 0;
    }
 else if((jaraksensor > 150)&&(jaraksensor < 250))
    {
      sedang = (jaraksensor-150)/100;
      dekat = 1-(jaraksensor-150)/100;
      jauh = 0;
    }
 else if((jaraksensor > 250)&&(jaraksensor < 350))
    {
      jauh = (jaraksensor-250)/100;
      sedang = 1-(jaraksensor-250)/100;
      dekat = 0;
    }

 
//  ----------------------------------------- Mechanism Inference  ----------------------------------------

  if (dingin >0)          
  {
    dingin_1  = 1;
    }    
  else 
    {
    dingin_1  = 0;
    }
  
  if (hangat >0)          
  {
    hangat_1  = 1;
    }    
  else 
    {
    hangat_1  = 0;
    }
  
  if (panas >0)           
  {
    panas_1   = 1;
  }    
  else 
  {
    panas_1   = 0;
  }
  
  if (dekat   >0)         
  {
    dekat_1 = 1;
  }      
  else 
  {
    dekat_1   = 0;
  }
  
  if (sedang  >0)         
  {
    sedang_1 = 1;
  }   
  else 
  {
    sedang_1  = 0;
  }
  if (jauh    >0)         
  {
    jauh_1 = 1;
  }       
  else 
  {
    jauh_1    = 0;
  }
  

  
  float L[4]={0,1,2,3};                                                                                        // Low output, relay mati keduanya
  {
  if (dingin_1==1 && dekat_1==1)                {L[1]=min(dingin,dekat);}   else {L[1]=0;}  
  if (dingin_1==1 && sedang_1==1)               {L[2]=min(dingin,sedang);}  else {L[2]=0;}  
  if (dingin_1==1 && jauh_1==1)                 {L[3]=min(dingin,jauh);}    else {L[3]=0;}  
  }
  
  float M[6]={0,1,2,3,4,5};                                                                                            // Medium output, 1 relay aktif
  {
  if (hangat_1==1 && dekat_1==1)                {M[1]=min(hangat,dekat);}   else {M[1]=0;}  
  if (hangat_1==1 && sedang_1==1)               {M[2]=min(hangat,sedang);}  else {M[2]=0;}  
  if (hangat_1==1 && jauh_1==1)                 {M[3]=min(hangat,jauh);}    else {M[3]=0;}  
  if (panas_1==1 && dekat_1==1)                 {M[4]=min(panas,dekat);}    else {M[4]=0;}  
  if (panas_1==1 && sedang_1==1)                {M[5]=min(panas,sedang);}   else {M[5]=0;}  
  }
                                                                                                                                                   
  float H[2]={0,1};                                                                                         // High output, 2 relay aktif
  {
  if (panas_1==1 && jauh_1==1)                   {H[1]=min(panas,jauh);}             else {H[1]=0;} 
  }
 
                                                                                                                                               
  Lmax=L[0];    int index1=0;  for (int a=1; a<=3; a++)  {   if(Lmax<=L[a])      { Lmax=L[a];       index1=a;}  }
  Mmax=M[0];    int index2=0;  for (int b=1; b<=5; b++)  {   if(Mmax<=M[b])      { Mmax=M[b];       index2=b;}  }
  Hmax=H[0];    int index3=0;  for (int c=1; c<=1; c++)  {   if(Hmax<=H[c])      { Hmax=H[c];       index3=c;}  }
  
  
// --------------------------------------------------------------------------- End Interface Mechanism ----------------------------------------------------------------

// --------------------------------------------------------------------------- Defuzzyfication  -----------------------------------------------------------------------//

float num = (Lmax*0) + (Mmax*50) + (Hmax*100);
float den =  Lmax + Mmax + Hmax;
float output = num/den;

if(output < 50) {
  digitalWrite(device1_pin, HIGH);
  Serial.print("relay 1: MATI");
  Serial.println(" ");
  digitalWrite(device2_pin, HIGH);
  Serial.print("relay 2: MATI");
  Serial.println(" ");
  }
else if(output >= 50 && output <=80) {
  digitalWrite(device1_pin, LOW);
  Serial.print("relay 1: HIDUP");
  Serial.println(" ");
  digitalWrite(device2_pin, HIGH);
  Serial.print("relay 2: MATI");
  Serial.println(" ");
}
else {
  digitalWrite(device1_pin, LOW);
  Serial.print("relay 1: HIDUP");
  Serial.println(" ");
  digitalWrite(device2_pin, LOW);
  Serial.print("relay 2: HIDUP");
  Serial.println(" ");
  }

 //Hasil print


  
  Serial.print("suhu (dari sensor): ");
  Serial.println(suhusensor);
  Serial.print("suhu (manual): ");
  Serial.println(suhumanual);
   
  Serial.print("jarak (dari sensor): ");              // Output to the serial port monitor 
  Serial.print(jaraksensor, DEC);                     // Output to the serial port monitor   
  Serial.println("mm");                               // Output to the serial port monitor
  Serial.print("jarak (manual): ");              // Output to the serial port monitor 
  Serial.print(jarakmanual);                     // Output to the serial port monitor   
  Serial.println("mm");                               // Output to the serial port monitor

  
  Serial.print("dingin : ");
  Serial.println(dingin);
  Serial.print("hangat : ");
  Serial.println(hangat);
  Serial.print("panas : ");
  Serial.println(panas);
  Serial.print("dekat : ");
  Serial.println(dekat);
  Serial.print("sedang : ");
  Serial.println(sedang);
  Serial.print("jauh : ");
  Serial.println(jauh);
  Serial.print("m_suhu : ");
  Serial.println(m_suhu);
  Serial.print("m_jarak : ");
  Serial.println(m_jarak);
  Serial.print("L 0 : ");
  Serial.println(L[0]);
  Serial.print("L 1 : ");
  Serial.println(L[1]);
  Serial.print("L 2 : ");
  Serial.println(L[2]);
  Serial.print("L 3 : ");
  Serial.println(L[3]);
  Serial.print("M 0 : ");
  Serial.println(M[0]);
  Serial.print("M 1 : ");
  Serial.println(M[1]);
  Serial.print("M 2 : ");
  Serial.println(M[2]);
  Serial.print("M 3 : ");
  Serial.println(M[3]);
  Serial.print("M 4 : ");
  Serial.println(M[4]);
  Serial.print("M 5 : ");
  Serial.println(M[5]);
  Serial.print("H 0 : ");
  Serial.println(H[0]);
  Serial.print("H 1 : ");
  Serial.println(H[1]);
  
  Serial.print("num : ");
  Serial.println(num);
  Serial.print("den : ");
  Serial.println(den);
  Serial.print("output : ");
  Serial.println(output);
  Serial.println("----------------------------------------------------");
   
}



void httppost()
{
  //Send an HTTP POST request every 10 minutes
  if ((millis() - lastTime) > timerDelay) {
    //Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      WiFiClient client;
      HTTPClient http;

      // Your Domain name with URL path or IP address with path
      http.begin(client, servername);

      // Specify content-type header
      http.addHeader("Content-Type", "application/x-www-form-urlencoded");

      // Prepare your HTTP POST request data
      String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
                            + "&location=" + sensorLocation + "&value1=" + String(dht.readTemperature())
                            + "&value2=" + String(dht.readHumidity()) + "&value3=" + jaraksensor + "";
      //Serial.print("httpRequestData: ");
      //Serial.println(httpRequestData);

      // You can comment the httpRequestData variable above
      // then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)
      //String httpRequestData = "api_key=tPmAT5Ab3j7F9&sensor=BME280&location=Office&value1=24.75&value2=49.54&value3=1005.14";

      // Send HTTP POST request
      int httpResponseCode = http.POST(httpRequestData);

      // If you need an HTTP request with a content type: text/plain
      //http.addHeader("Content-Type", "text/plain");
      //int httpResponseCode = http.POST("Hello, World!");

      // If you need an HTTP request with a content type: application/json, use the following:
      //http.addHeader("Content-Type", "application/json");
      //int httpResponseCode = http.POST("{\"value1\":\"19\",\"value2\":\"67\",\"value3\":\"78\"}");

      if (httpResponseCode>0) {
        Serial.print("HTTP Response code: ");
        Serial.println(httpResponseCode);
        Serial.println("----------------------------------------------------");
      }
      else {
        Serial.print("Error code: ");
        Serial.println(httpResponseCode);
        Serial.println("----------------------------------------------------");
      }
      // Free resources
      http.end();
    }
  }
}

void loop() 
{
    suhu(); 
    jarak();
    httppost();
    relay();
    //Serial.println("IP address: ");
    //Serial.println(WiFi.localIP());
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    Serial.println("----------------------------------------------------");
    delay(10000); 
}

Since I cant post 2 image, here's the breadboard fullview version:

Are they 5v relays? Do they work if connect VCC/GND to signal IN?

How are you powering everything?

Yes it is 5v relays with optocoupler. Since I heard NodeMCU can control 5v relays with optocoupler. Is it not true?

I powered everything with USB port connection.

There are 2 things to consider...

1). The relay requires 5v to power the coil... you are only supplying 3.3v.

2). The trigger (signal) voltage will also be a 5v logic level. This may still work using a 3.3 voltage level but you would need to check the Datasheet for the module.

I see, I'll try to buy the 3.3V version today then. Thank you very much for the insight sir.

Shouldn't you use '6' or 'D6' for pin D6 and '5' or 'D5' for Pin D5? Arduino doesn't use physical pin numbers or GPIO pin numbers.

I'm sorry but I'm using NodeMCU ESP8266 sir. So far what I found the problem appeared only on some 3.3V and GND PIN as I asked on another thread here:

Blockquote
Relay not switching/clicking on some NodeMCU ESP8266 PIN