2 Channel Relay normal open is not working with NodeMCU but led on board light up

I am pretty new to NodeMCU (ESP8266) and Ardunio IDE in general. I followed various documentation / blogs to set up 2 Channel Relay with NodeMCU chip.

Below is sketch code for it.

#include<CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial

#define LEFT_GARAGE 4
#define RIGHT_GARAGE 5

char ssid[] = "XXXXXXXXXXXXXXXXXXXXXXXX";
char password[] = "XXXXXXXXXXXXXXXXXXXXXX";

char username[] = ""XXXXXXXXXXXXXXXXXXXXXX";";
char mqtt_password[] = ""XXXXXXXXXXXXXXXXXXXXXX";";
char client_id[] = ""XXXXXXXXXXXXXXXXXXXXXX";";

void setup() {
  Cayenne.begin(username, mqtt_password, client_id, ssid, password);
  pinMode(LEFT_GARAGE, OUTPUT);
  digitalWrite(LEFT_GARAGE, HIGH);
  pinMode(RIGHT_GARAGE, OUTPUT);
  digitalWrite(RIGHT_GARAGE, HIGH);
}

void loop() {
  Cayenne.loop();
}

// Left Garage Door
CAYENNE_IN(0){
  int currentValue = getValue.asInt();
  digitalWrite(LEFT_GARAGE,!currentValue);
  }

//Right Garage Door
CAYENNE_IN(1){
  digitalWrite(RIGHT_GARAGE,!getValue.asInt());
  }

On relay board I tried to connect wire in 2 different configuration.

1st Config:

vcc -> 3.3v from NodeMCU
in1 -> D1/GPIO 04 from NodeMCU
in2 -> D2/GPIO 5 from NodeMCU
GND -> GRD from NodeMCU

2nd Config:

vcc -> 5v usb from NodeMCU
in1 -> D1/GPIO 04 from NodeMCU
in2 -> D2/GPIO 5 from NodeMCU
GND -> GRD from NodeMCU

In 1st config, On relay board respective LEDā€™s are turning on when Cayenne buttons are pressed but when I check for continuity on multi meter I donā€™t get anything.

In 2nd config, no led and no continuity.

am I missing something here? Any feedback/comments are highly appreciated.

Hello and Welcome to the Cayenne Community.
Can you show us your relay specification? Maybe it is normally closed, and when you apply signal on some of the pins, it opens the relay? You can test it when you measure also when you do not apply a signal.

Thank you.

Can you post a link to the relay you are using?

Hi!
Are you sure your relay module is 3.3v?
Most of those modules are 5v, butā€¦ though the coil must be energized with 5v, the trigger ā€œsignalā€ can be 3.3v from the ESP (High state GPIO output).

This is how I connected mine. Works like a charmā€¦

Hope it helpsā€¦
Cheers
Marc

1 Like

Also, reading the code, I believe your GPIO wiring is incorrectā€¦

D1 is GPIO 5
D2 is GPIO 4

Cheers!

I have had problems getting my solid state relays to consistently work with just 3.3v (they re rated at 5v trigger). It could also be that the 3.3v doesnā€™t have enough mA to trip the switch inside the relay. I have a relay board with 2 relays that can be powered by a external source and then it just uses the MCU input to trigger it rather than power it. That way it only takes 5-10mA to trip it.

I also had a problem with a relay module. One time it works with 3.3 and other it does not workā€¦It depends on how many other consumers I have on my GPIOsā€¦

There has been a couple posts recently about relays not working, so for anyone here having problems with relays, this video describes why they do not with out of the box with 3.v gpio pins. If you use 5v for vcc on the relay coil circuit and 3.3v vcc on the trigger circuit it will solve the problems. As for the single channel relays, Iā€™m not sure how to hook them up. Google seems to offer lots of conflicting answers and I donā€™t have one to test with.

3 Likes

@ognqn.chikov @adam @vapor83 @spacefolder so good to see everyone helping out, a huge thank you from the Cayenne team!

~Benny

2 Likes

I will also suggest not buying cheap relay boards because they can burn the house! I was using a cheap 8 channel relay that was market as 15A. On 6A they melted down! Soā€¦I never ever buy parts from cheap suppliers. I use adafruit and other similar suppliers that they give warranty and seems legit :slight_smile:

1 Like