Esp 32 Foil Keyboard
This project turns an ESP32 microcontroller into a fully functional 8-key piano using nothing but jumper wires as keys. The ESP32 has built-in capacitive touch sensing on several of its GPIO pins, meaning it can detect the electrical capacitance of your finger touching a wire — no extra sensor modules needed. Each key is mapped to a musical note across a full C major octave (C4 to C5), and a passive buzzer module plays the corresponding tone when a key is touched.
This is a great beginner-to-intermediate electronics project that requires minimal hardware and teaches you about capacitive sensing, PWM-based tone generation, and GPIO pin behaviour on the ESP32.
Supplies
1x ESP32 development board (any standard ESP32 dev board with touch pins works)
1x Passive buzzer module (3-pin: S, VCC, GND)
8x Male-to-male jumper wires (for the touch keys)
3x Male-to-male jumper wires (for the buzzer module)
Arduino IDE with ESP32 board support installed
Aluminium foil strips or copper tape to make wider key pads
Cardboard to mount and arrange the keys
How Capacitive Touch Works
The ESP32 has 10 built-in capacitive touch pins. Each one continuously measures the capacitance on its GPIO pin. When your finger touches a wire connected to one of these pins, your body adds extra capacitance and the pin's reading drops. The code detects this drop and treats it as a key press.
This means you do not need any extra components for the keys — a bare jumper wire connected to a touch pin is enough to detect your finger.
The 8 pins used in this project and their corresponding notes are:
- GPIO4 → C4
- GPIO15 → D4
- GPIO13 → E4
- GPIO14 → F4
- GPIO27 → G4
- GPIO32 → A4
- GPIO33 → B4
- GPIO12 → C5
Important: GPIO12 is a boot strapping pin on the ESP32. Make sure nothing is touching the GPIO12 wire at the exact moment you power on or reset the board. Once the board has booted it works as a normal touch pin.
Wire the Touch Keys
Connect one jumper wire to each of the following GPIO pins the your ESP32 according to the the list mentioned before.
Leave the other end of each wire exposed — these are your piano keys. Arrange them in order from left to right so they go from the lowest note (C4) to the highest (C5).
To make the keys easier to play, wrap a small strip of aluminium foil around the exposed end of each wire. You can then stick them onto a piece of cardboard spaced evenly apart to create a proper keyboard layout.
No resistors or extra components are needed — the wires connect directly to the GPIO pins and nothing else.
Wire the Buzzer Module
The passive buzzer module has 3 pins. Connect them as follows:
- S (Signal) → GPIO25 on the ESP32
- Middle pin (VCC) → 3.3V on the ESP32
- − (GND) → GND on the ESP32
Passive vs Active buzzer: Make sure you are using a passive buzzer module. A passive buzzer accepts a PWM signal and can play different pitches, which is what allows it to play musical notes. An active buzzer only produces a single fixed beep tone regardless of what signal you send it and will not work for this project.
If you are unsure which type you have, upload a quick test that runs tone(25, 440) for one second. If you hear a clear musical pitch, it is passive and will work. If you just hear a generic beep that sounds the same no matter what frequency you set, it is active.
Test the Touch Pins
Before uploading the piano code, it is a good idea to confirm all 8 touch pins are working correctly on your specific board. Upload the sketch below and open the Serial Monitor at 115200 baud.
You will see a row of numbers updating every second, one for each pin. Here is what to look for:
- When you are not touching anything, all values should be roughly between 600 and 1000.
- When you touch a wire, that pin's value should drop noticeably — often below 300 or even into single digits.
- If a pin's value stays high when you touch it, check that the wire is pushed firmly into the GPIO pin.
- If a pin's value is constantly low even when nothing is touching it, try a shorter wire or move it away from the USB cable to reduce noise.
Once all 8 pins respond cleanly to touch you are ready for the final step.
Upload the Piano Code
Upload the full piano sketch below. Once it is running, touch each wire in order from left to right and you will hear a musical note for each one — a complete C major octave from C4 up to C5.
How it works:
- The code reads all 8 touch pins every 20 milliseconds.
- If any pin drops below 600 it is treated as a key press and the corresponding note plays on the buzzer.
- When you release the key and all pins go back above 600 the buzzer stops.
- Only one note plays at a time since the buzzer can only output one frequency — whichever key you press first takes priority.
If a key is misfiring (triggering without being touched) you can raise the threshold slightly below 600 to tighten the detection. If a key is not triggering when touched, lower it toward 500.
Video Demo