In this ESP32 tutorial, I have explained how to connect the TTP223 touch sensor with ESP32 to control relays. We will discuss what changes you must make in the circuit and source code to add to control relays with the TTP223 touch switch.

So after going through this article, you can add the TTP223 sensor to any of your home automation projects.

What is the TTP223 capacitive touch sensor?

The TTP223 is a compact capacitive touch sensor module that detects touch or proximity. It operates with low power consumption, making it suitable for battery-powered devices. When a conductive object, like a finger, approaches or touches the sensor pad, it provides a digital output signal (high or low) to indicate touch status. 

During this article, I have covered the following topics: 

Here I have used one of my previous Blynk projects. So with this home automation project, you can control the appliances with Blynk IoT, Bluetooth, IR, and touch switch. 

 So, you can easily make this touch-sensitive home automation project at home just by using an ESP32 and relay module or you can also use a custom-designed PCB for this project. 

 Required components:

 You can make this project just by using ESP32, an 1838 IR receiver, and a 4-channel relay module. But if you use PCB then you need the following components.

Required components for PCB:

Inbuilt Capacitive Touch Sensor of ESP32

The ESP32 is a popular microcontroller module that comes equipped with various built-in features, including an inbuilt capacitive touch sensor. This capacitive touch sensor is a part of the ESP32's GPIO (General-Purpose Input/Output) pins, which can be configured to sense touch or proximity without the need for additional external components.

ESP32's software libraries and development tools provide easy-to-use functions for configuring and reading the capacitive touch sensor values, simplifying the development process.

Control Relay Without External Touch Switch

Here I have used the inbuilt Capacitive Touch Sensor of ESP32.

If you want to control a single relay, then refer to the above circuit.

The GPIO D27 which T7 is used as the Touch pin.

And the relay is connected to the GPIO D13.

Please refer to the following code for the 1-channel relay.

Download Code for 1-Relay

Now if you want to control multiple relays then I will recommend you to use an external touch sensor like TTP223 with ESP32.

Circuit Diagram of the ESP32 TTP223 Project

The circuit is very simple, I have used the GPIO pins D23, D22, D21 & D19 to control the 4 relays.

The GPIO pins D13, D12, D14 & D27 are connected to the TTP223 touch sensor to control the 4 relays manually.

You can use either 4-channel or 4 1-channel TTP223 touch sensors as per the above circuits.

IR remote receiver (TSOP1838) connected with D35.

I have used a 5V mobile charger to supply the smart relay module.

Please take proper safety precautions while working with high voltage.

Control Relays With Blynk Bluetooth & Touch Switch

Now before designing the PCB, I have tested the circuit.

Here you can see, that you can control the relays with Blynk IoT, Bluetooth, IR remote, and TTP223 touch switch.

In the following steps, I will explain all the steps.

Design the PCB for ESP32 Smart Home System

To make the circuit compact and give it a professional look, I designed the PCB after testing all the features of the smart relay module.

You can download the PCB Gerber, BOM, and "pick and place" files of this ESP32 control relay PCB from the following link:

GitHub link to Download PCB Gerber File

For this project, you can also use the JLC SMT Service while ordering the PCB.

Why you should use JLC SMT Service?

On JLCPCB's one-stop online platform, customers enjoy low-cost & high-quality & fast SMT service at an $8.00 setup fee($0.0017 per joint).

$27 New User coupon & $24 SMT coupons every month.

Visit https://jlcpcb.com

JLCPCB SMT Parts Library 200k+ in-stock components (689 Basic components and 200k+ Extended components)

Parts Pre-Order service https://support.jlcpcb.com/article/164-what-is-jlcpcb-parts-pre-order-service

Build a Personal library Inventory, save parts for now or the future

Assembly will support 10M+ parts from Digikey, Mouser.

Steps to Order the PCB Assembly from JLCPCB

1. Visit https://jlcpcb.com and Sign in / Sign up.

2. Click on the QUOTE NOW button.

3. Click on the "Add your Gerber file" button. Then browse and select the Gerber file you have downloaded.

4. Set the required parameters like Quantity, PCB masking color, etc.

5. Select the Assemble side and SMT Quantity.

6. Now upload the BOM and PickAndPlace files.

7. Now confirm all the components which you want to be soldered by SMT services.

8. Click on the SAVE TO CART button.

Select Shipping Address and Payment Mode

6. Type the Shipping Address.

7. Select the Shipping Method suitable for you.

8. Submit the order and proceed with the payment.

You can also track your order from the JLCPCB

My PCBs took 3 days to get manufactured and arrived within a week using the DHL delivery option.

PCBs were well-packed and the quality was good at this affordable price.

Get the IR Codes (HEX Code) From the Remote

Now, to get the HEX codes from the remote, first, we have to connect the IR receiver output pin with GPIO D35.

And give the 5V across the VCC and GND. The IR receiver must have a metallic casing, otherwise, you may face issues.

GitHub link to Download code to get HEX code

Then follow the following steps to get the HEX codes

Save all the HEX codes in a text file.

Configure the Blynk IoT Cloud

Click on the following link to create a Blynk Cloud account.

https://blynk.cloud/dashboard/register

After that Blynk cloud dashboard will open.

Create a New Template in Blynk Cloud

First, you have to create a template in the Blynk cloud.

You will get the BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME after creating the temple.

After that, you have to create Datastreams. Here I will control 4 relays, so I have to create 4 Datastreams.

Similarly, create 4 datastreams with virtual pin V1 to V4. (Refer to Picture)

Set Up Blynk Cloud Web Dashboard

Now go to the Web Dashboard tab.

Drag and drop 4 Switch widgets.

Go to the settings of each widget, and select a Datastream.

Please refer to the tutorial video for more details.

Then click on Save to save the template.

Add Device Using Template in Blynk IoT

Steps to add a device in the Blynk IoT cloud:

Then in the device info tab, you will get the Blynk Auth Token, Template ID, and Device Name. All these details will be required in the code.

Program the ESP32 for This Blynk Project

GitHub link to Download the Main code

Download and install the following libraries in Arduino IDE

Now open the main sketch (code).

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

 After doing these changes, go to Tools and select the board as "ESP32 Dev Module", Partition Scheme as "Huge APP (3MB...)" and the proper PORT in Arduino IDE.

Then click on the upload button to program the ESP32 board.

While uploading the code to ESP32, if you use the PCB then you will see the "Connecting....___" text, then press and hold the BOOT button and then press the EN button, after that release both buttons.

Install Blynk IoT App to Configure Mobile Dashboard

Download and Setup the Bluetooth App

If the ESP32 is not connected to WiFi, still you can control the relays from mobile using Bluetooth.

I have designed the Bluetooth Switch App in MIT App Inventor for this ESP32 Bluetooth project.

Please download and install the Bluetooth App (GitHub Link), then you have to connect the Bluetooth App with ESP32.

Now you can smartly control your home appliances. I hope you have liked this new Blynk home automation project. I have shared all the required information for this project. 

 I will appreciate it if you share your valuable feedback. Also if you have any queries please write in the comment section. Thank you & Happy Learning.