Sensing Capacitive Touch – MPR121 + Arduino

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.Sensing Capacitive Touch – MPR121 + Arduino

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.Schematic Sensing Capacitive Touch – MPR121 + Arduino

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


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top