Thanks to the I2C bus, the Raspberry Pi can be equipped with a variety of practical sensors and actuators. The MPR121 offers a (in my opinion) very elegant way for user input.
The MPR121 is a controller that makes it possible to evaluate up to 12 touch electrodes. You can use it to set up up to 12 electrodes, which can then be used as buttons. Depending on the structure of the electrode, you can also detect these touches through thin materials or even just by approaching (without touching).
For example, I use this on my MagicMirror to be able to switch the screen on and off manually.
Everything you need to read the MPR121 via NodeRed and to react to keystrokes can be found in the following article.
Safety instructions
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
Affiliate links / advertising links
The links to online stores listed here are so-called affiliate links. If you click on such an affiliate link and store via this link, Nerdiy.de receives a commission from the online store or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Requirements
Helpful articles:
So that you can install new nodes, NodeRed should of course already be installed on your RaspberryPi.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.
- RaspberryPi - Setup for nerdiys!
- RaspberryPi - The first configuration!
- RaspberryPi - Control the RaspberryPi via SSH
- NodeRed - Installing NodeRed on the RaspberryPi
In the following lists you will find all the parts you need to implement this article.
Required tool:
Number | Link |
---|---|
1x | Screwdriver set Buy at Amazon |
1x | SD card reader Buy at Amazon |
Required material:
Connect MPR121 correctly
In order for your Raspberry Pi to be able to communicate with the MPR121, you must of course connect it correctly to the GPIOs of the Raspberry Pi.

To do this, you need to connect the MPR121 breakout board to the Raspberry Pi as shown.
RasPi | MPR121 |
---|---|
3.3V | 3.3V |
GND | GND |
GPIO2 | SDA |
GPIO3 | SCL |
Activate the I2C bus in the Raspberry Pi configuration.
In order to be able to use the I2C bus with the Raspberry Pi, it must first be activated. There are two ways to do this.
Activate the I2C bus of the Raspberry Pi via SSH

To activate the I2C bus via the SSH connection, you must establish a connection via SSH to your Raspberry Pi and then enter the following command.
sudo raspi-config

The menu shown then appears.
Use the arrow keys to navigate to the option
- Interface options
and confirm it with "Enter".
Activate the I2C bus of the Raspberry Pi via the graphical interface

To activate the I2C bus via the graphical user interface, you must first click on the Raspberry Pi icon in the upper left corner.
Log in to the NodeRed configuration interface
Before you can edit your NodeRed configuration you must - if activated - first log in to the NodeRed configuration interface.

Installation of the required nodes
In order for NodeRed to be able to communicate with your already connected MPR121, you must first install the node "node-red-contrib-mpr121". How you can install a node is in the article NodeRed - Install new nodes described.
Import Node Red code
In this section you will find the Node Red code you need. How you can import this into your NodeRed environment is described in the article NodeRed - importing and exporting node code.
In order to be able to use the node code linked below with your ESPEasy device, you have to make a few changes. These are described in the next section.
You can find the Node Red code in the Nerdiy Git repository under the following link:
The NodeCode below evaluates all 12 electrodes of the MRP121. In order for this to work, it must be connected to the Raspberry Pi via I2C. You also have to set the correct I2C address.
The currently measured value for each electrode is displayed on the dashboard. This value changes depending on the environment and also whether a finger (or something else) is nearby, which should trigger an action. So that an approach/touch can also be reliably detected, you can also set the threshold value for each electrode in the dashboard. just try it You really can't break anything. 🙂
When you release an electrode, a signal is sent to the associated link node, which you can use to carry out any switching action.


By clicking on the MPR121 node you can configure the address of your MPR121. This must match the address of the MPR121 configured on the hardware side.


Dashboard view
Here you can see the current measured value of each electrode and you can also set the threshold value for each electrode.
More articles related to the topic
In the following category you will find further links on the subject of Rasperry Pi and Node Red.
Have fun with the project
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate that I share this information with you, I would be happy about a small donation to the coffee box. 🙂