Other Arduino Codes and Videos by Robojax

Introduction to TTP223 Capacitive touch module for Arduino

The source code for TTP223 Touch Module for Arduino

by touching the module, the pin 8 is sending signal to turn the Relay or switch ON


 /*
 * This is the Arduino code for  TTP223 Touch module switch
 * by touching the module, the pin 8 is sending signal to turn the Relay or switch ON  
 *  * 
 * Written by Ahmad S. for Robojax.com 
 * Date: April 01, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 
 */

int touchPin = 2;// connect output from TTP223 to this
int val = 0; 
int relayPin = 8;// Connected to relay

void setup() {
 Serial.begin(9600);
 pinMode(touchPin, INPUT); 
  pinMode(relayPin, OUTPUT);

}

void loop() {
  digitalWrite(relayPin, HIGH);
  val = digitalRead(touchPin); 
  if(val ==1){
  Serial.println("Touched");
  digitalWrite(relayPin, LOW);
  }
  delay(100);
  Serial.println();
}
   

The source code for TTP223 Touch Module for Arduino for 2 Touch module

by touching the module, the pin 8 is sending signal to turn the 2 Relay or 2 switch ON


 /*
 * This is the Arduino code for  TTP223 Touch module switch
 * by touching the module, the pin 8 is sending signal to turn the Relay or switch ON  
 *  * 
 * Written by Ahmad S. for Robojax.com 
 * Date: April 01, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 
 */

 // 1st channel
int touchPin1 = 2;// connect output from TTP223 to this
int val = 0; 
int relayPin = 8;// Connected to relay

 // 2nd channel
int touchPin2 = 3;// connect output from TTP223 to this
int val2 = 0; 
int relayPin2 = 9;// Connected to relay

void setup() {
 Serial.begin(9600);
 pinMode(touchPin, INPUT); // input put from touch
 pinMode(relayPin, OUTPUT);// output to relay
 
  pinMode(touchPin2, INPUT); // input put from touch (2)
 pinMode(relayPin2, OUTPUT);// output to relay (2)

}

void loop() {
 // start of channel 1 code 
  digitalWrite(relayPin, HIGH);// set the relay to HIGH (if your relay is lowe-trigger. If not remove this line)
  val = digitalRead(touchPin); // read channel 1 touch module value
  if(val ==1){
  Serial.println("Channel 1 Touched");
  digitalWrite(relayPin, LOW);// turn relay (of switch) 1 ON
  }
  delay(100);
  Serial.println();
   // end of channel 1 code 
  
 // start of channel 2 code   
  digitalWrite(relayPin2, HIGH);// set the relay to HIGH (if your relay is lowe-trigger. If not remove this line)
  val2 = digitalRead(touchPin2); // read channel 2 touch module value
  if(val2 ==1){
  Serial.println("Channel 2 Touched");
  digitalWrite(relayPin2, LOW);// turn relay (of switch) 2 ON
  }
  delay(100);
  Serial.println();
  // end of channel 2 code 
}
   

If you found this tutorial helpful, please support me so I can continue creating contents like this.