Problems with ttp223

Hello everyone,

recently i purchased some ttp223 boards to make a switch for some LED lights. I control the lights with a mosfet, which workes without any problems itself.

My setup:

Arduino Nano Mosfet IRF3708 on PIN D2 TTP223 on PIN D5 as switch (soldered connection B)

On top of the TTP223 there is a metal button mounted in a piece of wood.

What I expect: I touch the metal, light on. I touch it again. light off.

What happens: I touch the metal, light on. After some 20-30 seconds(irregular) it turns off without touching it. If I touch the metal before it turns of "automatically" it works just fine.

Whenever I leave the sensor floating in the air, the light stays on "forever". So the ttp223 gets some kind of trigger, but i don't know where from.

What I have tried already: Soldered a 22pF and 100yF between VCC and GND: no change. Different ttp223 module, same setup: no change. Different ttp223 module, this time not as switch (left connection B open): It is interesting what happend here!

When the LED (so the mosfet) was on high (on) from the beginning and i touched the sensor, it turned off immediatly until i removed my finger from the sensor. Seemd to work just perfect! But unfortunately i need the light to be off most of the time, so change the code respectively. The results made me wonder about whats going on: Light is off. Touch sensor, light turns on for 5 seconds even though i removed the finger. Light turns off. I could repeat this many times, always with the same result.

I unplugged the mosfet from the arduino and tried again, checking the serial monitor: IT WORKED JUST FINE! I tested the whole setup with the switch i mentioned before (connection B soldered) and the mosfet not connected and it worked just fine.

So my conclusion is, it has something to do with the mosfet being turned "on" but this is basically where my knowledge ends. I hope someone knows whats going on here and can offer a solution? I am happy to post any missing information!

My code looks like this:

define RELAY 2

define TOUCHPIN 5

int touch;

void setup(){ Serial.begin(115200); // must be same baudrate with the Serial Monitor while (!Serial) { delay(10); }

pinMode(RELAY,OUTPUT); pinMode(TOUCHPIN, INPUT); digitalWrite(RELAY, LOW); delay(100);

} // end setup

void loop() { touch = digitalRead(TOUCHPIN); Serial.println(touch);

if (touch == 0){ turn_off(); }

else { turn_on(); }

delay(100); } // end loop

void turn_off(){ digitalWrite(RELAY, LOW); Serial.println("TURNED OFF!"); }

void turn_on(){ digitalWrite(RELAY, HIGH); Serial.println("TURNED ON!"); }

Do post some photos of the setup.

It sounds like the TTP223 recognises the extra metal bit as a touch. Nearby power wires (including those to your LED) can also mess with a capacitive sensor.