Interface Relay Module With NodeMCU




Introduction: Interface Relay Module With NodeMCU

About: " Work until you no longer have to introduce yourself " Show some love on Instagram @makers_bee & Motivate me on YouTube @MakersBee

Hello Makers!

I hope you know what is an Relay Module. Have you wondered how the relay module works?

In this Instructable we will see how an Relay works and how to Interface Relay with NodeMCU.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components Needed

List of parts required for this instructable :

Hardware Required

  • NodeMCU
  • Relay Module
  • Breadboard
  • LED (optional)
  • Micro USB cable
  • Connecting Wires

Software Required

  • Arduino IDE (with ESP8266 Library installed)

Step 2: Description

  • Relay is a electrically operated switch. Generally used relay modules are 5v / 12v.
  • The relay uses an electromagnet to mechanically switch electric appliances.
  • A relay can be operated by a relatively small electric current that can turn ON or OFF a much larger electric current.
  • Using relays is safe as there is no any physical contact between NodeMCU and AC devices.

Step 3: How It Works

Relay is basically act a switch between electrical load and NodeMCU.

Relay have two configuration NO (Normally Open) & NC (Normally Close).

Relay have coil which is energized by 5v, when coil energized switching action takes place, based on NO-NC configuration.

If relay is NO configuration then when coil is energized switching action takes place from NO-NC then load will be connected.

Step 4: Circuit Connections

Connections are very simple, initially you need to power-up the Relay Module.

Relay Connections:

Connect NodeMCU Ground (GND) pin to -ve pin of Relay.

Connect NodeMCU Supply (3v3) pin to +ve pin of Relay.

Connect NodeMCU Digital pin (D4) to Input pin of Relay.

Step 5: Code Is Right Here

int relayInput = 2; // the input to the relay pin
void setup() {

	pinMode(relayInput, OUTPUT); // initialize pin as OUTPUT

void loop() {

	digitalWrite(relayInput, HIGH); // turn relay on


	digitalWrite(relayInput, LOW); // turn relay off



Download the "Relay_NodeMCU.ino" file and open it up in the Arduino IDE.

Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload. You can tinker with it if you like based on the application, or just use it as it is.

Step 6: OUTPUT

That's all makers!

It takes less time to create this instructable, and its fun too.

Thank you for taking your time to read my instructable.

I hope you enjoy it as I enjoy making it and documenting it to show and tell to other fellow makers here.

CIAO!! with another interesting Instructables!

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    10 Discussions


    Question 5 months ago

    Hi guys am a hobbies new to the arudino uno, I connected nodemcu to a 5v 4channel relay, connected to the external 5v dc across vin and gnd pins of the nodemcu and the 5v relay module and configured with BLYNK app, I used D1,D2,D3,D4 (GPIO5,GPIO4,GPIO0,GPIO2), when I turned on the power supply all the 4channels of the relay are turning on and I need to turn off then using the BLUNK app then the module is working fine, I need a best solution so that when I turn on the mocro controller the active state will be lo so that it won’t be any issue in my projuct, thank you


    1 year ago

    there is a way to prevent the relay from switching to NC and then back to NO when the nodemcu is turned on?


    Reply 8 months ago

    Use low level triggered relay.
    Some of the NodeMCU pins momentarily turns 'HIGH' (3.3V) when switched on or restarted which causes the relay to change its states. I've read that D1 (GPIO5) and D2(GPIO4) pins of NodeMCU don't change their states on restart. So you can try using these pins for controlling your relay board if you don't wish to buy a low level triggered relay module.
    Refer this-

    For your information-
    There are two types of relay modules available. One is high level triggered (as used in this tutorial) and another is low level triggered. The main difference lies in its working. High level triggered relay board activates when 'IN' pin is given HIGH voltage (5V or 3.3V) and low level triggered relay activates when 'IN' pin is grounded (0V).

    Smit pambhar
    Smit pambhar

    1 year ago on Step 6

    thank you sir

    this is very helpful for me....


    1 year ago

    I think you should warn, that the nodeMcu has a rather low max current for it's GPIO pins. Many relays draw more than 12mA.


    1 year ago

    Relay is 5V. You Connect 3V of NodeMCU. Is it OK?


    Question 1 year ago on Step 6

    My 5V relay board did not works when 3.3V input signal is given what will be the issue

    But my relay board specification of operating input signal with 3.3V


    Question 2 years ago

    is it ok to drive a 5v Relay with 3v GPIO? i am supposed to use it in a consumer product so i would need some certainity that it would work.


    Answer 2 years ago

    Yes, NodeMCU can drive a 5v Relay. Because it has Vin(5v) pin.