NodeMCU v3 two push buttons not working for me

Pretty simple.

Trying to use two push buttons on a NodeMCU v3 (no resistance), three relays to move a cover… any way D4 working great but D3 (or any other) is not!

captive_portal:

switch:
  # Relay que energiza el transformador de 24 V.
  - platform: gpio
    pin: D1
    id: relay_1
    # If ESP reboots, do not attempt to restore switch state
    restore_mode: always off

  # On Sube      Off Baja
  - platform: gpio
    pin: D2
    id: relay_2
    # Use interlocking to keep at most one of the two directions on
    interlock: &interlock_group [relay_2, relay_3]    
    restore_mode: always off

  # On Baja     Off Sube
  - platform: gpio
    pin: D5
    id: relay_3
    interlock: *interlock_group
    # If ESP reboots, do not attempt to restore switch state
    restore_mode: always off

binary_sensor:

  - platform: gpio
    id: cerrar
    pin: 
      number: D3
      inverted: true
    on_press:
      - cover.close: my_cover
    on_release:
    - cover.stop: my_cover

  - platform: gpio
    id: abrir
    pin: 
      number: D4
      inverted: true
    on_press:
      - cover.open: my_cover
    on_release:
        - cover.stop: my_cover

what I’m doing wrong??

You didn’t define any pullup… how do you have buttons connected? Do you have pull-up (or pull-down) resistors?

This is my first project… the connection is:

D3 - push button - ground ( not working)

D4 - push button - ground ( working)

No resistor.

Ok, now you have either program pull-up input

binary_sensor:
  - platform: gpio
    pin:
      number: D3
      mode:
        input: true
        pullup: true
    name: ...

or add physical resistors:

  • from D3 to +3.3v
  • from D4 to +3.3V

value is…say, 10kohm (value really isn’t accurate, can be 4.k7, 15k, 20k… anything really.)

What you have now is inconsistent states. When you push your button then D3 or D4 is on GND, true. But what happens when you release button? What state is input on? noone knows… inputs must never be left floated.

For what I have read nodemcu have internal resistor. Do not know how to use it.

Exactly like i wrote above… (add pullup: true) …

You are right sorry my lack of attention!

No worries…
But, be aware that loooong cables from ESP module to button location can lead to “funny” and erratic button working with internal resistor only… that’s because internal resistor is quite high, so long wires can easily pickup disturbances…
So, for long wires from ESP to button it’s reccomended to add external pullup.

1 Like