Other Arduino Codes and Videos by Robojax

Robojax Touch Counter V1 (basic counter) Robojax.com

Robojax Touch Counter V1 (basic counter)

This Arduino code make simple touch counter. Every time touch module TTP223/TTP223B is touched, the counter number increases and displayed on the serial monitor in Arduino by pressing Ctrl+Shift+M on your PC. There is a reset button which you can reset the counting at any time.

TTP223 or TTP223B module with a single push button is used to make this counter. Any Arduino boards can be used.

Fig. 1 Wiring of Robojax Touch Counter V1

Resources for this sketch


 /*
 * This is Arduino Robojax Touch counter using TTP223/TTP223B
 * this program will function as counter. Every time the touch module is touch
 * the counter increments +1 to the counter.
 * We have got a reset button to restart the counting from zero.
 * 
 * Watch video instruction for this video:https://youtu.be/zJ-yd4vYn8s
 * 
 * Written by Ahmad Shamshiri on Saturday 27th of October at 14:40 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 download 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
}