Arduino capacitive touch switch sensor

Hello world! Today i made a code for the Arduino capacitive touch switch / ttp223b capacitive touch sensor. A sensor that i am testing for my webshop, and it does its job! So soon i will add it to my webshop at The code is really easy and can be used with normal buttons to.

Arduino capacitive touch switch
It is very easy, Just wire it the Arduino capacitive touch switch sensor up like the schematic and upload the code.

Parts list:
Arduino uno, I used the RobotDyn Uno.
KY-019 Relay
TTP223B Capacitive touch sensor.
Jumper wire set MM/FF/MF
Lamp socket + power cable & light bulb (optional)


Author: Danny van den Brande. BlueCore Tech.
Hello world! Today i made a code for the TTP233B capacitive touch sensor.
Its very simple and you can toggle on and off a led/relay or whatever you wanna add. 
#define TouchSensor 9 // Pin for capactitive touch sensor
int relay = 2; 

boolean currentState = LOW;
boolean lastState = LOW;
boolean RelayState = LOW;
void setup() {
  pinMode(relay, OUTPUT);  
  pinMode(TouchSensor, INPUT);
void loop() {
  currentState = digitalRead(TouchSensor);
    if (currentState == HIGH && lastState == LOW){
    if (RelayState == HIGH){
      digitalWrite(relay, LOW);
      RelayState = LOW;
    } else {
      digitalWrite(relay, HIGH);
      RelayState = HIGH;
  lastState = currentState;

What is capacitive touching?
In electrical engineering, capacitive sensing (sometimes capacitance sensing) is a technology, based on capacitive coupling, that can detect and measure anything that is conductive or has a dielectric different from air.
Many types of sensors use capacitive sensing, including sensors to detect and measure proximity, position or displacement, humidity, fluid level, and acceleration. Human interface devices based on capacitive sensing, such as trackpads, can replace the computer mouse. Digital audio players, mobile phones, and tablet computers use capacitive sensing touchscreens as input devices. Capacitive sensors can also replace mechanical buttons.

Danny van den Brande

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *