Touch sensor stops firing after 8 seconds

Hi! I’m using an Arduino with a touch sensor. I need the sensor to continuously fire when touched, but it stops after about 8 seconds and then only triggers again after I release my finger and put it back on.
Could there be a workaround like turning the sensor off and on again repeatedly so that the signal stays somewhat stable?

#include <Keyboard.h>

void setup() {
  Keyboard.begin();
  Serial.begin(9600);
  Serial.setTimeout(5);
  pinMode(10, INPUT);
}

void loop() {
  if(digitalRead(10) == HIGH) {
    Keyboard.press('t');
  } else {
    Keyboard.releaseAll();
  }
}

Help us help you.

Hi!

You should post your code so we can attempt to help.

Is the 8 seconds before fire stops constant? It could be overlap of your timer. If yes, turning the timer you use with a larger prescaler will give you more time before next overlap.

Theorically, you touch sensor seems to works properly (like changing a value from 0 to 1) until its value is changed back to 0 by the software, but let you changing again the value to 1 by pressing it again.
Maybe a bad move would be to set a value to 1 when touch sensor was activated, then set the value at 0 only when the sensor is not activated.

Sorry, sure, here is my very basic code. I tried different things, but in every case the sensor stops firing after about 8 seconds.

#include <Keyboard.h>

void setup() {
  Keyboard.begin();
  Serial.begin(9600);
  Serial.setTimeout(5);
  pinMode(10, INPUT);
}

void loop() {
  if(digitalRead(10) == HIGH) {
    Keyboard.press('t');
  } else {
    Keyboard.releaseAll();
  }
}

even if pin 10 was tied to Vcc it still only works for 8 seconds? How does the OP know its 8 seconds?

I’m sorry, I’m totally new to Arduino. How could I test this? The 8 seconds is just the time I measured when testing myself.

put pin 10 to Vcc.

#include <Keyboard.h>

unsigned long pastpresstime = millis();

void setup() {
  Keyboard.begin();
  Serial.begin(9600);
  Serial.setTimeout(5);
  pinMode(10, INPUT);
  pastpresstime = millis();
}
//tie pin 10 to Vcc

void loop() 
{
  //                                                    with pin 10 tied to Vcc.
  if(digitalRead(10) == HIGH) {
  //  Keyboard.press('t');
  serial.print( " " );
  serial.print( millis()- pastPressTime; )
  } else {
   serial.println(''released");
 //Keyboard.releaseAll();
  }
}

does millis get greater then 8000? Does "released" get printed?

keyboard.h is for a USB interface.

I see you use Keyboard library. The author proposes some warnings about the use.

I dont use this one, so it is only presumption: the 8 sec you observe could be a kind of security into the library that stops listening for input.

An idea would be to reset the key before you read the input pin (I code my leds this way, avoiding some remains on). Your code will be flawlessely sending "type nothing/ type "t" instead of repeating "t" (what your code actually do).

Another idea will be to put timer into your code and use Keyboard.press only at regular interval like 10 or 100ms.

I just found out, that the touch sensor I use actually powers down after 8secs of contact. I’m gonna use another then!

you may aslo try a simple manual switch in place of the touch sensor. The switch is not supposed to have a 8sec lifespan, so you can test your code for long period of time.
Hope it will works with a brand new sensor!

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