0
\$\begingroup\$

I have a power supply (let's say 5V battery) and a NodeMCU (micro-controller) attached to it.

I want to turn on the power supply for this NodeMCU #1 by signal from another micro-controller (from separate circuit, where there is another power supply and another NodeMCU #2). Later, NodeMCU #1 itself may also "force" to stay in powered on state (ask not to be shut down.)

Typical use case:

  1. Relay is off, NodeMCU#1 is off, NodeMCU#2 is on.
  2. NodeMCU#2 wants NodeMCU#1 to turn on and do some task so it sends UP signal. Now the relay is on, so NodeMCU#1 powers-up.
  3. NodeMCU#1 sets own signal to UP so even when NodeMCU#2 sets signal to DOWN, NodeMCU#1 can still perform what it needs before shut down.
  4. NodeMCU#2 sets signal to DOWN, as it received what it needed from NodeMCU#1.
  5. Once NodeMCU#1 is finished, it sets signal to DOWN, relay changes off, NodeMCU#1 is powered off.

In other words NodeMCU#2 stays ON all the time, NodeMCU#1 turns on by NodeMCU#2 and off after it's done.

I realised that by using an OR gate - either external controller is forcing the relay to stay OPEN or NodeMCU itself signals it to stay OPEN.

The problem is where do I connect the GND from the relay? In fact, in my OR gate I "mix" two VIN - one from the NodeMCU signal port, another from the external controller (with its own power supply). Isn't it a problem, even if both signals are +3V? Is it important if I connect the GND from relay to NodeMCU GND or external controller GND?

enter image description here

Update:

According to @user263983 I've redesigned the circuit to meet the answer (I cannot add the scheme in comment to his answer):

enter image description here

I am not sure if OR gate and relay should work on VCC (+5V) directly. Do I need some resistor there, or will the relay itself provide some resistance?

As mentioned by @Peter Bennett I would have to find an OR gate that supports 5V input/output with enough current to operate the relay, and maybe add a flyback diode (@Ron Beyer.)

\$\endgroup\$
6
  • 1
    \$\begingroup\$ I'm not quite sure what is your problem but I need to know that you MUST have one single GND for both uControllers if you want your logic to work properly. From the presented schematic I see that your OR gate must Source current to feed your relay since the other relay coil wire is connected to ground. Since your OR gate is part of the circuit that is no problem. But if you want a signal from another uController to feed the OR gate you MUST utilize the same GND. Please let me know if that explanation is understandable. \$\endgroup\$ Commented Feb 21, 2022 at 0:06
  • \$\begingroup\$ Also, OPEN means the current is not going through the relay switch, which means your NodeMCU is not powered, which means that it cannot feed your OR gate to stay open. This is a bad design for the NodeMCU could not be in control at all time. The circuit logic should be implemented such that the OR gate remain powered when NodeMCU call for a shot OFF, so that the other uController could still turn the NodeMCU ON. \$\endgroup\$ Commented Feb 21, 2022 at 0:10
  • 1
    \$\begingroup\$ The 74AHC32 output current is only 8 mA - you can't drive a relay directly with it. \$\endgroup\$ Commented Feb 21, 2022 at 0:58
  • 1
    \$\begingroup\$ I'm curious why you need the OR gate? Can't you run "CONTROLLER_SIGNAL" into the MCU and use an IF statement with a logical OR there to drive (a BJT) and the relay? You also need a flyback diode on your relay coil. \$\endgroup\$
    – Ron Beyer
    Commented Feb 21, 2022 at 1:26
  • \$\begingroup\$ @FredCailloux "OPEN means the current is not going through the relay switch, which means your NodeMCU is not powered, which means that it cannot feed your OR gate to stay open" - Exactly what I wanted. Use case: external controller powers up NodeMCU, NodeMCU does some magic, external controller disable signal at some point, but NodeMCU can still need some time to perform clean shutdown. So external controller controls power-up and NodeMCU power-down mainly. \$\endgroup\$
    – PolGraphic
    Commented Feb 21, 2022 at 11:22

2 Answers 2

3
\$\begingroup\$

If you have two power sources and they are not isolated from each over, the ground is common. If they are isolated, output from NodeMCU to logical element should be isolated, optocoupler can be used.

\$\endgroup\$
3
  • \$\begingroup\$ Thank you! I am going for two isolated circuits with optocoupler. I've extended my question with new scheme that uses what you wrote - is it what you meant in the answer? \$\endgroup\$
    – PolGraphic
    Commented Feb 21, 2022 at 11:30
  • 1
    \$\begingroup\$ @polgraphic Only one optocoupler is needed, depends of the power for logical element. If it powered from same source as NodeMCU, optocoupler for signal from that IC not needed. And feed power to logical element before relay contacts. If feed of logical element from external MCU, optocoupler for signal from it not needed. And relay should have same feed and ground as logical element. And add transistor to control relay, output of logical element is not strong enough. \$\endgroup\$
    – user263983
    Commented Feb 21, 2022 at 12:22
  • 1
    \$\begingroup\$ @polgraphic Resistor in series with optocoupler LED is must. \$\endgroup\$
    – user263983
    Commented Feb 21, 2022 at 12:29
1
\$\begingroup\$

Here is my proposed solution NodeMCU isolated remote control

No need for an OR gate. The transistor will drive the contact relay. The MCU will maintain its own power until the IO goes low if the opto coupler is not energized. When the opto coupler is energized the whole circuit will turn ON. No need for common ground.

Disregard the uController pinout and naming. It is just a generic schematic. Any MCU like NodeMCU will do the job.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks! Is it a diode near the relay? Is it maybe for back-ward current when relay switches? \$\endgroup\$
    – PolGraphic
    Commented Feb 24, 2022 at 9:49
  • \$\begingroup\$ Also, is it safe to just join NodeMCU output signal PIN with 5V (on 2.7k resistor)? Won't it cause current going to NodeMCU PIN (like it would be input) when this PIN output is low? \$\endgroup\$
    – PolGraphic
    Commented Feb 24, 2022 at 13:30
  • \$\begingroup\$ Shouldn'y the diode and relay part be connected to V+5V (it looks to me like there's loop between relay 1- diode - relay 2 now? Or am I missing something? \$\endgroup\$
    – PolGraphic
    Commented Feb 24, 2022 at 14:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.