Interface Relay Module With NodeMCU

14,777

52

4

About: Work until you no longer have to introduce yourself.

Intro: Interface Relay Module With NodeMCU

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

	delay(1000);

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

	delay(1000);

}

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!

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    4 Discussions

    0
    None
    CosmosL

    7 weeks ago

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

    0
    None
    baranichandarb

    Question 2 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

    0
    None
    AnthonyS332

    Question 6 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 more answer
    0
    None
    TheCircuitAnthonyS332

    Answer 6 months ago

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