RoboJax Touch Counter V3 Using TM1637 4-Digit LED Display
```htmlRoboJax Touch Counter V3 Using TM1637 4-Digit LED Display
This project demonstrates how to build a touch counter using a TTP223 touch sensor and a TM1637 4-digit LED display. Each touch increments the counter, displayed on the LED. A reset button allows resetting the count to zero. This simple project provides a foundation for various applications and is a great introduction to interfacing sensors and displays with Arduino.
Here are some project ideas using this touch counter:
- Simple tally counter for events or inventory.
- Lap counter for races or games.
- Visitor counter for exhibits or rooms.
- Rep counter for exercise routines.
Hardware/Components
- Arduino Uno (or compatible board)
- TTP223 or TTP223B Touch Sensor Module
- TM1637 4-Digit LED Display Module
- Pushbutton (for reset)
- Jumper wires
- Breadboard (optional)
Wiring Guide
%%WIRING%%For the TTP223 touch sensor:
- VCC to Arduino 5V
- GND to Arduino GND
- SIG/IO/OUT to Arduino pin 2 (can be changed in code)
For the TM1637 display:
- VCC to Arduino 5V
- GND to Arduino GND
- CLK to Arduino pin 10
- DIO to Arduino pin 11
For the reset button:
- One leg to Arduino GND
- Other leg to Arduino pin 12 (can be changed in code)
Code Explanation
This sketch uses the TM1637 library. Install it via the Arduino IDE Library Manager.
Key configurable elements in the code:
#define CLK 10 // clock pin
#define DIO 11 // data in-out pin
const int touchPin = 2; // touch sensor pin
const int resetPin = 12; // reset button pin
const int touchDelay = 500; // delay between touches (in ms) (in video at 04:15)
Adjust these pin definitions if you're using different pins. The touchDelay variable (in video at 04:15) prevents multiple counts from a single touch. A voltage divider isn't necessary for the touch sensor or reset button because the Arduino's internal pull-up resistor is used for the reset button, and the touch sensor module handles its own voltage regulation.
The following lines initialize the serial monitor and set the initial display state:
Serial.begin(9600);
display.setBrightness(0x0f); // Set brightness (0x00 to 0x0f) (in video at 05:24)
display.showNumberDec(0); // Initial display value
The main loop reads the touch sensor and reset button states. If the touch sensor is activated, the count increments and is displayed. If the reset button is pressed, the count resets to zero.
Live Project/Demonstration
(in video at 09:27) The demonstration shows the counter incrementing with each touch and resetting when the button is pressed. The serial monitor also displays the current count. The initial "8888" on the display confirms that the display is functioning correctly.
Chapters
- [00:00] Introduction and Project Overview.
- [00:34] Components and Explanation.
- [02:41] Code Explanation.
- [07:54] Wiring Instructions.
- [09:27] Project Demonstration.
/*
* This is Arduino touch counter V3 using TTP223/TTP223B and TM1637 seven-segment LED Display.
* This program will function as a counter. Every time the touch module is touched,
* the counter increments by 1. The count number is displayed on the TM1637 display.
* We have a reset button to restart the counting from zero.
*
* Watch video instructions for this video: https://youtu.be/VzH9iEqrm0E
*
* Written by Ahmad Shamshiri on Sunday, October 28th at 10:33 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/>.
*/
//***** beginning of TM1637 Display
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 10 // clock pin
#define DIO 11 // data in-out pin
// The amount of time (in milliseconds) between readings
#define TEST_DELAY 300
TM1637Display display(CLK, DIO);
uint8_t blank[] = { 0x0, 0x0, 0x0, 0x0 };// data to clear the screen
//***** end of TM1637 Display
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 = 500;//millisecond delay between each touch
int count=0;// variable holding the count number
void setup() {
// Robojax.com Touch counter 20181029
Serial.begin(9600);// initialize serial monitor with 9600 baud
Serial.println("Robojax Touch Counter V3");
pinMode(touchPin,INPUT);// define a pin for touch module
pinMode(resetPin,INPUT_PULLUP);// define a pin for reset button
// see video ( link in the video description) on using PULLUP
display.setBrightness(0x0f);// set brightness of display
uint8_t data8888[] = { 0xff, 0xff, 0xff, 0xff }; // all segments show
display.setSegments(data8888); // display 8888 on display for test
delay(3000);// give time to user to read the display at the beginning
display.setSegments(blank); // clear the screen from previous values
display.showNumberDec(0);// display zero at the belonging
// Robojax.com Touch counter 20181029
}
void loop() {
// Robojax.com Touch counter 20181029
int touchValue = digitalRead(touchPin);// read touchPin and store it in touchValue
// if touchValue is HIGH
if(touchValue == HIGH)
{
count++;// increment the count
display.setSegments(blank); // clear the screen from previous values
display.showNumberDec(count);// display 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
display.setSegments(blank); // clear the screen from previous values
display.showNumberDec(count);// display the count
}
// Robojax.com Touch counter 20181029
}
文件📁
没有可用的文件。