Interface Relay Module With NodeMCU

by CodeChamp in Circuits > Electronics

96737 Views, 69 Favorites, 0 Comments

Interface Relay Module With NodeMCU

Main.jpg

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.

Components Needed

7.png

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)

Description

0.png
10.png
2.png
9.png
11.png
  • 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.

How It Works

12.png

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.

Circuit Connections

8.png
3.png
4.png
5.png

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.

Code Is Right Here

Code.PNG
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.

OUTPUT

Relay_NodeMCU

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!