nodemcu-devkit-v1.0
nodemcu-devkit-v1.0 copied to clipboard
Connect relay board to NodeMCU
Hello, I've a relay board with 3 pins, VCC, GND and IN. I've connected VCC to 3.3 and GND to GND of MCU. In is connected to a GPIO pin. With pinMode(pin, OUTPUT); and digitalWrite(RELAY1,LOW); and digitalWrite(RELAY1,LOW); relay doesn't work. I've tested that if I connect relay IN pin to VCC it doesn't work but if I connect it to GND it work. This relay hasn't jumper to set if it should work in HIGHT or LOW. I suppose that MCU GPIO should provide a GND signal to turn on relay but I don't know how. Can you help me ?
Probably not supplying the correct pinout. Also you would need to define "RELAY1" to the pin you're using.
Google how to use relay with Arduino, and you will get your basic setup. Also there are several videos of the NodeMCU used with relays.
No need to post under issues, as you're inability to use a simple relay is not an issue with NodeMCU
If I connect led anode (+) to the same GPIO and led catode (-) to GND it works so GPIO is controlled correctly, but if the same GPIO is connected to IN pin of relay, it doesn't work.
http://bfy.tw/F33K
Many thanks but it is what I've done and I'm sure that relay is connected well, as explained on internet. You haven't understand my question. I think that the problem is that this relay board work with low signal, GND to be clear. But a GPIO is not able to send a GND signal bit a positive signal from 0 to 3.3V. I think that with a transistor I can resolve but I'm searching other solutions.
No, relays work the same. You have POWER or NO POWER to the input/trigger. Which Opens or Closes the gate/circuit depending on the NC/NO state of the relay. By connecting to GND you are basically providing NO POWER to the input/trigger.
You are almost 100% referencing the wrong GPIO in your code, or have not correctly defined your pin
Ok but I've wrote that if I connect a led in the place of relay, it work so GPIO work.
I think this is the solution: https://iot-playground.com/images/articles/053/ESP8266_4_relay_switch.png
Again, relay works the same. I have a 8 RELAY system that controls the lights in my work shop off a NodeMCU, and each relay input/trigger is connected to a GPIO. No need for any resistors (or in the case of the link you provided NO transistor) to make the relay work.
I even have a 2 channel relay sitting right here, that I just tested on a spare NodeMCU, and again no resistor or transistor needed.
Probably my relay is different from your. I don't know.
THEY ALL WORK THE SAME! FFS
My relay turn on with pin IN connected to GND or also to 3.3V. GPIO pin from MCU turn from 0V to 3.3V but I don't understand why it cannot turn on relay. I've solved with circuit with transistor. Bye