Using a TTP223B touch module and relay to control AC/DC loads with an Arduino

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.

Schematic of TTP223 module
Arduino wring for TTP223 Touch sensor with relay
TTP223 Touch module - Top view
TTP223 Touch module - Top view

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

ManufacturerTaiwan Semiconductor (TONTEK)
Part numberTTP223B
Logic/IO voltage2.2 - 5.5 V
Supply voltage2.2 - 5.5 V
Output current (per channel)20 mA max
Peak current (per channel)50 mA max
PWM frequency guidanceN/A
Input logic thresholds0.3 * VCC (low), 0.7 * VCC (high)
Voltage drop / RDS(on) / saturationN/A
Thermal limitsN/A
PackageTO-220
Notes / variantsAlso 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

Bilder

Arduino wring for TTP223 Touch sensor with relay (blue)
Arduino wring for TTP223 Touch sensor with relay (blue)
Arduino wring for TTP223 Touch sensor with relay
Arduino wring for TTP223 Touch sensor with relay
TTP223 Touch module - Top view
TTP223 Touch module - Top view
TTP223 Touch module - back view
TTP223 Touch module- back view
TTP223 Touch module - Top view
TTP223 Touch module - Top view
TTP223 Touch module - back view
TTP223 Touch module - back view
Schematic of TTP223 module
Schematic of TTP223 module
21-TTP223B capacitive touch sensor with relay and AC load code
Sprache: C++
29-How to turn on an AC bulb with a TTP223 capacitive touch Arduino and relay code
Sprache: C++
30-TTP223 Capacitive Touch Arduino with relay code and a 5-second delay
Sprache: C++
Kopiert!

Ressourcen & Referenzen

Noch keine Ressourcen vorhanden.

Dateien📁

Datenblatt (pdf)