Setting delay for capacitive touch sensor to prevent "double press"

capacitive touch sensor circuit
capacitive touch pad
self capacitance vs mutual capacitance
how does capacitive touch work
capacitive touch sensors fujitsu
capacitive touch pcb design
driven shield capacitive sensor
flexible capacitive touch sensor

I am building a number numpad using 3 different capacitive touch sensor. So my function will be to label each the 3 touch sensors with a different number to create a password system.

However i realised that whenever i try to press the button to key in the number, for example the button tagged with number "3", multple values of 3 came out even though i only pressed once. Is there any function on arduino that i can use so that it only generate 1 results with 1 press instead of multiple results in a press.

Is there anyway to change my code such that i can create some sort of debounce for each button so that when i press the button once only 1 result will be shown.

Would appreciate an edit on my code, thanks!

#include <LiquidCrystal.h>
#include <CapacitiveSensor.h>
CapacitiveSensor cs_2_3= CapacitiveSensor(2,3);
CapacitiveSensor cs_2_4= CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5= CapacitiveSensor(2,5);
int pos=0;
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);

char pass[]= "321";
int currentposition=0;
char code=0;

void setup() {
cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);
lcd.setCursor(0,0);
lcd.println("Enter Password: ");
Serial.begin(9600);
lcd.begin(16,2);

}

void loop() {
 long total1= cs_2_3.capacitiveSensor(100);
  long total2=cs_2_4.capacitiveSensor(100);
  long total3= cs_2_5. capacitiveSensor(100);
    if(total1>=1000)
  {
   code= '1';

  }

   if(total2>=1000)
  {
    code= '2';

  }


   if(total3>=1000)
  {
    code='3';

  } 
  delay(100);

if(currentposition==0)
{
lcd.setCursor(0,0);
lcd.println("Enter Password: ");
}
int lu ;
if(code!=0)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PASSWORD:");
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);

for(lu=0;lu<=currentposition;++lu)
{
lcd.print(code);
delay(25);
}

if (code==pass[currentposition])
{
++currentposition;

if(currentposition==3)
{

delay(900);

lcd.setCursor(0,0);
lcd.println(" ");
lcd.setCursor(1,0);
lcd.print("Correct Password");
lcd.setCursor(4,1);
lcd.println("HELLO!!");
lcd.setCursor(15,1);
lcd.println(" ");
lcd.setCursor(16,1);
lcd.println(" ");
lcd.setCursor(14,1);
lcd.println(" ");
lcd.setCursor(13,1);
lcd.println(" ");
delay (5000);



lcd.clear();
lcd.setCursor(0,0);
lcd.println("Enter Password: ");
}

}

else
{
delay(500);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("PASSWORD");
lcd.setCursor(6,0);
lcd.print("INCORRECT");
lcd.setCursor(15,1);
lcd.println(" ");
lcd.setCursor(4,1);
lcd.println("GET AWAY!!!");

code=0;
lcd.setCursor(13,1);
lcd.println(" ");
delay(3000);
currentposition=0;
lcd.clear();
lcd.setCursor(0,0);
lcd.println("Enter Password: ");

}
}
}

Just debounce it like any other button. Only accept signal changes longer then a certain time.

From https://www.arduino.cc/en/tutorial/debounce

/*
  Debounce

  Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
  press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's a
  minimum delay between toggles to debounce the circuit (i.e. to ignore noise).

  The circuit:
  - LED attached from pin 13 to ground
  - pushbutton attached from pin 2 to +5V
  - 10 kilohm resistor attached from pin 2 to ground

  - Note: On most Arduino boards, there is already an LED on the board connected
    to pin 13, so you don't need any extra components for this example.

  created 21 Nov 2006
  by David A. Mellis
  modified 30 Aug 2011
  by Limor Fried
  modified 28 Dec 2012
  by Mike Walters
  modified 30 Aug 2016
  by Arturo Guadalupi

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Debounce
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin

// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // set initial LED state
  digitalWrite(ledPin, ledState);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH), and you've waited long enough
  // since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        ledState = !ledState;
      }
    }
  }

  // set the LED:
  digitalWrite(ledPin, ledState);

  // save the reading. Next time through the loop, it'll be the lastButtonState:
  lastButtonState = reading;
}

[PDF] Touch Sensors Design Guide, overview on designing capacitive touchscreens. 1.2. Self-capacitance and Mutual-capacitance Type Sensors. Atmel� touch controllers allow for two families of� Design tips for using cap sensors. Touche for Arduino: Advanced touch sensing. Tutorial for mimicking Disney's Touché with an Arduino. YouTube: Capacitive sensor, Theory, application and design. Video explanation of cap sensing. MPR121 Hookup Guide. Sparkfun's guide for using a capacitive touch breakout board with an Arduino. Arduino Air

You could use INPUT_PULLUP like this:

void setup() {
  pinMode(pin, INPUT_PULLUP)
}

But since your using i library this may be an issue.

Capacitive Sensing for Dummies : 7 Steps, Capacitive Sensing for Dummies: For someone new to electronics, capacitive sensing This creates a delay in the pulse due to the time it takes to charge and will start working as a capacitor by the proximity of any other conductive surface, They're great for situations where you want to avoid any mechanical stress on a� A linear is a set of contiguous capacitive electrodes. Figure 9. Interlaced linear touch sensor with 3 channels / 4 electrodes (half-ended electrodes design) shows a slider used on a discovery board. Figure 9. Interlaced linear touch sensor with 3 channels / 4 electrodes (half-ended electrodes design) Legend: Via between layers 10% meshed

You could simply use the delay() function, as stated here: https://www.brainy-bits.com/arduino-switch-debounce/

This might be the fastest and simplest way to do it.

Debouncing the button will help - Adafruit got something especially on this topic: https://learn.adafruit.com/make-it-switch/debouncing

But for a quick and dirty solution delay() will do.

[PDF] Multiple Channel Capacitive Touch Sensor and LED Driver Datasheet, Capacitive Touch sensor inputs with programmable sensitivity for use Table 6.81 Off Delay Settings . Added filtering on RESET pin to prevent errant resets. I purchased a 12 key capacitive touch sensor based on I2C some days ago, and tried connecting it to my Arduino One. So I realized that I am not able to make it working right. I looked for lots of info, but I am still lost, and that´s something I don´t like.

A Design of Capacitive Sensing Touch Sensor Using RC Delay with , In this paper, we propose a full digital capacitive sensing touch key reducing the effects due to the variations of resistance and clock frequency. The proposed� Capacitive touch sensors are based on the electrical capacitance of the human body. When, for example, a finger comes close to the sensor, it creates a capacitance to Earth with a value of 30 to 100 pF. This effect can be used for proximity detection and touch-controlled switching.

Differentiating noise from real touch: the key to robust capacitive , The key aspect of a robust capacitive sensing performance is to The robustness of capacitive sensing technology depends on how well this is done to avoid false capacitor front-ends, Mutual capacitance sensing, phase delay and from different kinds of noise by dynamically adjusting compensation to� Tap Location Settings. Tap Modes. Tap "Home" or "Away." Tap "Exit Delay." Set the exit delay for the amount of time you wish. To configure your entry delay: Tap the three-lined menu icon on the upper left-hand side of your screen. Tap Location Settings. Tap Modes. Tap "Home" or "Away." Tap "Entry Delay." Set the entry delay for the amount of time you wish.

[PDF] MPR121, Proximity Capacitive Touch Sensor Controller, The MPR121 is the second generation capacitive touch sensor controller after The amount of charge (Q) applied is programmable by setting the charge current (I), and the charge time (T). MPR121 can be set into Stop Mode by writing Filter Delay Count Limit (FDL): Determines the rate of operation of the filter. A larger� Let’s say we have an RC circuit composed of a 1 MΩ resistor and a capacitive touch sensor with typical fingerless capacitance of 10 pF. We can use a general-purpose input/output pin (configured as an output) to charge the sensor cap up to the logic-high voltage. Next, we need the capacitor to discharge through the large resistor.

Comments
  • Yes. Google "debounce". You can do it in hardware or software.