Summary of Sensing Capacitive Touch – MPR121 + Arduino
This article introduces using the MPR121 capacitive touch sensor with an Arduino to create interactive projects without physical buttons. It explains the basic concept of capacitance, details the I2C wiring connections for various Arduino models, and discusses configuring electrodes and thresholds for reliable touch or proximity detection.
Parts used in the MPR121 Capacitive Touch Project:
- MPR121 capacitive touch sensor breakout board
- Arduino board (Uno, Nano, or Mega)
- SDA wire (Data line)
- SCL wire (Clock line)
- Digital pin 2 connection wire
- Metal tape electrodes
- Bare wire segments
Every now and then you get sick of the typical push buttons and you want something cooler. And what is cooler than touch sensitive things? Remember that old lamp in your Grandma’s that changed brightness just by touching the base? Yeah, that’s right… We are talking THAT cool! The MPR121 capitative touch sensor gives you 12 of such inputs that we can use with our Arduino, and you can get it in several forms from SparkFun – Im using the basic breakout board.
How? Well… Capacitive sensing is pretty simple in concept. Every object has capacitance, (in laymen’s terms capacitance is just an objects ability to hold a charge), and when you come in contact with something you change its capacitance. Well the MPR121 just looks for these changes, and tells us when it happens.
Hooking It Up
Hooking it up to your Arduino is pretty simple, the MPR121 is an I2C device. I2C is a 2-wire serial connection, so you just need to connect the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the mega) SDA is on analog pin 4, and SCL is on analog pin 5. On an Arduino Mega, SDA is digital 20, and SCL is digital 21.
When the MPR121 senses a change, it pulls an interrupt pin LOW. Now if we were ninja’s we would use this oppertunity to create an interrupt on our Arduino and deal with changed immediately. However, to simplify things for us non-ninjas, we are just going to check that pin to see if it is LOW during our loop. To do this, this sensor also needs access to another digital pin, and in this case we are using digital 2.
Electrodes
This is a touch sensor, so we need something to touch right? We call these electrodes. Typically, electrodes can just be some piece of metal, or a wire, or my favorite, metal tape (just make sure you have at least 1/2in of bare wire in contact with the sticky part of the tape for good contact). But some times depending on the length of our wire, or the material the electrode is on, it can make triggering the sensor difficult. For this reason, the MPR121 allows you to configure what is needed to trigger and untrigger an electrode. So if you are getting false or no positives, you may need to change that.
Proximity Sensing
There is a small change in capacitance even as you approach an electrode, just through the air. So if you set the touch threshold, or release threshold too low you may notice it trigger even a few inches away. If you want it to trigger from a decent distance away, the MPR121 supports aggregating all of the electrodes together to use it as a single large proximity sensor – But you will need to read the doc sheet to figure that one out, sorry.
For more detail: Sensing Capacitive Touch – MPR121 + Arduino
- What is the main function of the MPR121 sensor?
The MPR121 provides 12 capacitive touch inputs that detect changes in capacitance when a person touches an electrode. - How do you connect the MPR121 to an Arduino Uno?
Connect the SDA line to analog pin 4 and the SCL line to analog pin 5 on the Arduino. - Which pins are used for I2C communication on an Arduino Mega?
On an Arduino Mega, use digital pin 20 for SDA and digital pin 21 for SCL. - How does the MPR121 signal a touch event to the Arduino?
When a change is sensed, the MPR121 pulls an interrupt pin LOW, which the Arduino checks during its loop. - What materials can be used as electrodes for this project?
Electrodes can be made from pieces of metal, wires, or metal tape with at least 1/2 inch of bare wire contact. - Can the MPR121 detect objects without direct contact?
Yes, small capacitance changes occur as you approach an electrode, allowing for proximity sensing if configured correctly. - What should you do if the sensor triggers false positives or no responses?
You may need to reconfigure the touch threshold or release threshold settings in the MPR121. - Is it possible to use all electrodes together for one large sensor?
Yes, the MPR121 supports aggregating all electrodes to act as a single large proximity sensor.