Example Code for Arduino-TouchPad
Last revision 2025/12/12
This guide offers example code and setup instructions for using an Arduino TouchPad with a 3.3V Arduino Pro Mini, focusing on integrating capacitive touch functionality via the MPR121 library.
Hardware Preparation
- 3.3V Arduino Pro Mini: Quantity 1
- DFRobot Touch Kit (TouchPad): Quantity 1
- Wiring: SDA (MPR121) -> PIN A4 (Arduino), SCL (MPR121) -> PIN A5 (Arduino), IRQ (MPR121) -> PIN A2 (Arduino)
Software Preparation
- Development Tool: Arduino IDE
- Library: MPR121 v1.0.zip
Wiring Diagram
Touch pad CD
The pin number is the same to the PCB board one.
Other Preparation Work
Please download the MPR121 v1.0.zip first.
Sample Code
// #
// # Editor : Jiang from DFRobot
// # Data : 19.11.2012
// # E-Mail : [email protected]
// # Product name : Capacitive touch pad
// # Version : 0.4
// # Power supply: 3.3v
// # Connection:
// # SDA (MPR121) -> PIN A4 (Arduino)
// # SCL (MPR121) -> PIN A5 (Arduino)
// # IRQ (MPR121) -> PIN A2 (Arduino)
#include <Wire.h>
#include <mpr121.h>
int X ; // X-coordinate
int Y ; // Y-coordinate
// ========= setup =========
void setup()
{
// initialize function
Serial.begin(19200);
Wire.begin();
CapaTouch.begin();
delay(500);
Serial.println("START");
}
// ========= loop =========
void loop()
{
X=CapaTouch.getX(); // Get X position.
Y=CapaTouch.getY(); // Get Y position.
if(X>=1&&X<=9&&Y>=1&&Y<=13)
{ // Determine whether in the range.If not,do nothing.
Serial.print("X=");
Serial.print(X);
Serial.print(" Y=");
Serial.println(Y);
}
delay(200);
}
Was this article helpful?
