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:
- Relay is off, NodeMCU#1 is off, NodeMCU#2 is on.
- 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.
- 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.
- NodeMCU#2 sets signal to DOWN, as it received what it needed from NodeMCU#1.
- 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?
According to @user263983 I've redesigned the circuit to meet the answer (I cannot add the scheme in comment to his answer):
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.)