Project tutorial
Turn (Almost) Any Surface Into a Touch button with MPR121

Turn (Almost) Any Surface Into a Touch button with MPR121 © GPL3+

Capacitance capabilities at the tip of your finger!

  • 3,736 views
  • 10 comments
  • 29 respects

Components and supplies

Apps and online services

About this project

MPR121 is a 12-pin touch sensor, using capacitance capabilities of the IC.

There are 2 libraries for this IC, I personally prefer Using the bare conductive one.

https://github.com/BareConductive/mpr121

The chip has a trigger pin, that allow you to know that one of the pins was either touched or released, giving you great response time and giving you option to use an interrupt instead of scanning the state in the loop – like showed in the example.The only down side it that you have only one trigger pin for all the 12 IO pins of the IC.The I2C address can be set ADDR is the I2C address select pin. By default, this is pulled down to ground with a 100K resistor, for an I2C address of 0x5A. You can also connect it to the 3Vo pin for an address of 0x5B, the SDA pin for 0x5C or SCL for address 0x5DThis setting is for the adafruit boards, some of the clone boards haved ifferent I2C address sets and defaults. You can use the I2C scanner in case you do not know the one for your board.

Connecting the boards is really simple, as shown in the drawing.

One thing do note - most of the breakout boards power supply is rated at 3.3V do not power it with the 5V. what about the data level voltage - well due to the nature of the i2c hardware you wont damage the MPR121 with the 5V of the arduino, but if you do notice issue reading from it, or not even finding it on the bus - try a logic level converter between the 2.

Over the years I made a few things with this great IC.On2 of the first things I created was a game for my kid, the letters on the top are connected to 2 MPR121 and each touch will trigger an mp3 record of me saying the letter name.

I also at the same time experimented with the bare conductive paint - it’s a lot of fun, and works great with the MPR121.


Code

Simple on/off led on pin 0/1Arduino
It show the option of turn on and off a led that is connected on pin 3.
Using the pin 0 touch of the mpr121 for on and the 1 on release for off.
#include <MPR121.h>
#include <Wire.h>

#define numElectrodes 2

#define LEDPIN 3

void setup()
{
  Serial.begin(115200);
  Serial.println("System started");
  pinMode(LEDPIN, OUTPUT);

  Wire.begin();

  // 0x5C is the MPR121 I2C address on the Bare Touch Board
  if (!MPR121.begin(0x5A)) {
    Serial.println("error setting up MPR121");
    switch (MPR121.getError()) {
      case NO_ERROR:
        Serial.println("no error");
        break;
      case ADDRESS_UNKNOWN:
        Serial.println("incorrect address");
        break;
      case READBACK_FAIL:
        Serial.println("readback failure");
        break;
      case OVERCURRENT_FLAG:
        Serial.println("overcurrent on REXT pin");
        break;
      case OUT_OF_RANGE:
        Serial.println("electrode out of range");
        break;
      case NOT_INITED:
        Serial.println("not initialised");
        break;
      default:
        Serial.println("unknown error");
        break;
    }
    while (1);
  }

  
  MPR121.setInterruptPin(4);
  MPR121.setTouchThreshold(40);
  MPR121.setReleaseThreshold(20);
  MPR121.updateTouchData();
}

void loop()
{
  if (MPR121.touchStatusChanged()) {
    MPR121.updateTouchData();
    for (int i = 0; i < numElectrodes; i++) {
      if (MPR121.isNewTouch(i)) {
        if (i == 0) {
          digitalWrite(LEDPIN, HIGH);
        }

      } else if (MPR121.isNewRelease(i)) {
        if (i == 1) {
          digitalWrite(LEDPIN, LOW);
        }
      }
    }
  }
}

Schematics

Schematics
Mpr121 bb rtoqw9ya0j

Comments

Similar projects you might like

Arduino - Use Reset Button Like a Push Button

by RoHa

  • 4,767 views
  • 0 comments
  • 13 respects

Touch Controlled Light Using Arduino

Project tutorial by Amal Mathew

  • 10,857 views
  • 5 comments
  • 14 respects

Turn LEDs On/Off via Remote Control

Project tutorial by ismystore

  • 9,135 views
  • 1 comment
  • 8 respects

You've Been Using a Button Wrong this Whole Time

Project tutorial by SMM2

  • 8,182 views
  • 1 comment
  • 6 respects

touch sensor

Project tutorial by tech guy

  • 20,730 views
  • 4 comments
  • 12 respects

What to Wear? Twitter Button

Project showcase by Arduino “having11” Guy

  • 2,981 views
  • 0 comments
  • 6 respects
Add projectSign up / Login