Introduction
If you’re looking for a simple and easy-to-use keypad for your next Arduino project, the TTP229 16-key capacitive touch keypad might be what you need. With its compact size and capacitive touch-sensing technology, this keypad allows quick and accurate inputs without needing physical buttons or switches. Plus, it’s easy to interface with the Arduino using just a few lines of code. Whether you’re building a home automation system, a musical instrument, or anything in between, the TTP229 keypad is a versatile and reliable input solution.
With the 16 keys, it allows you to assign different functions to each key, providing you with a customizable input solution for your project. So if you’re looking for a compact, easy-to-use input device for your next Arduino project, the TTP229 16-key capacitive touch keypad is worth considering.
What is Capacitive Touch Keypad?
A capacitive keyboard is a keyboard that senses when a key is pressed by changing the capacitance on the keyboard’s capacitor pad. This sort of keyboard has functionality comparable to that of a conventional mechanical keyboard, yet, pressing a key on this type of keyboard is faster due to its internal structure.
Hardware Components
You will require the following hardware for Interfacing TTP229 16 Key Capacitive Touch Keypad with Arduino.
S.no | Component | Value | Qty |
---|---|---|---|
1. | Arduino UNO | – | 1 |
2. | Capacitive Touch Keypad 4×4 | TTP229 | 1 |
3. | Breadboard | – | 1 |
4. | Jumper Wires | – | 1 |
TTP229 Touch Keypad with Arduino
Follow the given steps to interface a capacitive touch keypad with Arduino:
Schematic
Make connections according to the circuit diagram given below.
Installing Arduino IDE
First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.
Code
Now copy the following code and upload it to Arduino IDE Software.
4×2
/*
XD-62B-TTP229-4x4-Keypad-8
*/
void setup(){
for(int x=2;x<10;x++)
pinMode(x,INPUT);
Serial.begin(9600);
}
void loop(){
for(int y=2;y<10;y++){
if (digitalRead(y)==HIGH)
Serial.println(y-1);
}
}
4×4
/*
XD-62B-TTP229-4x4-Keypad-16
*/
/* Define the digital pins used for the clock and data */
#define SCL_PIN 10
#define SDO_PIN 11
/* Used to store the key state */
byte Key;
void setup()
{
/* Initialise the serial interface */
Serial.begin(9600);
/* Configure the clock and data pins */
pinMode(SCL_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
}
/* Main program */
void loop()
{
/* Read the current state of the keypad */
Key = Read_Keypad();
/* If a key has been pressed output it to the serial port */
if (Key)
Serial.println(Key);
/* Wait a little before reading again
so not to flood the serial port*/
delay(100);
}
/* Read the state of the keypad */
byte Read_Keypad(void)
{
byte Count;
byte Key_State = 0;
/* Pulse the clock pin 16 times (one for each key of the keypad)
and read the state of the data pin on each pulse */
for(Count = 1; Count <= 16; Count++)
{
digitalWrite(SCL_PIN, LOW);
/* If the data pin is low (active low mode) then store the
current key number */
if (!digitalRead(SDO_PIN))
Key_State = Count;
digitalWrite(SCL_PIN, HIGH);
}
return Key_State;
}
Testing and Working Explanation
Let’s dive into the coding to understand the working of the circuit!
You can see that there are two codes given above. Let’s talk about the first code first.
First Code
The first code will configure 8 pins as input, read the state of these pins repeatedly, and if the state is high, it will print the pin number minus 1 on the serial port.
- The setup function is called once at the beginning of the program and is typically used to set initial values or configure the microcontroller. In this case, the code uses a for loop to iterate through the numbers from 2 to 9. The pinMode function is called for each iteration to configure the pin with the current number as an input.
- The loop function is called repeatedly after the setup function is finished. In this case, another for loop is used to iterate through numbers 2 to 9. For each iteration, the digitalRead process is called to read the state of the pin with the current number, then checks if the value returned is HIGH. If the value is HIGH, then the code calls the Serial.println function to print the current number minus 1 to the serial port. This will cause the number to be sent to a connected computer via a serial connection, where it can be displayed or processed further.
Second Code
- At the beginning of the code, the pins for the Serial Clock (SCL) and Serial Data Out (SDO) lines are defined as constant integers using the “#define” preprocessor directive. Then a variable “Key” is declared to store the state of the keypad.
- The “void setup()” function is called once when the program starts, and it is used to initialize the Serial communication and to set the pin modes of the SCL and SDO pins.
- The “void loop()” function is called repeatedly, and it is used to read the current state of the keypad using the “Read_Keypad()” function and output it to the serial port using the “Serial.println(Key)” function call, if a key has been pressed.
- The “Read_Keypad()” function is defined at the end of the code, it is used to read the state of the keypad by pulsing the clock pin 16 times (one for each key of the keypad) and reading the state of the data pin on each pulse. On each pulse, if the data pin is low (active low mode) the current key number is stored in the “Key_State” variable. The “Key_State” variable is returned at the end of the function.
Applications
- Electronic devices
- Smartphones
- Home and industrial automation systems, etc
Conclusion.
We hope you have found this Circuit very useful. If you feel any difficulty in making it feel free to ask anything in the comment section.