Nodemcu - relay not being triggered using an external power source **SOLVED**

Hello,

I’ve been playing around with a relay the past two nights. First off using an Uno, which triggered the relay to power and LED. Then using a push button. Next step, using an external power source, so the board was separate from switching transients/current. All worked fine.

Then I tried with a Nodemcu, as I intend to put this into practice using wifi. It was a bit faffy at first as I had to get the pin labels correct but I eventually got it working, and the LED lit up.

I know the board is 3.3V, so I used and external 5V source to power the LED on the switching side, which worked. Now the odd thing, or to me at least. If I connected the relay to an external source, nothing happened. If I connected the relay to 3.3V and GND of the board, it worked. Now that just doesnt make sense to be. Fair enough, a 3.3V signal wont drive the relay but I’m not sure how the external power source gets in the way, I’d have thought the problem would be vice versa.

Having googled it, I’ve come across using a transistor would help with a 3.3V signal but I still don’t get how I wouldnt have the same problem.

I’m using this relay board module

Youmile 5-Pack 5V One 1 Channel Relay Module Board Shield For PIC AVR DSP ARM MCU Arduino

Thanks for the help

I think folks would be better able to help if you could post a schematic or at least a sketch.

For instance.

If I connected the relay to an external source, nothing happened. If I connected the relay to 3.3V and GND of the board, it worked. Now that just doesnt make sense to be. Fair enough, a 3.3V signal wont drive the relay but I'm not sure how the external power source gets in the way

It's difficult for us not seeing what you are doing to know what and where you are hooking up the relay.

I believe the relay you have shown needs 4 connections;
Two from the relay input to the processor board.
Another two from the relay contacts to the LED.

Also we need to know how your grounds are connected.

JohnRob:
I think folks would be better able to help if you could post a schematic or at least a sketch.

For instance.

It's difficult for us not seeing what you are doing to know what and where you are hooking up the relay.

I believe the relay you have shown needs 4 connections;
Two from the relay input to the processor board.
Another two from the relay contacts to the LED.

Also we need to know how your grounds are connected.

Sorry about not adding the sketch, I’d packed up and was on the way to bed. Will put it up later.
With an external power source, I’ve not done a common ground between the nodemcu and the relay as I thought I wouldn’t need to. I can’t remember if I tried that though.

Here is the code and a terrible hand drawn schematic. I'll have to try the common ground later to the nodemcu, although I was trying to avoid this due to switching transients. But I can't remember if I already tried that.

If I connect the 3.3V and ground of the Nodemcu, it works, but not the way shown.

int relay_pin = 5;
//int led_pin = 4;

void setup(){ 
  pinMode(relay_pin,OUTPUT);
//  pinMode(led_pin,OUTPUT);  
//digitalWrite(led_pin,HIGH);
}

void loop(){
  digitalWrite(relay_pin,HIGH);
  delay(5000);
  digitalWrite(relay_pin,LOW);
  delay(5000);
}

I don't see a GND connection between relay and ESP, just a single line from a GPIO pin to the relay module. That won't work indeed.

Always connect grounds together.

wvmarle:
I don't see a GND connection between relay and ESP, just a single line from a GPIO pin to the relay module. That won't work indeed.

Always connect grounds together.

I thought I’d tried connecting the grounds but couldn’t remember, I may have, as I just tried again and nothing happened. The external source was 5V. Having changed the source to 3.3V, it weirdly worked.

Should I have some sort of protection between the ground and the nodemcu