Nodemcu becomes unavailable when powered from relay, but works with external power, but then connected relay is humming

Hi,

I am having a problem or a series of problems that I am not able figure out how to deal with.

I am using a nodemcu v2 (I believe/assume, it is using ESP-12F (so a higher number than ESP-12E which the v2 apparently use – here are more details: https://www.amazon.co.uk/dp/B07M8Q38LK/ref=pe_3187911_189395841_TE_dp_1).

Now, I wanted to use it to control an H-bridge relay (24V) and wanted to connect it to push buttons as per this drawing:

The drawing is from https://drzzs.com/diy-window-shades-motorized-automated/, Thanks to Dr. Zzs for that, and do let me know if I am not allowed to use the drawing.

That is for the Wemos, but the principle should be the same except that I use other pins (I will get back to that in a second). And I got it working fine on a Wemos D1 mini so thought should be the same with the nodemcu.

I connected the relay to pins D5 and D6, and used the ESPhome like this:
switch:

- platform: gpio
  pin: D5
  interlock: &interlock [open_windowopener, close_windowopener]
  id: open_windowopener
- platform: gpio
  pin: D6
  interlock: *interlock
  id: close_windowopener

And the push buttons I connected to pins D1 and D2 as per the below.

binary_sensor:
- platform: gpio
  pin: 
    number: D1
    inverted: true
  id: button_close
  on_press:
    then:
      - lambda: |
          if (id(my_windowopener).current_operation == COVER_OPERATION_IDLE) {
          id(my_windowopener).close();
          } else {
          id(my_windowopener).stop();
          }

- platform: gpio
  pin: 
    number: D2
    inverted: true
  id: button_open
  on_press:
    then:
      - lambda: |
          if (id(my_windowopener).current_operation == COVER_OPERATION_IDLE) {
          id(my_windowopener).open();
          } else {
          id(my_windowopener).stop();
          }

That worked fine, but only for a few minutes, then it became unavailable. I could get it going again after some minutes. I started looking into if I needed to have some pull-down resistors, and actually reached the conclusion that I should, but then struggled to figure out exactly how they should be connected. Being it a Sunday and it anyhow not possible to get hold of resistors, I thought I in the meantime would try to power the Nodemcy through its USB port. I disconnected all wires to the four pins (and to VIN and Ground) and connected it to USB. It worked like a charm, kept going and going.

Great, but then wanted to reconnect it to the relay. That is sort of fine, but the when pins D5 and D6 are triggered, the motor connected to the relay started making some small humming noise without really moving. Perhaps it is something to do with a missing ground on the nodemcu, although I do not see how that should impact the relay.

So, something is terribly wrong, and I could really use some very specific assistance in how to get this connected.

The first questions are:
a) Why would the nodemcu stay connected when connected to an external powersupply (the H-bridge can output 5V). If it is relevant, it is what I believe is referred to as L298N, can be found here: https://www.amazon.co.uk/dp/B07S1N97V2/ref=pe_3187911_189395841_TE_dp_2).
b) What do I do with ground, do I need to connect the nodemcu to the relays ground?
c) Why is the motor now only humming?
d) Assuming there are solutions to the above, would I need pull-down resistors for the buttons on D1 and D2?
e) If the answer to d is yes, how should it look like, my take it would be like the diagram below? But what is VCC? In my case I as of now have connection from the pin (D5 or D6) on the nodemcu to the input pins on the H-bridge relay. Would the VCC be the relevant input pin on the relay?

ScreenHunter_74 May. 03 21.44

Confusion is total, not even sure my explanation and questions makes sense to others, and I am not able to google my way out of it. I hope somebody can help.

OK, a couple of things here. I’m not super familiar with this hardware, but it looks like the datasheet for your ESP-12F indicates that its Vio is 3.3V, while a datasheet I found for the motor driver says it’s TTL (5V) logic. You’re probably going to want a level converter in there. It seems that the inputs on the ESP-12F have built-in pullups, so you should NOT add pull-downs. The switches will pull the inputs to ground which should give you what you want. Your grounds should be fine to connect together.

Yep, all esp chips have 3v3 logic.

Thanks for the suggestions. Yes, the ESP chip needs 3.3 V, but from all I can read the board takes care of that, and VIN can be higher, perhaps up to 12 V, hence also the USB input which would anyhow be 5V. See for example https://github.com/nodemcu/nodemcu-devkit-v1.0/issues/15 and here http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/powering-the-esp-12e-nodemcu-development-board/

Or perhaps I misunderstood something? If I did not, something else must be at play, other suggestions still welcome.

Thanks for the info on built-in resistors.

Just to be sure I understand it correct: because it has built-in pull-UP resistors I do not need pull-DOWN resistors? I am asking because I thought they were two different things.

Discrete inputs are (typically) used to detect one of two states. The pull-up resistors serve to keep the voltage high at the input pin. The processor reads the voltage and calls that idle or logic ‘0’). That’s now the default, and if you connect nothing to it it will always report that. What you want to do with your buttons is to change the state by changing the voltage at the input pin. By connecting the input pin directly to ground through your switch (which happens when you press the button and the two terminals are connected) you override the pull-up resistor because the input pin’s connection to ground is essentially ‘stronger’ than the connection to the high voltage, which has to go through the resistor. With the voltage at the pin now being essentially 0 vs whatever voltage the pull-up resistor is connected to, the processor is able to determine the pin is now in the ‘active’ state, or logic ‘1’

A pull-down resistor would essentially do same thing but in the opposite direction. You should only ever need one.

Your ESP chip communicates by switching outputs between 0 volts and 3.3 volts to determine logic ‘0’ vs logic ‘1’. The driver board expects its inputs to switch between 0 volts and 5 volts to determine logic ‘0’ vs logic ‘1’. You should use hardware that takes 3.3V signals at the input and generates 5V signals at the output in between them. These are commonly called ‘level shifters.’

1 Like

Aha, just to make sure I understand this correctly, in layman’s terms, this would mean that the L298 would need a 5V (or 0V) signal to work/to understand there has been a change in state?

Strange as L298 works fine with Wemos D1 mini.

But that still does not explain why the nodemcu becomes unavailable after a little while. It would, if I understand it correctly merely mean that the L298 would not react, or?

Aha, the inputs from Peter_K made me measure the actual output voltage from the L298, supposed 5V (to power the Nodemcu): it is 5V for a short while, but then drop to around 2.3V, strange, I think.

I then did some searching on the L298 voltages, and I found this: https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/. It says that "The module has an on-board 78M05 5V regulator from STMicroelectronics. It can be enabled or disabled through a jumper.

When this jumper is in place, the 5V regulator is enabled, supplying logic power supply(Vss) from the motor power supply(Vs). In this case, 5V input terminal acts as an output pin and delivers 5V 0.5A. You can use it to power up the Arduino or other circuitry that requires 5V power supply.

When the jumper is removed, the 5V regulator gets disabled and we have to supply 5 Volts separately through 5 Volt input terminal."

Aha, I have 24V (seems it’s not very common) l and have NOT removed the jumper, so that of course I should do, and then use an external power supply for the nodemcu. I can just use the USB, I figure.

So far so good, perhaps, but then I can not figure out if I need to connect the ground on nodemcu to the ground in the L298 (as I will need a ground to shorten the pins for the pushbuttons), or perhaps it does not matter? Or perhaps it is crucial for the L298 in order for it to register there has been a change in the state of the relevant pin. Any suggestions (I am a bit afraid of frying something if I go by trial and error)?

I’m not super familiar with this hardware, but there is typically a threshold voltage above which a chip would consider an input a logical high, (for example, 3.6V). There is the possibility that this varies slightly in certain designs, so that sometimes a 3.3V (or 3.2) signal would be considered a high, and sometimes it wouldn’t. It might even toggle between considering it high or low.

edit: I found the datasheet for the L298 here and it looks like the driver IC does in fact have a Vih of 2.3V so your 3.3V signalling should be OK.

I’m not 100% certain why the nodemcu becomes unavailable when powered by the 5V output of the L298. When it does can you verify your supply voltage with a multi-meter? Can you verify the voltage at the inputs to the L298? Could it be a software issue? How do you have the power jumper configured on the L298?

It looks like there are configuration jumpers for stepper motor vs standard dc motor. Are those configured correctly for your motors as well?

I dont know about stepper vs standard dc, but it worked fine to begin with, so perhaps I just leave it as is…?

The input for L298 is 24V and that is also what I am getting out when I power it via the USB (with the 5V). I did it without removing the jumper, but that seems clearly to have been my first mistake.

From what it says here: https://www.bananarobotics.com/shop/How-to-use-the-L298N-Dual-H-Bridge-Motor-Driver under Hardware Details, I must, when removing the jumper because more than 12V, supply 5V separately through the +5V pin (next to the gnd pin, which in turn is next to the +12V pin). I can do that. But what should I use for gnd? Perhaps the 24V and 5V is supposed to be the same source, ie they would have the same ground? Meaning I can not have two different power sources, but only one outputting 12 and 5V?

The ESP8266 already has built-in pull-up resistors, you should not have to add any external ones. Just search on how to enable them(if necessary)

I’d start by disconnecting your motors and stick a voltmeter on the motor outputs and measure to see what voltage you’re outputting without a load when the pushbuttons are pressed.

Also see what your supply voltage is doing when the buttons are pressed under load and no-load conditions (i.e. motors connected and disconnected)

Since you are not using any isolated power supplies, the -V (Gnd) for the motor board should be common with the V- (Gnd) of the nodeMCU.

I would have thought that even if the motor board is expecting a TTL level 5V, the nodeMCU 3.3V logic level would still be high enough to get over the threshold.

1 Like

Ai, I am in way over my head here. I get 24V output just fine when I active the pins using hassio via wifi. This was done before removing the jumper when powering the nodemcu through usb, which apparently is not the proper way as eventually the voltage regulator will break, so the jumper is to be taken of, and 5V is to be supplied to the L298 (in addition to 5V external to the nodemcu).

Instead the jumper is to be removed, and an external 5V power supply to be connected to the +5V pin as I described in my post above.

I have not yet dared connecting the pushbuttons to the nodemcu as I’m still not sure about powering the whole thing.

SimonPth, I think you try to explain it to me, but I’m not sure I get it. I have 24V + and gnd, and will need 5 V + and gnd. Now, I only have 3 pins (+12V, gnd, and +5V) pins to connect them to. Which gnd do I omit, and is that even possible? As I asked above: perhaps the 5V has to come from the same source as the 24V so they would have the same ground?

I’ve found some conflicting information online, probably because while the L298 chip is the same in all implementations, the modules do seem to vary a bit by manufacturer.

The onboard voltage regulator essentially takes the voltage from the motor supply (24V) in your case and outputs 5V on that pin if you install the jumper. This 5V is needed to power the chip and is also available to power your nodemcu. Otherwise if the jumper is removed, you need to supply 5V on that pin to power the chip, as well as supply it (somehow) to your nodemcu.

The voltage regulator varies by module manufacturer. Some data sheets say that regulator can handle up to 35V input, but the one you linked to says it can only handle up to 12V input. If you can confirm the allowable voltage input range for the regulator on your board, you can decide which path to take. If it will work (and is probably worth trying), then installing that jumper should put 5V on the pin, power the chip, and allow you to connect the 5v pin to the nodemcu’s power input to power it.

If it can’t handle it, then remove the jumper and you need to connect a 5v supply to that pin and to the nodemcu. The grounds are likely all tied together so any ground pin/terminal can be used to connect the grounds of both of your DC power supplies.

1 Like

Draw on a piece of paper exactly how you have it connected right now.

The NodeMCU and the motor drive board have to share a common ground.

Also, since you now have 24V supply to your motors and don’t have the 5V output enabled, you need to INPUT 5V into the 5V port, since that chip needs 5V logic supply for the control circuitry, and a separate motor supply.

So, without the 5V jumper in place, feed 5V into the motor drive board, and that same 5V feeds the nodeMCU.

Also, feed your 24VDC motor supply into the corresponding port on the motor drive Port.

Common the grounds together and connect them to the NodeMCU ground and motor drive ground.

1 Like

It would appear that we are on the same page :slight_smile:

Thank you so much to both of you. Great that you are on the same page, and I believe I am on it too. Here is what I was thinking for the power connections (no buttons).

What bothers me is the common ground (12V- and 5V-), but that is most likely because I do not understand DC properly?

And here it is with the connections for the buttons. As per Peter_K’s earlier remark it should not be necessary with any (pull-down) resistors as most likely the nodemcu already have pull-up resistors. I guess, anyhow, that it will not break anything if I am wrong, only might it not respond as expected when pushing buttons (or respond even when not pushed). Did I perhaps get that right?

A lesson learned here, for me, is that just because something can be operated from eg 5V to 30V, and works fine with 12V, one can not assume that the operations for 24V is the same (in this case one need an external 5V power supply).