Interface Relay Module With NodeMCU




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

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.

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!



    • Tape Contest

      Tape Contest
    • Trash to Treasure

      Trash to Treasure
    • Arduino Contest 2019

      Arduino Contest 2019

    7 Discussions


    6 days ago

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

    Smit pambhar

    2 months ago on Step 6

    thank you sir

    this is very helpful for me....


    4 months 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.


    7 months ago

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


    Question 7 months 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 11 months 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.

    1 answer

    Answer 11 months ago

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