today i will discuss you how to interface relay with nodemcu , fitst you have to need know

HOW TO WORK RELAY


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.

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.

CKT
Program 

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);
   }
}

No comments

Theme images by Dizzo. Powered by Blogger.