I'm using a Relay Channel and NodeMCU(8266-WIFI). When i trigger the connection, LED Turns ON in Node MCU But the Relay connection is not working. I'm not sure what is the issue, Please help to fix it..
My Pin connection as follows.
- NodeMCU (VIN) -> Relay (VCC)
- NodeMCU (G) -> Relay (G)
- NodeMCU (D1) -> Relay (IN4)
My code as follows,
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <FirebaseCloudMessaging.h>
#include <Firebase.h>
#include <FirebaseHttpClient.h>
#include <FirebaseArduino.h>
#include <FirebaseError.h>
#include <FirebaseObject.h>
// Set these to run example.
#define FIREBASE_HOST "xxx-xxxx.firebaseio.com"
#define FIREBASE_AUTH "xxxxxx"
#define WIFI_SSID "xxxx"
#define WIFI_PASSWORD "xxxxx"
void setup() {
Serial.begin(9600);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
pinMode(D1, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.set("LED_STATUS",0);
}
int n = 0;
void loop() {
// Get value
n=Firebase.getInt("LED_STATUS");
if (n==1) {
digitalWrite(D1, LOW);
digitalWrite(LED_BUILTIN, LOW);
Serial.print("LED is ON ");
Serial.println(Firebase.getInt("LED_STATUS"));
delay(1000);
}
else{
//LED_BUILTIN
digitalWrite(D1, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("LED is OFF ");
Serial.println(Firebase.getInt("LED_STATUS"));
delay(1000);
}
}