TTP223 Touch sensor

Hi All,

I am trying to make the TTP223 capacitive sensor to work continuously while i am pressing the touch sensor, however the led turn off while i am still pressing , any idea how to fix that?

my aim is to turn on the LED when I touch the sensor and keep it on as long as I keep touching it. When I release the touch, the LED will turn off.

this is the code :

const int touchSensorPin = 2;
const int ledPin = 3;

void setup() {
Serial.begin(9600);
pinMode(touchSensorPin, INPUT_PULLUP);

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}

void loop() {
int touchState = digitalRead(touchSensorPin);
if (touchState == LOW) {
Serial.println("Sensor Touched!");
digitalWrite(ledPin, HIGH);

while (digitalRead(touchSensorPin) == LOW) {
  // Do nothing, just wait
}
digitalWrite(ledPin, LOW);

}
}

your advice very helpful
Thank you

Link to what you bought, please. Some TTP223 modules are configurable to do what you want, others are not.

1 Like

here's an example of a configurable one:

1 Like

const int touchSensorPin = 2;
const int ledPin = 3;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, digitalRead(touchSensorPin));
}

2 Likes

const int touchSensorPin = 2;
const int ledPin = 3;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
if(digitalRead(touchSensorPin)) digitalWrite(ledPin, !digitalRead(ledPin));
while(digitalRead(touchSensorPin));
}

I'm starting to add comments to lines like these, as follows:

const int touchSensorPin = 2; //touch sensor signal is HIGH when pressed
const int ledPin = 3;                 //LED is ON when output is HIGH

To help make sense of a lot of postings, and ease the newbie's questions/confusion. Not telling you what to do, just a note in passing.

at least he named it with "Pin" on the end. advanced user.

1 Like

And const, another nod!

Hi, Thank you ,

So, you see the configuration jumpers, right, and understand how to configure it to do what you described?

not fully, do i have to connect jumper B (solder it) in my case? can you confirm please? Thanks

The way I read that graphic, B not welded will give you an output that "follows" the button, while A will either give you a high output if not soldered, or a low output (when pressed) if soldered.
But, the description is a bit "hinky", so you'll just have to try one, I guess.

1 Like

Thank you for your quick reply, and i have tried both, the issue is as in the attached video, i dont think it is related to AB trigger, it is the code how we make it as long as i touch the sensor it stay active (led on). please see the video and let me know your thought about why led goes off after about 10 seconds and i am still touching the sensor.

sorry i couldnt download the video...... anyway, the LED switched off after 10 seconds while my finger still on touch

I am thinking of: The ttp223 module may have a built-in timer that turns off the output after a certain period of continuous touch

Well, if the button does that(change the output, despite still pressing), then you're beat, because you'll never know when you really let go of the button.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.