I'm trying to use a 16-channel capacitive touch sensor named TTP229-BSF with an Arduino Uno. I use the following code it works correctly when i touch directly but when i place two 4 mm plexiglass pads on top and try to touch over them some times wrong numbers are printed out in the serial terminal. I linked the required jumper as shown in the attached picture. i used 22p capacitors instead of the existing 33p sensitivity capacitors for increasing sensitivity
What is the problem here?
Is there a better and more robust way to do this based on the timing diagram of the datasheet that I attached?
#define SCL_PIN 8
#define SDO_PIN 9
/* Used to store the key state */
byte Key;
void setup()
{
/* Initialise the serial interface */
Serial.begin(9600);
/* Configure the clock and data pins */
pinMode(SCL_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
}
/* Main program */
void loop()
{
/* Read the current state of the keypad */
Key = Read_Keypad();
/* If a key has been pressed output it to the serial port */
if (Key)
{
Serial.println(Key);
}
/* Wait a little before reading again
so not to flood the serial port*/
delay(300);
}
/* Read the state of the keypad */
byte Read_Keypad(void)
{
byte Count;
byte Key_State = 0;
/* Pulse the clock pin 16 times (one for each key of the keypad)
and read the state of the data pin on each pulse */
for(Count = 1; Count <= 16; Count++)
{
digitalWrite(SCL_PIN, LOW);
/* If the data pin is low (active low mode) then store the
current key number */
if (!digitalRead(SDO_PIN))
Key_State = Count;
digitalWrite(SCL_PIN, HIGH);
}
return Key_State;
}