Mechatronics LAB
Published © Apache-2.0

Interface Relay with NodeMCU

today i will discuss you how to interface relay with nodemcu

BeginnerFull instructions provided1 hour67
Interface Relay with NodeMCU

Story

Read more

Code

Code

Arduino
int relayPin = D5; // Define NodeMCU pin connected to relay module

void setup() {
  pinMode(relayPin, OUTPUT);
}

void loop() {
  // Example: Turn on relay when button is pressed
  if (digitalRead(D2) == HIGH) { // Assuming D2 is connected to a push button
    digitalWrite(relayPin, HIGH); // Turn on relay
  } else {
    digitalWrite(relayPin, LOW); // Turn off relay
  }
}

Code

Python
relay_pin = 14  # Define NodeMCU pin connected to relay module

def setup():
    global relay_pin
    pin(relay_pin, OUT)

def loop():
    global relay_pin
    if pin(4).value() == 1:  # Assuming pin 4 is connected to a push button
        pin(relay_pin, 1)  # Turn on relay
    else:
        pin(relay_pin, 0)  # Turn off relay

Credits

Mechatronics LAB
75 projects • 49 followers
I am Sarful , I am a Mechatronics Engineer & also a teacher I am Interested in the evolution of technology in the automation industry .

Comments