[SOLVED] Nodemcu+5V relay to switch on/off usb light problem

I am using a Nodemcu board and connect to a 5V single relay which is going to switch on/off for the USB lamp.The relay SIG is connect to D1. I have added a button on the Blynk app. Actually the relay does work when I push the button on the app. you can see the red light on the relay board and heard the click sound and the USB lamp light is on. It switch off when I press again. however when I press it again , the relay red light on the board is on and heard the click sound, but the USB lamp won’t turn on. after I switch it off. Then click the button, everything works again. The relay only works on every second times.

not sure why is happened ? and how to fix it ? I have tried to use another relay it act the same. I also try to change the VCC input to 3.3v , and still act the same.

1,button on/off---- working (lamp on/off)
2.button on/off---- not working (no action on usb lamp, but can hear relay click sound and red light on/off)
3.button on/off---- working (lamp on/off)
4.button on/off---- not working (no action on usb lamp, but can hear relay click sound and red light on/off)
5.button on/off---- working (lamp on/off)
6.button on/off---- not working (no action on usb lamp, but can hear relay click sound and red light on/off)

the relay is relay v1.0 HILS8L-DC5V-S-C a very simple relay

I have read some document they have add a NPN for the relay. not sure is that the way to solve ?

It could have something to do with the NodeMCU signal from the D1. I’m not sure if it’s 3.3v or 5v. It could be 3.3v and thus your relay will act weird. Considering it’s based on the ESP I’m guessing it’s 3.3v on the signal and in that case you indeed need a transistor to switch or a logic level voltage convertor to boost the signal to 5v.

If your relay is like this one (link below), and at Ver.1.0, then you are not getting enough voltage and current to the coil… and risk damaging your NodeMCU. Boost the coil voltage (NOT the signal as that is clearly working) from a separate 5vdc power source to the Vcc of the relay and remember to share the ground between it (the 2nd power supply) and the NodeMCU.

@Gunner Yes, it is the relay on that link and Ver.1.0. Thank you for your advise. I will try to use the 2nd power supply in case it damage my NodeMCU. As I am a newbie to electronic, just want to check with you. if I don’t have an extra breadboard to do the common ground. Will this method works the same ? Please let me know if I am getting the wrong idea.

The positive(+) of the 2nd power supply to the relay’s VCC , the negative(-) of the 2nd power supply to the ground of the NodeMCU board. and by using another ground pin from NodeMCU to the relay’s GND. So actually it will use two ground pin of the NodeMCU to make as common ground.

Yes, that will be fine for the grounding.

I finally get it working, I was trying with external power supply and using NPN transistor to fix the issue that I mentioned above. however still no luck, even i change another “xiaomi usb led light” Xiaomi USB Light. It raise my curiosity, so I used another USB led light (simple led with resister )which is created by my friend. then it works like a charm.

Not sure whether Xiaomi USB light has some sort of protection or what ,however if I plug it on the power bank by using the switch on the power bank to switch it on/off . it works okay, no such issue… Will it due to the GPIO signal time is not long enough to switch the Xiaomi USB Light on/off ? Perhaps debounce (not sure about this term as I am a newbie to electronic world),however it occurs in very regular order, so might not be the reason for that.

Anyway thank you for helping me on this project. the relay project works well now.