Interface Relay with NodeMCU

In this tutorial, we will discuss the basics of the relay and how to interface relay with NodeMCU. To setup NodeMCU board with the Arduino software visit here.
RELAY WORKING
The relay is an electrically operated switch. NodeMCU can only provide 3.3 volts at maximum. So to control AC devices from the microcontroller we should use the relay. Circuit diagram of the relay is given below.

          
                         NO - Normally Open
                         NC - Normally Closed
                         COM - Common

When the voltage is not supplied, the armature is not energized and the contacts are normally connected with the NC terminal. When the voltage is supplied the armature is energized and the contacts are connected with NO terminal. Here we are going to control a led with the relay. The relay is turned on when the push button is pressed.

DIAGRAM:

PROGRAM:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int rpin=D5;
int spin=D2;
void setup() {
 
  pinMode(rpin, OUTPUT);
  pinMode(spin,INPUT);
}
 
void loop() {
 
  int val=digitalRead(spin);
  //If switch is pr
  if(val==HIGH)
  {
  digitalWrite(rpin, HIGH);   
  }
  else
  {  
 
  digitalWrite(rpin, LOW);   
  }                  
}

OUTPUT:

Thankyou
SHARE THIS!!!

Gowtham S

Gowtham is a programming enthusiast. His field of interest includes Arduino, NodeMCU, Raspberry Pi, and Python. To know more about him visit https://mybtechprojects.tech/about-us/.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.