Making cap touch buttons for a project

Hi everyone,
Im trying to make cap touch buttons for turning on/off power for my project and turning on/off some vents.
So I want to use two plates or strings which should act as turn on/off buttons. In the attachment you can image of my testing board that I made for UNO just to test out button sensitivity with couple of strings and leds. First I used 1Mohm resistor for each button and it worked fine when I had bare strings but when I put some plastic over it (since the strings wont actually be visible in project but rather covered with plastic) they didnt have enough sensitivity to turn the leds on and off. I tried replacing 1Mohm resistors with 10Mohm to increase sensitivity but when I tested it it seemed to me that sensitivity decreased and behavior of leds was very erradic at some times ( when I held button down it would turn on and off instead on holding state). I have also tried already done touch sensors with ttp223 ic on them but I found them to be extremely unreliable at some times (they would turn on and off by themselves even when there wasnt anything near them,etc.).
Here is my code:

#include <CapacitiveSensor.h>

CapacitiveSensor   senzor1 = CapacitiveSensor(7,2);
CapacitiveSensor   senzor2 = CapacitiveSensor(7,12);
const int ledPin1 = 5;
const int ledPin2 = 10;

static boolean lastSensorHit1 = false;
static boolean LEDvalue1 = LOW;
static boolean lastSensorHit2 = false;
static boolean LEDvalue2 = LOW;

void setup()                 

void loop() {
  bool sensorHit1 = senzor1.capacitiveSensor(30) > 100;
  bool sensorHit2 = senzor2.capacitiveSensor(30) > 100;


  if (sensorHit1 && !lastSensorHit1)  
    LEDvalue1 = !LEDvalue1; 
    digitalWrite(ledPin1, LEDvalue1);
  lastSensorHit1 = sensorHit1;

    if (sensorHit2 && !lastSensorHit2)  
    LEDvalue2 = !LEDvalue2; 
    digitalWrite(ledPin2, LEDvalue2);
  lastSensorHit2 = sensorHit2;

Any ideas on how I can fix the code or electronics in current setup to be more sensitive and reliable or just suggestions about some good cap touch sensors that are reliable would be much appriciated. Thanks.



I would recommend you read a couple of application notes on capacitive touch sensing. Most of the major MCU manufacturer (ST, NXP, Microchip, SiLabs, IFX, TI) have products and documentation. This will cover everything from PCB design and cover materials and their effects on sensitivity.

I've worked with the TTP223 and found them highly reliable, no false triggers whatsoever. Maybe your connections were faulty.

I've worked with the TTP223 and found them highly reliable, no false triggers whatsoever. Maybe your connections were faulty.

How did you use them? What was the distance between the sensor and mcu? Did you add any extra capacitor for sensitivity? Ive noticed there is an empty place on the small pcb of ttp223 where 0-50pF capacitor can be added to change sensitivity.

I've tested them with short wires; in the final project they were soldered directly onto the PCB. No modifications to the module.

This sensor has push/pull outputs (configurable - check the solder jumpers) so should have no problem with long wires, provided the power supply is stable.

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