How to Connect a Touch Sensor to Arduino

This site contains affiliate links to products. We may receive a commission for purchases made through these links.

Connecting touch sensor to Arduino is quite a simple task and usually doesn’t take much time. In this tutorial, we will try to be as clear as possible about how you can carry out the process efficiently and ensure that you’ve connected the touch to your Arduino properly without much strain.

x
What is Arduino?

Our post will mainly focus on providing touch inputs to Arduino, which you can use for any output. Therefore, this means that using this touch sensor, you can provide the output that can be controlled by touch inputs, which is quite good.

1. Items You Require

The first step in this process is to identify some of the items that you require. See below what you need:

  • Arduino UNO
  • Jumper wires
  • Breadboard
  • Touch sensor (TTP223B1)

A touch sensor is also known as a touch switch or button, and it is normally used for controlling devices. Therefore, note that it has similar functionalities like a button. It replaces the button on most devices because it gives a product an appealing look.

There are three pins in a touch sensor and they include:

  • GND pin – It should be connected to the GND at 0V
  • Signal pin – This is an output pin. When it’s not touched it is usually LOW and when touched it tends to be HIGH. You should connect this pin to the input pin of the Arduino.
  • VCC pin – You should connect this to the VCC at 3.3V or 5V
How to Connect a Touch Sensor to Arduino

2. The Connection Process

The connection process needs to be done properly for everything to function as it should. Note that when you don’t touch the sensor, the signal pin is normally low. However, when you touch the sensor, its signal pin tends to be high.

Therefore, you need to connect the sensor signal to the input pin of an Arduino. When you read the state of the pin of an Arduino, it is easy to tell if the touch sensor has been touched or not.

Point to Note

There are two cases that are normally used by so many people. They include:

  • The First Case

This is when the input state is high you are supposed to do something, and when it is low carry out a reverse action.

  • The Second Case

If the input case changes from low to high or vice versa, you are supposed to do something.

However, you are supposed to choose one of them depending on the application that you are using. A good example is if you want to control an LED with the use of a touch sensor, below is what you need to consider.

  • In case you want the LED to be ON when you touch the sensor, and OFF when you don’t touch the sensor, you can use the first case defined above.
  • If you want the LED to switch between ON and OFF, every time the sensor is touched, you can go ahead and use the second case.

3. Wiring the Diagram

Three wires are needed to connect Touch Sensor(TTP223B1) to Arduino UNO, for the following connections:

  • VCC to 5V pin of Arduino UNO
  • GND to GND (Ground)
  • SIG to digital pin 8
Connect the components! 🙂
How to Connect a Touch Sensor to Arduino 5

4. Coding

The fourth step in the process of connecting the touch sensor to the Arduino involves code. When it comes to programming for the touch sensor, you need to initialize the pin of your Arduino as the input. Here is an example pin 8

pinMode(8, input_pullup);

This one tends to read the state of your Arduino pin

int inputState = digitalRead(8);

Check out the code below and copy-paste it:

Void setup() {
pinMode(8, INPUT);
serial.begin(9600);
}
Void loop() {
If (digitalRead(8) = = High)
{serial.printIn("sensor touched");
delay(400);}
}

After you’ve copied the above code, then verify and upload the code to Arduino board. You can open the serial monitor and then set the BAUD RATE to about 9600. Therefore, when it is touched a message will appear written: “Sensor touched” on the Serial Monitor

5. Test the Process

Testing the experiment or project you are carrying is quite crucial. The reason why it is important is that it helps you find any errors to know where you can improve or fix some of the issues involved.

In this process, we highly recommend that you test everything that you have done to see the results and learn even more. After you have connected everything and uploaded the code to your Arduino, every time you touch the sensor in the LED on the pin it will light up.

On the serial monitor, you are supposed to get the message that you included in the code, just the way we indicated above. If you happen to get any errors, make sure you go through everything that you have to see if there are any mistakes you made during the process.

Usually most people are able to get it done faster the first time, since it doesn’t require any “magical” skills or complex methods to do this task. It just requires you to be keen and follow each step as we’ve stipulated in this post.

Please note that you also need a USB 2.0 cable type A/B for this project, as well as jumper wires. There are also 4 example codes that you can test from Examples in this process, and they include:

  • Code to read the touch sensor value and then print it to the serial monitor.
  • A code to control the LED according to the state of the sensor.
  • A code to detect whether the sensor is released or touched.
  • A code that toggles the LED when someone touches the sensor. This is actually the most commonly-used code by a lot of people.

Conclusion

In our opinion, coding is the most complex part of this project, since you can clearly see the other steps have been well-outlined in a way that makes it easier for you to understand and implement. A lot of people have been able to achieve this process and you can too. This is not rocket science.

You will realize that it is not that hard to connect touch sensor to Arduino as has been outlined in this article. It is a process that you can easily follow and get it done effectively. Therefore, go ahead and try it out today.

Special offer for our visitors

Get your Soldering Iron Guide For DIYERS

We will never send you spam. By signing up for this you agree with our privacy policy and to receive regular updates via email in regards to industry news and promotions