I am going to connect NodeMCU to a latching relay board like tis one (4 channel version): LINK

Both MCU board and relay board will be powered from the same 5V voltage regulator.

Now I have two problems to solve:

Problem 1 - logic levels

NodeMCU logic level is 3.3V and relays board works in 5V levels. I can either use logic level converters or simple transoptors. Because I am going to attach NodeMCU to a custom PCB, I think transoptors will be simpler to solder.

Problem 2 - relay triggers with low pulse on the control pin

This relay boards works like this: every time the channel pin (T1 - T4) is connected to ground for few miliseconds - the relay flips to other state. Here is the question: when the MCU board resets/reboots on power cycle, how do I ensure that the control pins are HIGH from the beginning? If they are not, the relay can flip randomly before my program starts and I will not know the initial state of relay.

What would be the best approch here ?

  • How do you ensure that the relay module is in a certain state at power-up? The linked resource says nothing concerning this. Commented Sep 29, 2021 at 9:37
  • It seems that my particular relay board is always in the same (NO) state after connecting 5V power. So there is no ambiguity at start, unless some random low-pulse is not send to control pins
    – michal
    Commented Sep 29, 2021 at 9:52
  • 1
    Seems High Impedance won't trigger. So first set pin to HIGH, then pinMode OUTPUT. Commented Sep 29, 2021 at 10:14

1 Answer 1


Since ports commonly are configured as inputs at reset, you will need to add a pull-up resistor.

Then write your setup so that the pin is high before switching to output mode.


Some microcontrollers have internal pull-ups, that are even activated at reset, see the specific data sheet. (Thanks, Juraj. I don't know NodeMCU enough to go in details. Anyway, my answer might apply to other controllers and other loads, too.)

The value of the pull-up can be determined by the maximum input current for the relay module (or your adapting circuitry) and the respective voltages. To be sure, make it a bit smaller, for example to the next E-series value. Just an example: minimum supply voltage is 3.15V (3V minus 5%), the maximum input voltage to detect "high" is 2.4V and maximum input current is 10 µA. Then the resistor will need to be at most Rmax = (Vdd_min - Vin_max) / Iin_max = (3.15V - 2.4V) / 10 µA = 75kOhm. This value is part of the E24 series, but is can be 68kOhm that is in the E6 series.

However, it seems as if the circuit of the modules contains a simple PNP BJT, a pull-up will not work here, because the input needs to be pulled up to the supply voltage of the module. You need a level converter, this could be a simple transistor. How to design that circuit, is another issue. There are lots of information in the web how to do this.

  • Thanks! This seems as a solving answer! Any hints what resistor values I should choose? What do I need to know before choosing resistors ?
    – michal
    Commented Sep 29, 2021 at 9:55
  • 1
    esp8266 has internal pullup activated on io pins at boot
    – Juraj
    Commented Sep 29, 2021 at 10:30
  • 1
    use pins 4 and 5, they are quieter during power-up than other GPIOs.
    – dandavis
    Commented Sep 30, 2021 at 4:36

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.