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);
}
}
-
the red wire is not connected to anythingjsotola– jsotola2020年08月04日 06:42:29 +00:00Commented Aug 4, 2020 at 6:42
-
you mean the Main power Red wire right ?I removed the connection to take photo..GK_– GK_2020年08月04日 07:08:23 +00:00Commented Aug 4, 2020 at 7:08
-
What version of the NodeMCU is that?Majenko– Majenko2020年08月04日 09:55:33 +00:00Commented Aug 4, 2020 at 9:55
-
On back of board it mentioned, "Node MCU V3" and in front top right corner , ver 0.1GK_– GK_2020年08月04日 10:49:25 +00:00Commented Aug 4, 2020 at 10:49
-
1Does the relay work when you connect IN4 to Vcc ?SBF– SBF2020年08月04日 15:14:50 +00:00Commented Aug 4, 2020 at 15:14
1 Answer 1
I found that the 3V isn't enough to power the relay. https://www.instructables.com/Getting-Started-With-ESP8266LiLon-NodeMCU-V3Flashi/ shows the board supplies USB power (pin VU).
You can remove the jumper that connects signal voltage to relay power and connect the relay board to the USB power.
After that change I could turn the relays on and off, but I could not reliably power 4 relays, 2 relays as shown below seems fine.