In this blog post I talk about how you can use the TTP223B Capacitive Touch sensor with a WeMos D1 Mini (ESP8266) using the Arduino IDE.
Summary of the TTP223B Capacitive Touch Sensor
The TTP223B capacitive touch sensor works as a standard button. The main difference being that it requires no force to activate.
Most mechanical buttons require a minimum amount of force to activate them, providing a tactile response. Since this needs no force to trigger the button it can be used for designs where no actuation force is desired.
This sensor has three pins, SIG, VCC and GND. When the sensor detects a press the SIG pin is pulled HIGH and can be read by the WeMos. The VCC accepts 2 to 5.5 volts which mean its ideal for use with the WeMos that works on 3.3 volts.
Important differences compared with using the TTP223B Capacitive Touch Sensor on an Arduino
There is one major difference to bear in mind when using the TTP223B Capacitive Touch Sensor on a WeMos D1 Mini (ESP8266) or similar chipset.
When using the Arduino IDE with the WeMos chips, the standard pin numbers do not refer to the pin numbers on the WeMos. For example, instead of using 1 to refer to digital pin 1, you need to use the constant D1.
I go into more details for this in my blog post Pin numbering for WeMos D1 Mini (ESP8266). If you haven’t read this and are having trouble connecting your TTP223B Capacitive Touch Sensor properly I recommend having a read.
In addition, because the digital pins on the WeMos do not accept 5 volts, you need to wire VCC to 3.3 volts. Failing to do this will overload the chip and may cause damage to it.
Wiring it up to a WeMos D1 Mini
Here I am connecting the TTP223B Capacitive Touch Sensor to a WeMos D1 mini.
The pins on the TTP223B Capacitive Touch sensor, from left to right, are Signal (digital out) Out, VCC, and GND.
It is important to note that the WeMos’s digital pins can only accept up to 3.3 volts maximum on their inputs. This means that the TTP223B Capacitive Touch Sensor’s VCC pin must be connected to the 3.3 volts and not the 5 volt line like when using the Arduino.
Programming the WeMos to use the TTP223B Capacitive Touch sensor
To use the touch sensor I am going to wire it up so that when it detects a press it will send a message on the serial port.
We configured the touch input pin as an INPUT and start the serial connection in the setup. In the main loop the WeMos continually reads the sensor and prints out either “DETECTED!” or “Not detected”.
This could be changed so that a led is lit, or other actions are performed when the button is pressed.
The TTP223B Capacitive Touch sensor is a nice little alternative to a standard button. In addition since it only requires contact with your hand it is less likely to break from forceful use due to no moving parts.
No ESP8266 specific libraries are required as this only uses the single digital pin. However it is important to ensure you connect the VCC pin to the 3.3 volts line. This is because this is the maximum voltage accepted by the digital pins.