TTP224 4-Channel Capacitive Touch Arduino Basic Code

TTP224 4-Channel Capacitive Touch Arduino Basic Code

This tutorial will walk you through using the TTP224 4-channel capacitive touch sensor with an Arduino. The TTP224 allows you to create a simple touch interface that can light up LEDs based on which button is pressed. By the end of this project, you will have a working system where touching each of the four buttons will turn on a corresponding LED and display messages on the serial monitor.

TTP224 touch module

In this setup, when a button is pressed, the corresponding output pin on the Arduino will be activated, turning on an LED. You'll also see a message in the serial monitor indicating which button was touched. This project is ideal for beginners looking to learn about capacitive touch technology and basic Arduino programming. For more details, be sure to check the video at 2:30.

Hardware Explained

The main component of this project is the TTP224 capacitive touch sensor. It features four touch-sensitive buttons, allowing for simple interaction without mechanical switches. When a button is touched, the sensor outputs a high signal on the corresponding output pin. This makes it easy to connect to other devices like LEDs or relays.

In addition to the TTP224, you'll need an Arduino board to process the touch input and control the LEDs. The Arduino reads the sensor's output pins and activates the LEDs accordingly. This setup can also be expanded for more complex applications, such as controlling a relay or creating a security lock system.

Datasheet Details

ManufacturerTonTouch
Part numberTTP224
Logic/IO voltage2.5–5.5 V
Output current (per channel)10 mA max
Peak current (per channel)20 mA max
Response time10 ms (typ.)
Package8-DIP

  • Ensure the power supply is stable within the specified range.
  • Use pull-down resistors if needed to prevent floating states.
  • Keep the sensor away from sources of interference like strong electromagnetic fields.
  • Consider using a debounce delay to prevent false triggers.
  • Test the touch sensitivity and adjust the environment for optimal performance.

Wiring Instructions

Wring TTP224 Touch 4 Channel with 4 LED
Wring TTP224 Touch 4 Channel with 4 LED

To wire the TTP224 to the Arduino, start by connecting the power and ground. Connect the VCC pin of the TTP224 to the 5V pin on the Arduino, and the GND pin to a ground pin on the Arduino. Next, connect the output pins of the TTP224 to the Arduino digital pins. Specifically, connect output pin 1 to pin 2, output pin 2 to pin 3, output pin 3 to pin 4, and output pin 4 to pin 5 on the Arduino.

For the LEDs, connect the anodes (longer pins) of each LED to Arduino pins 10, 11, 12, and 13 respectively. Connect the cathodes (shorter pins) of the LEDs to ground through a resistor (typically 220Ω) to limit the current. This setup will allow the Arduino to control each LED based on touch input from the TTP224.

Code Examples & Walkthrough

The Arduino code initializes the output pins for the LEDs and the input pins for the touch sensor. The code uses simple conditionals to check if a button is pressed and then turns on the corresponding LED while printing a message to the serial monitor.

int LD = 200; // Loop Delay. Do not change.

void setup() {
    Serial.begin(9600);
    pinMode(10, OUTPUT);// LED for button 1
    pinMode(11, OUTPUT);// LED for button 2
    pinMode(12, OUTPUT);// LED for button 3
    pinMode(13, OUTPUT);// LED for button 4            
    pinMode(2, INPUT);// Button 1 input pin 2  
    pinMode(3, INPUT);// Button 2 input pin 3  
}

In this excerpt, the variable LD is defined to control the loop delay. The setup() function initializes the serial communication and sets the appropriate pins as inputs or outputs.

void loop() {
    if(digitalRead(2)){
        Serial.println("Button 1 Touched "); 
        digitalWrite(10, HIGH); // Turn the LED ON     
        delay(LD); 
    }else{
        digitalWrite(10, LOW);// Turn OFF the LED
    }
}

This code snippet demonstrates how the Arduino checks the state of the input pin connected to button 1. If the button is touched, it prints a message and turns on the corresponding LED. The same logic is repeated for the other buttons in the full code.

Demonstration / What to Expect

When you run the program, touching each button on the TTP224 will light up the corresponding LED and display a message in the serial monitor. Ensure that your wiring is correct to avoid issues. If you touch multiple buttons simultaneously, you may see unexpected behavior, so be cautious of that (in video at 5:15).

Video Timestamps

  • 00:00 - Introduction to TTP224
  • 02:30 - Wiring setup
  • 04:15 - Code walk-through
  • 05:15 - Demonstration of the project

Images

TTP224 touch module
TTP224 touch module
Wring TTP224 Touch 4 Channel with 4 LED
Wring TTP224 Touch 4 Channel with 4 LED
19-TTP224 4-Channel Capacitive Touch Arduino Basic Code
Language: C++
Copied!

Resources & references

No resources yet.

Files📁

Datasheet (pdf)