Search Code

RoboJax Touch Counter V1 (Basic Counter)

RoboJax Touch Counter V1 (Basic Counter)

Introduction

This guide demonstrates how to build a simple yet practical touch counter using an Arduino and the TTP223B capacitive touch sensor module. The project, created by Robojax, provides a hands-on introduction to reading digital inputs and managing state within a microcontroller program. Instead of a physical push-button, this project uses a touch-sensitive pad, which is a great way to learn about capacitive sensing technology.

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

The core functionality is straightforward: each time you touch the sensor, a counter increments by one, and the current count is displayed on the Arduino's Serial Monitor. A separate push-button is used to reset the count back to zero. This simple project can be adapted for a variety of real-world applications, including:

  • Creating a simple people counter for a room or event.
  • Building a tally counter for inventory or counting items.
  • Developing a touch-based control panel for other projects.
  • Teaching the fundamentals of digital input reading and state management.

Hardware Required

  • Arduino board (Uno, Nano, etc.)
  • TTP223B capacitive touch sensor module
  • Push-button switch
  • Breadboard and jumper wires

Wiring Guide

The wiring for this project is very simple, requiring only a few connections. The TTP223B module has three pins: VCC, GND, and OUT (or SIG). The push-button has two pins, and it is connected using the internal pull-up resistor of the Arduino, which simplifies the circuit by removing the need for an external resistor.

Here is the connection diagram:

  • TTP223B VCC: Connect to the Arduino's 5V pin.
  • TTP223B GND: Connect to the Arduino's GND pin.
  • TTP223B OUT: Connect to Arduino digital pin 2.
  • Push-button Pin 1: Connect to Arduino digital pin 12.
  • Push-button Pin 2: Connect to the Arduino's GND pin.

As explained in the video, the push-button is wired to use the Arduino's internal pull-up resistor. This means the pin will read HIGH when the button is not pressed and LOW when it is pressed, eliminating the need for an external resistor. (in video at 03:48)

Code Explanation

The Arduino code for this project is concise and focuses on a few key configurable parameters. You can easily adapt this project to use different pins or adjust the timing by modifying the variables at the top of the sketch.

const int touchPin = 2;// the input pin where touch sensor is connected
const int resetPin = 12;// the input pin for reset button
const int touchDelay = 10;//millisecond delay between each touch
  • touchPin: This constant defines the digital pin to which the OUT pin of the TTP223B touch sensor is connected. You can change the number 2 to any other digital pin (e.g., 3, 4, 5, etc.) if you prefer a different wiring setup.
  • resetPin: This constant defines the digital pin connected to the reset push-button. The default value is 12, but you can change it to any other available digital pin.
  • touchDelay: This variable sets a delay in milliseconds after a touch is detected. Its purpose is to debounce the sensor and prevent multiple counts from a single, quick touch. A value of 10 milliseconds is a good starting point, but you can increase it (e.g., to 100 or 500) if you find that the counter is incrementing too quickly. (in video at 02:45)

The count variable is an internal counter that you should not modify. The setup() function initializes the Serial Monitor at a baud rate of 9600, which must match the setting in your Arduino IDE's Serial Monitor, and sets the pin modes for the touch sensor and reset button. The loop() function continuously reads the touch sensor; when it detects a HIGH signal, it increments the count variable and prints the new value to the Serial Monitor. It also checks the reset button, and if it reads LOW, it sets the count back to zero. (in video at 04:04)

Live Project Demonstration

Once the code is uploaded to your Arduino, open the Serial Monitor (set to 9600 baud). You should see the message "Robojax Touch Counter". Every time you touch the metal pad on the TTP223B module, the counter will increment and print a message like "Touched 1 times." Pressing the reset button will clear the count and print "Counter Resetted." The video demonstrates this process with two different TTP223B modules, showing that the code works with both common variants. (in video at 00:49)

Conclusion

This project provides a solid foundation for understanding how to interface with touch sensors and manage simple counters. The code is clean and well-commented, making it easy to modify for other purposes. The creator also mentions future variations, such as adding a limit to the count or triggering an alarm or relay after a specific number of touches, which are excellent next steps for expanding your skills. (in video at 05:50)

Chapters

  • [00:00] Introduction to the Touch Counter Project
  • [00:49] Hardware Setup and Wiring
  • [02:29] Code Explanation
  • [04:04] How the Loop Function Works
  • [05:50] Conclusion and Future Project Ideas

Images

TTP223B touch module
TTP223B touch module
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
Schematic of TTP223 module
Schematic of TTP223 module
165-RoboJax Touch Counter V1 (basic counter)
Language: C++
++
/*
 * This is an Arduino Robojax Touch counter using TTP223/TTP223B.
 * This program will function as a counter. Every time the touch module is touched,
 * the counter increments by 1.
 * We have a reset button to restart the counting from zero.
 * 
 * Watch video instructions for this video: https://youtu.be/zJ-yd4vYn8s
 * 
 * Written by Ahmad Shamshiri on Saturday, October 27th at 2:40 PM in Ajax, Ontario, Canada.
 * Get this code from Robojax.com
 * 
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
 * This code has been downloaded from Robojax.com.
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

const int touchPin = 2;// the input pin where touch sensor is connected
const int resetPin = 12;// the input pin for reset button
const int touchDelay = 10;//millisecond delay between each touch

int count=0;// variable holding the count number

void setup() {
 // Robojax.com Touch counter 20181027
  Serial.begin(9600);// initialize serial monitor with 9600 baud
  Serial.println("Robojax Touch Counter");  
  pinMode(touchPin,INPUT);// define a pin for touch module
  pinMode(resetPin,INPUT_PULLUP);// define a pin for reset button
  // see video ( http://bit.ly/pushbutton-resistor) on using PULLUP

  
  // Robojax.com Touch counter 20181027        
}

void loop() {
  // Robojax.com Touch counter 20181027
  int touchValue = digitalRead(touchPin);// read touchPin and store it in touchValue

  // if touchValue is HIGH
  if(touchValue == HIGH)
  {

    count++;// increment the count

      Serial.print("Touched ");//print the information
      Serial.print(count);//print count
      Serial.println(" times.");        
    delay(touchDelay);// touch delay time
  }

   // if reset switch is pushed
   if(digitalRead(resetPin) == LOW)
   {
    count =0;// reset the counter;
      Serial.println("Counter Resetted.");//print the information
    
   }

  // Robojax.com Touch counter 20181027
}

Files📁

Datasheet (pdf)

Other files