Simulate touch (capacitive) button from nodemcu

Hey guys

I’m trying to build this on a nodemcuV2 but don’t know where to start and how I can do it with esphome.

I don’t know why he’s using pin 13 specifically and which pin I should use on the nodemcuv2.

This will be for my clothes washing machine which has capacitive touch buttons

Any help would be great

NodeMCU is the firmware. What hardware are you using?

It doesn’t really matter if it is an ESP8266 or ESP32 based board. The program will be the same (more on that in a minute) however it does effect your best choice of pin to use.

For an ESP2866 board you can use any of these recommended output pins (scroll down to the table “Best Pins to Use – ESP8266” In short, D1 to D7 are all good choices for outputs.

For an ESP32 based board there is a similar table here: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/ any of GPIO16 to GPIO33 are good choices.

Now, rather than swapping the pin mode from input to output as was done in video what you can do in ESPHome is use the open drain pin mode. For example if you use pin D5 (ESP2866 board):

switch:
  - platform: gpio
    pin:
      number: D5
      mode: OUTPUT_OPEN_DRAIN
    name: "Washing Machine"

When you switch the pin on it will short the output to ground. When you switch the pin off it will be an open circuit / very high resistance (no voltage). This is what you want to use to activate a capacitive sense (touch) switch and was what the video was accomplishing by toggling from input (= high resistance) to output with the pin grounded.

1 Like

Thanks Tom for the prompt reply and great explanation

I can’t wait to test it tomorrow.

In the meantime how can I make it behave like a momentary switch or a relay so toggles on and off on one command?
Or is OUTPUT_OPEN_DRAIN is that function?

Also would like to know if we need to specify output voltage “HIGH/LOW”?

As I tried to explain open drain has no output voltage. Only ground (0V) when on or no connection when off.

For momentary action see the explanation lower down on this page: https://esphome.io/components/switch/gpio.html

Hey Tom.

I have flashed a nodemcu with the code below and connected a pin to D5 but it isn’t working

esphome:
  name: washing_machine
  platform: ESP8266
  board: nodemcuv2

WIFI....

# Enable logging
logger:
  level: debug


# Enable Home Assistant API
api:

ota:

switch:
  - platform: gpio
    pin:
      number: D5
      mode: OUTPUT_OPEN_DRAIN
    name: "Washing Machine"

I have wrapped the other end with aluminium foil and made it as wide and flat as the finger and placed it on the button. I even tried on the phone but no luck

I don’t know what type of sensor is on the washing machine, all I know is that it’s a touch sensor.

I have noticed that when I tap the foil with the jumper wire without triggering open drain it triggered the washing machine (I use non conductive pliers when doing so). But when the jumper wire is already in place and I trigger the open drain on and off it doesn’t do anything. It’s as if the jumper wire is always “active”

I don’t have a voltage meter with capacitance function so there’s no real way to know what’s happening.
To clarify, here’s a photo of my meter

Thanks for the help Tom

I assume you just cut the WIFI section of your code for security and that you see the switch in home assistant.

Put your meter in resistance measuring mode. Measure from the ESP ground pin to D5.

When the switch is on the resistance should be very small. When off the resistance should be large or open circuit. There’s a virtual reverse biased diode in the drain - source of the switch that may mess up this measurement so try it with the leads both ways round (red on D5, black on GND, then swap if not getting the result you expect). One of the ways (or maybe both) should give you this result.

The other way is to hook up a simple test circuit with an LED:

+3V DC -----[ 100 Ohms]—>|----- D5

This is the LED: Anode (+) ------>|------ (-) Cathode

The 100 Ohms isnt important, something around that value will do as long as you are using a red, orange or green LED. The forward voltage of a blue LED may be too much for it to light.

The LED should be on when the switch is on.

Assuming all this works you may have too much stray capacitance in the circuit. Try shortening the the connection between D5 and the foil.

Maybe try putting the circuit in place and power cycling the washing machine. It might have a calibration for the touch sensor on start up.

One last test. With the circuit in place and the switch on, touch the ground pin of the ESP module to the cold water tap.

Hopefully it isn’t a resistive touch sensor… The foil will always short it.

1 Like

That’s one great explanation! Testing it soon

In the mean time, if the sensor hasn’t been blown yet (even though I’ve used foil on it in the past test) we can pretty much rule out it being a resistive sensor? You got me a little worries :grin:

By the way, yes the Wifi section was deleted due to security, I can see the switch in HA

I should have said ‘activated’ rather than ‘shorted’. Apologies for causing worry. It will be fine.

1 Like

Ok @tom_l
I have tested by setting the multimeter on (Ω) and attached one lead to D5 and one to ground and it’s constantly showing me 33.1Ohms whether the switch is on or off.

Tried multiple grounds and swaped the test leads but nothing changed… This confirms my experiences testing on the washing machine, as if the lead is always active

unfortunately I don’t have an LED to test but hopefully this continuity test worked?

Edit:

I found the problem!
My jumper cable was rubbish, I tried testing straight to the pins of the nodemcu and the reading now shows 0.34Ohms when the switch is on and 33.1Ohms when off…

That’s great but this is way too low:

Are you sure it is Ohms and not M or K Ohms?

Yes sorry, I noticed after I wrote that post, it’s 0.34M and it’s just 33.1, no K or M

Its getting frustrating but I just tested on washing machine using a coin, I know the coin is getting the Ohms correctly (because I have the multimeter connected on the other side of the coin) but the machine isn’t turning on.

Funny thing is, if I remove the jumper lead and just tap the coin it triggers the sensor no matter if the open drain is on or off. Maybe the change in the resistance isn’t quick enough to trigger the sensor? I say this also because I notice when turning the switch on/off, the mutimeter jumps around for a second or 2 till it settles on 0.34M/33.1Ohms

I’m starting to think I might need a servo with a jumper lead attached to act like a stylus (active or capacitive?) to make this work…

Any ideas @tom_l?
Does the plan above sound like the next step to try?

Not sure. You may have to experiment a bit.

1 Like

Ok so my capacitive stylus arrived but have absolutely no effect on the sensor even though they work great on my phone… lol

Oh good experiment! That explains why your circuit wasn’t working. I wonder what sort of sensor it is then?

What’s the washing machine make/model?

@tom_l
It’s the Fisher&Paykel wh8560p1
https://www.fisherpaykel.com/in/laundry/washing-machines/front-loaders/WH8560P1%20FP%20IN/

Here’s the user manual:

Just tested a wire from the cold water tap to the touch button and it activates… :angry:

Connect the cold tap wire to GND on your ESP board. Try the circuit output again.

I found the service manual for your washer. No use in this case but you may want it for future reference:

https://www.manualslib.com/manual/1264071/Fisher-And-Paykel-Wh8560j1.html?page=27#manual

Ahh this is so frustrating!

Connected tap to GND on pin to sensor (with coin and foil) didn’t work even though the multimeter is showing changes in Ohms
The stylus didn’t work earlier by direct contact to the sensor but just tried with a coin it’s working fine!

Luckily I ordered the servo over 10 days ago so shouldn’t be too much longer (damn china shipping)