0

I'm using NodeMCU with 5v relay module. my problem is that when the output of NodeMCU is high the relay is off. Which means that the relay module work in an inverted way so how can I treat this issue while when the output is high the relay become on?

Michel Keijzers
13k7 gold badges41 silver badges58 bronze badges
asked Jul 17, 2018 at 8:23
3
  • Why do you care if HIGH is on and LOW is off, or HIGH is off and LOW is on? Commented Jul 17, 2018 at 11:06
  • @Majenko: consider the reset/booting behavior of all pins but 4+5 and it can matter a lot! Commented Jul 17, 2018 at 21:32
  • Good point. So it all depends: what relay module is it? Commented Jul 17, 2018 at 22:20

2 Answers 2

2

try changing the connection in relay moduleenter image description here

enter image description here

u can see that there are three pins in a relay. when you connect the output from the NodeMCU between the common and the NC(normally closed) pin of relay, makes the switch close and current flows (when the relay is not powered.) try connecting the output in between common and NO(normally opened). when you connect your output between common and NO the current will only flow when the relay is powered up.

answered Jul 17, 2018 at 9:55
0

Software solution:

The easiest way is to drive the pin inverted by the NodeMCU, so set it LOW when you want the relay to be activated, otherwise set it HIGH.

Example:

void setup()
{
 pinMode(13, OUTPUT); // sets the digital pin 13 as output
 digitalWrite(13, HIGH); // switches OFF the relay
}
void loop()
{
 digitalWrite(13, LOW); // switches ON the relay
 delay(1000); // waits for a second
 digitalWrite(13, HIGH); // switches OFF the relay
 delay(1000); // waits for a second
}

Hardware solution:

A hardware solution is to use an inverter IC, but since you use a microcontroller it would be only cost space, time and money.

answered Jul 17, 2018 at 8:29
2
  • Sorry but I'm new to this region, I didn't understand the first solution. Do you mean that there is a pin named inverted I can connect it ground and it will solve the problem or what? Commented Jul 17, 2018 at 9:07
  • There is no pin name inverted, but instead of sending a 1 / HIGH signal (digitalWrite(pin, HIGH), when you want to activate the relay, you send a 0 / LOW signal (digitalWrite(pin, LOW)... And in the setup you set it to HIGH (to switch it off initially). Commented Jul 17, 2018 at 9:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.