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


#1

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.


#2

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.


#3

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


#4

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


#5

Also, reading the code, I believe your GPIO wiring is incorrect…

D1 is GPIO 5
D2 is GPIO 4

Cheers!


#6

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.


#7

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…


#8

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.


#9

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

~Benny


#10

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: