Introduction to TTP223 Capacitive touch module for Arduino Example 1/2

Project Video
Project Details

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

See Using two TTP223 Touch Module with Arduino Example 2/2

Project Code


/*
 * 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();
}
Required File(s)

If you found this Arduino course helpful, please support me so I can continue creating content like this. support me via PayPal