Questo tutorial è parte di: Controllo del relè tramite Arduino
Questo è un gruppo di video tutti correlati alla staffetta. I link ad altri video si trovano sotto questo articolo.
Using a TTP223B touch module and relay to control AC/DC loads with an Arduino
In this tutorial, we will explore how to use the TTP223B capacitive touch module alongside a relay to control AC or DC loads with an Arduino. This setup allows for convenient touch-based activation of devices such as light bulbs or other electrical components. You will learn how to wire the components, write the Arduino code, and adjust the timing for how long the load remains active after being touched. This is a great project for both beginners and experienced users looking to expand their skills.




Throughout this guide, we will walk you through the essential components, wiring instructions, and the programming required to get this project up and running. You will also learn how to modify the timing for load activation based on your preferences (in video at 10:15). Be sure to check out the accompanying video for a visual demonstration of the process.
Hardware Explained
The key components for this project include the TTP223B touch module, a relay, and an Arduino. The TTP223B module detects touch inputs and sends a signal to the Arduino, which can then control the relay. The relay acts as a switch, allowing you to control higher voltage AC or DC loads safely.
The TTP223B chip is made by Taiwan Semiconductor (TONTEK) and module operates on a supply voltage of 2.2V to 5.5V and has three pins: VCC (power), GND (ground), and SIG (signal). When the touchpad is activated, the SIG pin sends a high signal to the Arduino. View datasheet for full details. The relay, on the other hand, requires a control signal from the Arduino to switch the load on or off. This control is achieved through a digital output pin connected to the relay.
Datasheet Details
| Manufacturer | Taiwan Semiconductor (TONTEK) |
|---|---|
| Part number | TTP223B |
| Logic/IO voltage | 2.2 - 5.5 V |
| Supply voltage | 2.2 - 5.5 V |
| Output current (per channel) | 20 mA max |
| Peak current (per channel) | 50 mA max |
| PWM frequency guidance | N/A |
| Input logic thresholds | 0.3 * VCC (low), 0.7 * VCC (high) |
| Voltage drop / RDS(on) / saturation | N/A |
| Thermal limits | N/A |
| Package | TO-220 |
| Notes / variants | Also known as BA6 |
- Ensure proper grounding to avoid false triggering.
- Use a capacitor to filter noise on the touch signal line.
- Verify relay specifications to match load requirements.
- Be cautious with AC connections—ensure proper insulation and safety measures.
- Adjust the timing in the code for desired load activation duration.
Wiring Instructions
To wire the TTP223B touch module and relay with the Arduino, follow these steps:
First, connect the VCC pin of the TTP223B to a 5V power source, either from the Arduino or an external supply. Next, connect the GND pin of the TTP223B to the ground. The SIG pin should be connected to pin 2 on the Arduino, which will read the touch input.
For the relay, connect its VCC pin to the same 5V power source, and connect its GND pin to ground. The control signal pin of the relay should be connected to pin 10 on the Arduino. Ensure that the relay is wired correctly to the load you want to control, with one wire going to the common (COM) pin and the other to the normally open (NO) pin. This setup allows the relay to switch the load on and off based on the Arduino's control signal.
Code Examples & Walkthrough
The following code snippet initializes the setup for the TTP223B touch module and relay. It sets pin modes for input and output, enabling the Arduino to read touch signals and control the relay.
void setup() {
Serial.begin(9600);
pinMode(10, OUTPUT); // Relay control pin
pinMode(2, INPUT); // Touch input pin
Serial.println("Robojax Test: TTP223B touch");
}
In the setup, we define pin 10 as an output to control the relay and pin 2 as an input to read the touch signal. A serial monitor is initiated for debugging purposes.
The main loop of the program checks if the touch button is pressed. If it is, the relay is activated, turning on the connected load.
void loop() {
if(digitalRead(2)) {
Serial.println("Button Touched");
digitalWrite(10, LOW); // Turn the relay ON
delay(LD);
} else {
digitalWrite(10, HIGH); // Turn OFF the relay
}
}
This code continuously reads the state of pin 2. If the touch sensor is activated, it turns the relay on for a specified duration defined by the variable LD. If the sensor is not touched, the relay turns off.
Demonstration / What to Expect
Upon completing the wiring and uploading the code, you should see the connected load (e.g., a light bulb) turn on when you touch the TTP223B module. The duration for which the load remains on is controlled by the LD variable in the code. If you want the load to stay on longer, simply increase the value of LD to the desired duration in milliseconds.
Common pitfalls include incorrect wiring, which could lead to the relay not activating or the touch sensor not responding. Ensure that all connections are secure and that you are using the correct pins as defined in the code. Additionally, be cautious when working with AC loads to avoid electric shock or damage.
Video Timestamps
- 00:00 - Introduction to the project
- 02:30 - Wiring overview
- 05:15 - Code explanation
- 10:15 - Demonstration of the setup
Questo tutorial è parte di: Controllo del relè tramite Arduino
- Codice Arduino e video per un relè a doppio canale da 5 V
- Controlling a 5V Relay Using Arduino to cotrol AC or DC load like bulb or motor
- TTP224 4-Channel Touch Sensor to Turn AC/DC Loads with Relay
- Utilizzando un modulo relè a 5V (bassa attivazione) con Arduino
- Utilizzo di una termocoppia di tipo K con MAX6675, relè e display
- Using a Reed Switch to Control a Relay and AC/DC Loads with an Arduino
- Usare un pulsante Arduino per commutare un relè e una lampadina in corrente alternata
/*
* Questo è il codice Arduino per l'interruttore a tocchi capacitivi TTP223B con relè.
* Il pin di uscita 10 è collegato al relè.
* Toccando il pad tattili TTP223B o TTP223N-BA6, il relè verrà attivato.
*
* Scritto da Ahmad Nejrabi per Roboja Video.
* Data: 4 dicembre 2017, ad Ajax, Ontario, Canada.
* Permesso di condividere questo codice, a condizione che questa
* nota venga tenuta insieme al codice.
* Dichiarazione di non responsabilità: questo codice è fornito "COSÌ COM'È" e solo a scopo educativo.
*/
int LD = 200; // Ritardo del Loop. Controlla per quanto tempo dopo il rilascio la lampadina è ACCESA
void setup() {
Serial.begin(9600);
// pin di uscita
pinMode(10, OUTPUT); // LED per il pulsante 1
// pin di ingresso
pinMode(2, INPUT); // Pulsante 1 pin di ingresso 2
Serial.println("Robojax Test: TTP223B touch");
}
void loop() {
// azione pulsante 1
if(digitalRead(2)){
Serial.println("Button Touched");
digitalWrite(10, LOW); // Accendi il LED
delay(LD);
}else{
digitalWrite(10, HIGH); // Spegni il LED
}
} // ciclo
/*
* Questo è il codice Arduino per l'interruttore touch capacitivo TTP223 con relè per accendere o spegnere un carico AC o DC.
* // 13 dicembre 2017
* // Scritto per il video di Robojax.com
* // Utilizzando il modulo touch TTP223 per accendere o spegnere un carico AC (o DC).
* // Quando il pad touch viene toccato, la luce sul relè si accenderà e il pin COM e NO saranno connessi
* guarda il video per i dettagli https://youtu.be/YSI1PdSLbt0
*
* Scritto da Ahmad Nejrabi per il video di RoboJax
* Data: 4 dicembre 2017, ad Ajax, Ontario, Canada
* Autorizzazione concessa per condividere questo codice a condizione che questa
* nota sia mantenuta con il codice.
* Esclusione di responsabilità: questo codice è "COSÌ COM'È" e solo per scopi educativi.
*
* /
*
* // 12 dicembre 2017
* // Scritto per il video di Robojax.com
* // Utilizzando il modulo touch TTP223 per accendere o spegnere un carico AC (o DC).
* // Quando il pad touch viene toccato, la luce sul relè si accenderà e il pin COM e NO saranno connessi
*/
int touchPin = 2; // collega l'uscita da TTP223 a questo
int val = 0;
int relayPin = 10; // Collegato al rele.
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();
}
/*
* Questo è il codice Arduino per l'interruttore a sfioro capacitivo TTP223 con relè per accendere un carico AC o DC con ritardo.
* // 13 dicembre 2017
* // Scritto per il video di Robojax.com
* // Utilizzando il modulo TTP223 Touch per accendere un carico AC (o DC) e attende 5 secondi prima di spegnersi.
* // Quando il pannello tattile viene toccato, la luce sul relè si accenderà e i pin COM e NO saranno collegati.
* Guarda il video per i dettagli: https://youtu.be/YSI1PdSLbt0
*
* Scritto da Ahmad Nejrabi per RoboJax Video
* Data: 4 dicembre 2017, ad Ajax, Ontario, Canada
* Autorizzazione concessa per condividere questo codice a condizione che questa
* nota venga mantenuta con il codice.
* Disclaimer: Questo codice è "COSÌ COM'È" e solo per scopi educativi.
*
* /
*
* // 12 dicembre 2017
* // Scritto per il video di Robojax.com
* // Utilizzando il modulo TTP223 Touch per accendere o spegnere un carico AC (o DC).
* // Quando il pannello tattile viene toccato, la luce sul relè si accenderà e i pin COM e NO saranno collegati.
*/
int touchPin = 2; // collegare l'uscita del TTP223 a questo
int val = 0;
int relayPin = 10; // Collegato al relè
int wait = 5; // aspetta per 5 secondi
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(wait*1000);
}
delay(100);
Serial.println();
}
Risorse e riferimenti
Nessuna risorsa ancora.
File📁
Scheda tecnica (pdf)
-
Datasheet TTP223 di Taiwan Semiconductor (TONTEK)
TTP223_datasheet.pdf0.27 MB