本教程是的一部分: 使用 Arduino 控制继电器
这里是所有与接力赛相关的视频合集。其他视频的链接在本文下方。
TTP224 4-Channel Touch Sensor to Turn AC/DC Loads with Relay
The TTP224 capacitive touch module is a versatile component that allows users to control AC and DC loads (like light, fan, motor) through touch inputs. In this tutorial, we will demonstrate how to connect the TTP224 to an Arduino to operate a relay, which can switch your lights or other devices on and off with just a touch. By the end of this guide, you will have a fully functional touch-sensitive control system for your electrical devices. For a visual walkthrough, be sure to check out the video (in video at 00:00).
Hardware Explained
The main components used in this project include the TTP224 capacitive touch module, an Arduino board, and a relay module. The TTP224 module detects touch through capacitive sensing, meaning it can register a touch by measuring changes in capacitance when a finger is placed near its pads. This module has four outputs that correspond to four different touch inputs, allowing you to control multiple devices. The relay module acts as a switch that can control high voltage AC loads safely. The relay used in this tutorial is LOW-Level triggered meaning when signal at the input of relay module is LOW,the relay turns ON and when signal is HIGH, the relay turns OFF. When the relay is activated, it connects the common terminal to the normally open terminal, allowing current to flow to the connected device. The relay is controlled by the Arduino, which reads the outputs from the TTP224 and activates the relay accordingly.Datasheet Details
| Manufacturer | Vishay |
|---|---|
| Part number | TTP224 |
| Logic/IO voltage | 2.2 – 5.5 V |
| Output current (per channel) | 10 mA (max) |
| Input logic thresholds | 0.3 V (low), 0.7 V (high) |
| Package | 16-pin DIP |
| Notes / variants | Four touch channels |
- Ensure the module is powered within 2.2 – 5.5 V for proper operation.
- Monitor the output current to avoid exceeding 10 mA per channel.
- Use decoupling capacitors near the module to filter power supply noise.
- Keep wiring short to reduce interference and improve signal quality.
- Use pull-down resistors on the input pins if not using Arduino for control.
Wiring Instructions

Code Examples & Walkthrough
The Arduino code begins by setting up the output pins for the relay and the input pins for the touch sensors. The code initializes the serial communication for debugging as well.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
pinMode(4, INPUT); // Button 3 input pin 4
pinMode(5, INPUT); // Button 4 input pin 5
}
This setup function configures the pins for the touch sensors and relay outputs. It initializes the serial monitor to track button presses.
The loop function continually checks the state of each touch sensor. When a button is pressed, it turns on the corresponding relay output and prints a message to the serial monitor.
void loop() {
if(digitalRead(2)){
Serial.println("Button 1 Touched ");
digitalWrite(10, LOW); // Turn the LED ON
} else {
digitalWrite(10, HIGH); // Turn OFF the LED
}
// Similar checks for buttons 2, 3, and 4...
}
This loop reads the state of each button and activates the corresponding relay pin. If button 1 is pressed, the message "Button 1 Touched" is printed, and the relay connected to pin 10 is activated.
Finally, to modify how long the relay stays activated, you can easily change the delay value in the code. This allows for more flexibility in how you control your devices.
Demonstration / What to Expect
When powered on, the system will allow you to control the connected load by touching the respective pads on the TTP224. For instance, touching pad one will turn on the relay connected to pin 10, which can power your light 💡. If you release the touch, the light 💡 will turn off (in video at 03:00). Be cautious about the wiring; ensure the relay is connected correctly to prevent any short circuits or damage to your devices. If the relay does not activate as expected, check all connections and verify that the Arduino code matches the intended pin configuration.Video Timestamps
- 00:00 - Introduction
- 01:30 - Hardware Setup
- 03:00 - Code Overview
- 04:30 - Demonstration

本教程是……的一部分: 使用 Arduino 控制继电器
- Arduino Code and Video for a Dual-Channel 5V Relay
- Controlling a 5V Relay Using Arduino to cotrol AC or DC load like bulb or motor
- 使用5V继电器模块(低触发)与Arduino
- Using a MAX6675 K-Type Thermocouple with Relay and Display
- Using a Reed Switch to Control a Relay and AC/DC Loads with an Arduino
- Using a TTP223B touch module and relay to control AC/DC loads with an Arduino
- Using an Arduino push button to switch a relay and AC bulb
20-TTP224 4-Channel Capacitive Touch Arduino with Relay Code
语言: C++
/*
* 这是 TTP224 四通道电容触摸开关的 Arduino 代码。按下键 1 至 4 时,输出引脚 10、11、12 和 13 会分别变为低电平,并且连接的继电器会开启。按下按钮 1 会使引脚 10 变为低电平。按下按钮 2 会使引脚 11 变为低电平。按下按钮 3 会使引脚 12 变为低电平。按下按钮 4 会使引脚 13 变为低电平。
*
* 由 Ahmad Nejrabi 为 Roboja Video 编写
* 日期:2017 年 12 月 3 日,加拿大安大略省 Ajax
* 允许分享此代码,前提是此说明与代码一起保留。
* 免责声明:此代码按 "原样" 提供,仅用于教育目的。
*/
int LD = 200; // 循环延迟。请勿更改。
void setup() {
Serial.begin(9600);
// 输出引脚
pinMode(10, OUTPUT); // 按钮1的LED
pinMode(11, OUTPUT); // 按钮2的LED
pinMode(12, OUTPUT); // 按钮3的LED
pinMode(13, OUTPUT); // 按钮4的LED
// 输入引脚
pinMode(2, INPUT); // 按钮 1 输入引脚 2
pinMode(3, INPUT); // 按钮 2 输入引脚 3
pinMode(4, INPUT); // 按钮 3 输入引脚 4
pinMode(5, INPUT); // 按钮4输入引脚5
Serial.println("Robojax Test");
}
void loop() {
// 按钮 1 操作
if(digitalRead(2)){
Serial.println("Button 1 Touched ");
digitalWrite(10, LOW); // 打开LED灯
delay(LD);
}else{
digitalWrite(10, HIGH); // 关闭LED
}
// 按钮2操作
if(digitalRead(3)){
Serial.println("Button 2 Touched ");
digitalWrite(11, LOW); // 打开LED灯
delay(LD);
}else{
digitalWrite(11, HIGH); // 关闭LED
}
// 按钮3动作
if(digitalRead(4)){
Serial.println("Button 3 Touched ");
digitalWrite(12, LOW); // 打开LED灯
delay(LD);
}else{
digitalWrite(12, HIGH); // 关闭LED
}
// 按钮4动作
if(digitalRead(5)){
Serial.println("Button 4 Touched ");
digitalWrite(13, LOW); // 打开LED灯
delay(LD);
}else{
digitalWrite(13, HIGH); // 关闭LED
}
} // 循环
资源与参考
尚无可用资源。
文件📁
数据手册 (pdf)
-
TTP224 datasheet by Taiwan Semiconductor (TONTEK)
TTP224_datasheet.pdf0.29 MB