I've connected the MCU to a cheap chinese 24/12v to 5v car phone charger and hooked some wires to a relay.When I try to program doesn't matter if the pin is set to high or low , as soon as I touch the "IN" wire from the relay into any of the selected pins, the relay auto actives.

here is the schematic The charger input is hooked to a 12V drill battery for tests and the output to arduino is an usb port that I soldered wires to it's respective poles.

USB from Chinese charger Positive pole ------- NodeMcu Vin
USB from Chinese charger Negative pole ------- NodeMcu GND
USB from Chinese charger Positive pole ------- Relay   VCC
Relay Ground --------------------------------- NodeMcu Gnd
Relay DataPin -------------------------------- NodeMcu D0 or D1 

And here's the code:

int port = D0;
int portB = D1;

void setup() {



void loop() {


But the result is that the relay will always be on activated ( IN pin = Low ) even connected to D0 that is high... Any ideas ?

  • Sorry, fixed , " it " was referring to the relay data pin Commented Aug 10, 2018 at 1:43
  • you probably have one side of the relay connected to the positive voltage .... connecting the other side of the relay to a pin overloads the pin circuitry and activates the relay
    – jsotola
    Commented Aug 10, 2018 at 2:46
  • the relay might want more than 3.3v to indicate high, try feeding it 5v to the relay data pin and see if it activates. if so, it's designed for 5v arduino devices, not 3.3v. FWIW, i've bought several kinds and this is common amoung single-relay modules, bit for whatever reason, all the few kinds of 2-relay modules i've bought work fine with my nodeMCUs.
    – dandavis
    Commented Aug 10, 2018 at 4:13
  • note that you can also use a logic level mosfet's S-D pins to connect the relay data line to ground, and use a 100k resisistor from 5v to relay data in to pull it up; when you set the pin high, it turns on the gate and pulls the 5v signal down ground. i like the irlz44n for most 3.3v applications.
    – dandavis
    Commented Aug 10, 2018 at 4:15
  • some relays hold the coil at LOW signal and release at HIGH
    – Juraj
    Commented Aug 10, 2018 at 4:26

1 Answer 1


Does your nodemcu directly feed the relay? If so, 3.3v (nodemcu output high level) is not enough to activate it. I would use a transistor like a s8050 to Power it (do not forget the freewheel diode on the relay coil)

  • You are right, I've completely forgot that the Mcu's digital is 3.3v instead of 5v and it wasn't able to properly control the relay, thank you very much. Commented Aug 10, 2018 at 15:53
  • @LucasMedeiros, it was in comments by dandavis
    – Juraj
    Commented Aug 10, 2018 at 16:24
  • you can try to feed the esp 3.6v or 3.7v instead of 3.3v; should work fine (within/cose to ESP spec) and might be enough to trigger the relay on HIGH, since VCC (and thus D1@HIGH) will be raised.
    – dandavis
    Commented Aug 10, 2018 at 20:30

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.