Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsThe ESP32-S2 has 14 capacitive touch pins. A finger near a pin (or anything conductive wired to it) changes the pin's capacitance, and the chip measures it. On the S2 the reading rises when touched (the original ESP32's falls). The sketch reads eight pins, compares them with untouched readings taken at start-up and plays a note on a buzzer.
Tick anything you already have and the total updates.
Espressif ESP32-S2-DevKitC-1
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB.
touch_piano.inoVerify & upload in Electrolarkconst int PADS[8] = {1, 2, 3, 4, 5, 6, 7, 8};
const int NOTES[8] = {262, 294, 330, 349, 392, 440, 494, 523}; // C D E F G A B C
const float TRIGGER = 1.10; // touched when 10% above the idle value
uint32_t idle[8];
void setup() {
Serial.begin(115200);
delay(500);
for (int i = 0; i < 8; i++) idle[i] = touchRead(PADS[i]);
}
void loop() {
int key = -1;
for (int i = 0; i < 8; i++) {
uint32_t v = touchRead(PADS[i]);
if (v > idle[i] * TRIGGER) { key = i; break; } // S2 values rise when touched
}
if (key >= 0) tone(17, NOTES[key]); else noTone(17);
delay(20);
}
Long wires pick up noise; keep them short or raise TRIGGER.
You touched the pads at start-up; reset with hands away.
That is an active buzzer; use a passive one or a small speaker with a transistor.
Yes, anything with some moisture conducts well enough.
Yes, the S2's native USB can act as a USB MIDI device with the right library.
Up to 14 touch pins on the S2.
4 parts: Espressif ESP32-S2-DevKitC-1-N8R2 Wi-Fi Development Board, Buzzer Module 3.3–5V, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 5 steps.
No. This page has the complete, tested code (touch_piano.ino).
About ₹1,243 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Capacitive touch sensing; Self-calibrating thresholds; Playing 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.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.