Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsEach electrode on the MPR121 is a touch key. Connect wires to foil pads or to bananas and playing them makes notes on the piezo. A classic way to learn about capacitive touch.
Every main part of this project is an item on the public Package 1 equipment list, so a school lab that already owns Package 1 can build it without buying anything extra.
See the full Atal Tinkering Lab packages →
Geekobot is an independent shop, not endorsed by or affiliated with NITI Aayog or the Atal Innovation Mission. Item names follow the public AIM equipment list.
Tick anything you already have and the total updates.
Connects the Uno to your computer to upload code and power it
Twelve touch inputs on one I2C chip: connect foil pads, fruit or wires and each becomes a touch key.
Follow the colours: red is power, dark grey is ground, blue is a signal.
atl_touch_piano.inoVerify & upload in Electrolark// Touch piano with the MPR121
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "atl-touch-piano"
#include <Wire.h>
#include <Adafruit_MPR121.h>
// ---- pins ----
const uint8_t PIEZO_PIN = 2;
Adafruit_MPR121 cap = Adafruit_MPR121();
// ---- latest readings ----
int touchMask = 0;
// notes for electrodes 0-7: C4 D4 E4 F4 G4 A4 B4 C5
const int NOTES[8] = {262, 294, 330, 349, 392, 440, 494, 523};
uint16_t lastTouched = 0;
void setup() {
Serial.begin(115200);
if (!cap.begin(0x5A)) { Serial.println(F("MPR121 not found: check the wiring")); while (1) delay(10); }
}
void loop() {
uint16_t t = cap.touched();
if (t != lastTouched) {
lastTouched = t;
noTone(PIEZO_PIN);
for (uint8_t i = 0; i < 8; i++) {
if (t & (1 << i)) {
tone(PIEZO_PIN, NOTES[i]);
Serial.print(F("note ")); Serial.println(NOTES[i]);
break;
}
}
}
delay(10);
}
Check SDA and SCL, 3.3 V power, and that the I2C address is 0x5A (ADDR pin not connected).
Normal for a bare piezo; mount it on a small box to resonate.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider.
Use a 5 V USB phone charger or a power bank into the board's USB port.
6 parts: Uno R3 CH340G ATmega328p Compatible Development Board, Arduino USB-A to USB-B Data Cable for UNO/MEGA, MPR121 12-Channel Capacitive Touch Sensor Module, I2C, Piezo Buzzer (passive), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 8 steps.
No. This page has the complete, tested code (atl_touch_piano.ino). Install this library first: Adafruit MPR121.
About ₹458 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Capacitive touch and I2C; Generating musical notes with tone().
Clap twice and the lights come on. Clap twice again to switch them off.
Plays a friendly ding-dong whenever someone walks into the shop or room.
Beeps and flashes any message in Morse, or key your own by hand.
Turn a membrane keypad into a two-octave piano.
Learning project. Check every circuit and the datasheet of each part before you power it up.