Digital Capacitive Touch Sensor arduino Code

Last Updated on March 16, 2024

We need Switch to control electronics or electrical appliances or something, Some time electrical switches will give a shock when we use electrical switches with wet hand and then touch to control electrical or electronic load is much interactive than ordinary switches, may be some projects needs touch switch. Here the Digital Capacitive touch sensor arduino interface is made as an experiment.




TTP223B IC based digital capacitive sensors are very affordable and gives good response when we touch it, this sensor breakout can be easily interfaced with any kind of microcontrollers, and contains only three terminals for external interface.

Digital Capacitive Touch Sensor Breakout Board

TTP223-IC

TTP223 is 1 Key Touch pad detector IC, and it is suitable to detect capacitive element variations. It consumes very low power and the operating voltage is only between 2.0V to 5.5V. The response time max about 60mS at fast mode, 220mS at low power mode VDD=3V. Sensitivity can adjust by the capacitance(0 to 50pF) outside. Refer datasheet for more details.

Applications:

  • Water proofed electric products
  • Button key replacement
  • Consumer products

Arduino Digital Capacitive Touch sensor Interface

Connect Vcc pin of Sensor breakout board to Arduino’s +5V pin and Gnd to Gnd. Connect Signal (SIG) pin to Arduino Digital pin D1 and Upload the following code to get response when you touch the Capacitive sensor.

Arduino Code for on board LED and Serial monitor observation.

//Digital Capacitive Touch Sensor Arduino Interfacing 
#define sensorPin 1 // capactitive touch sensor - Arduino Digital pin D1 
int ledPin = 13; // Output display LED (on board LED) - Arduino Digital pin D13 
void setup() 
{ 
<strong>Serial</strong>.begin(9600); 
pinMode(ledPin, OUTPUT); 
pinMode(sensorPin, INPUT); 
} 
void loop() 
{ 
int senseValue = digitalRead(sensorPin); 
if (senseValue == HIGH)
{  
digitalWrite(ledPin, HIGH); 
<strong>Serial</strong>.println("TOUCHED"); 
} 
else
{ 
digitalWrite(ledPin,LOW); 
<strong>Serial</strong>.println("not touched"); 
} 
 delay(500); 
 }


Capacitive Touch Sensor Switch Arduino

This arduino hookup is Controlling the Load (AC Bulb) connected with 5V DC relay and the Signal pin for Relay is taken from Arduino Digital pin D13, other wirings for Capacitive touch sensor is same as for the observation hookup.

Upload the following Arduino Code to control (ON / OFF) the Load device

//Digital Capacitive Touch Sensor Switch Arduino Interfacing 
#define sensorPin 1 // capactitive touch sensor - Arduino Digital pin D1 
int relayPin = 13; // Output RelayPin - Arduino Digital pin D13 
boolean currentState = LOW; 
boolean lastState = LOW; 
boolean RelayState = LOW;
 void setup() 
{ 
<strong>Serial</strong>.begin(9600);
 pinMode(relayPin, OUTPUT); 
 pinMode(sensorPin, INPUT); 
} 
void loop()
 { 
currentState = digitalRead(sensorPin); 
if (currentState == HIGH &amp;amp;&amp;amp; lastState == LOW)
{ 
 delay(1); 
 if (RelayState == HIGH)
{ 
digitalWrite(relayPin, LOW); 
 RelayState = LOW; 
 } 
else { 
digitalWrite(relayPin, HIGH); 
RelayState = HIGH; 
 } 
} 
lastState = currentState; 
}






Leave a Reply

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