Example Code for Arduino-KeyPad

Last revision 2025/12/12

This article guides users through the setup and programming of an Arduino-KeyPad using the MPR121 library, providing hardware preparation details, software requirements, wiring diagrams, and example code to enable effective touch interaction.

Hardware Preparation

  • 3.3V Arduino Pro Mini: Quantity 1
  • DFRobot Touch Kit (KeyPad): Quantity 1
  • Wiring: SDA -> A4, SCL -> A5, IRQ -> D2

Software Preparation

Wiring Diagram

Keypad 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


/*
 TouchWheel.pde
 MPR121 WhellPad Example Code

 by:Waiman Zhao
 Mail:[email protected]
 created on: 11/2/14
 license: CC-SA 3.0

 Hardware: 3.3V Arduino Pro Mini
           SDA -> A4
           SCL -> A5
           IRQ -> D2
*/


#include <Wire.h>
#include <mpr121.h>

int key = 0;


// =========  setup  =========
void setup()
{
    //  initialize function
  Serial.begin(19200);
  Wire.begin();
  CapaTouch.begin();

  delay(500);
  Serial.println("START");
}


// =========  loop  =========
void loop()
{
  key=CapaTouch.keyPad();

  if (key==11)
  { Serial.print("key:");
  Serial.println("*");
  }
  else if(key==12)
  {
    Serial.print("key:");
  Serial.println("#");
  }
  else if(key>=0){
    Serial.print("key:");
    Serial.println(key);
  }
    delay(200);
}

Was this article helpful?

TOP