SurtrTech
Published © GPL3+

Interfacing4-Channels Capacitive Touch Module with Arduino

TTP224 module with a RGB LED control example

BeginnerProtip1 hour2,739
Interfacing4-Channels Capacitive Touch Module with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DigitSpace TTP224 4 channel capacitive touch module
×1
RGB LED Common Cathod
×1

Story

Read more

Schematics

Wiring 1

Wiring 2

Code

Code_1

Arduino
Works with the serial monitor
/* This code works with 4 channel Capacitive touch buttons module or 4 buttons/switches
 * It displays the current state of the buttons on the serial monitor
 * Refer to www.SurtrTech.com for more details
 */

#define Button1 2 //Buttons pins
#define Button2 3
#define Button3 4
#define Button4 5

bool Button1_State, Button2_State, Button3_State, Button4_State; //Buttons states

String Data; //To regroup stats to be displayed on the serial monitor

void setup() {
  
  Serial.begin(9600);     //Set the serial communications
  pinMode(Button1,INPUT); //Set the pin modes
  pinMode(Button2,INPUT);
  pinMode(Button3,INPUT);
  pinMode(Button4,INPUT);
  
}

void loop() {
  
  Button1_State = digitalRead(Button1); //Reading different current states and store them
  Button2_State = digitalRead(Button2);
  Button3_State = digitalRead(Button3);
  Button4_State = digitalRead(Button4);

  Data = String(Button1_State) + "\t" + String(Button2_State) + "\t" + String(Button3_State) + "\t" + String(Button4_State); //Regroup and convert to string

  Serial.println(Data); //Display on the serial monitor
  
}

Code_2

Arduino
Works with the RGB
/* This code works with 4 channel Capacitive touch buttons module or 4 buttons/switches and a RGB LED
 * It controls the colors values of a RGB LED and displays the current values on the serial monitor
 * Refer to www.SurtrTech.com for more details
 */

#define Button1 2 //Buttons pins
#define Button2 3
#define Button3 4
#define Button4 5

#define LED_R 9   //RGB pins they should be pwm
#define LED_G 10
#define LED_B 11

int Red=0, Blue=0, Green=0; //Color values to be affected to the RGB

bool Button1_State, Button2_State, Button3_State, Button4_State; //Store the buttons states


void setup() {
  
  Serial.begin(9600);        //Set Serial communication
  
  pinMode(Button1,INPUT);    //Set pin modes
  pinMode(Button2,INPUT);
  pinMode(Button3,INPUT);
  pinMode(Button4,INPUT);

  pinMode(LED_R,OUTPUT);     
  pinMode(LED_G,OUTPUT);
  pinMode(LED_B,OUTPUT);
  
}

void loop() {

  Serial.print(Red);     //Display the colors values on the serial monitor
  Serial.print("\t");
  Serial.print(Green);
  Serial.print("\t");
  Serial.println(Blue);
  
  
  Button1_State = digitalRead(Button1); //Read the buttons states
  Button2_State = digitalRead(Button2);
  Button3_State = digitalRead(Button3);
  Button4_State = digitalRead(Button4);

  analogWrite(LED_R,Red);       //Write the values on the RGB
  analogWrite(LED_G,Green);
  analogWrite(LED_B,Blue);

  if(Button1_State == HIGH)   //Button 1 controls the RED, 2 Green and 3 Blue
     Red+= 20;                //Everytime you press the value gets incremented by 20 you can change as you want
  if(Red >= 255)              //If it exceeds the limit it will be brought back to 0
     Red=0;

   if(Button2_State == HIGH)
   Green+= 20;
  if(Green >= 255)
   Green=0;

   if(Button3_State == HIGH)
   Blue+= 20;
   if(Blue >= 255)
   Blue=0;

   if(Button4_State == HIGH){ //Button 4 resets the value to 0
    
    Red=0;
    Green=0;
    Blue=0;
    
   }
  delay(100); //To avoid that one touch gets counted as 10 or more, although 100 is pretty big you can reduce it and test
}

Credits

SurtrTech
9 projects • 207 followers
YT Channel bit.ly/35Ai76l, run by Automation and Electrical Engineer, Electronics amateur, no IT background so you may see wreckage in codes
Contact

Comments

Please log in or sign up to comment.