Introduction: Arduino Touch Capacitive MIDI Keyboard

NOTE: I have released a new Instructable on an improved version of this project. It is now capable of handling 12 keys multi-touch input, as well as the option to change from octave. The Instructable can be found here:


This Instructable will show you how to make a touch capacitive MIDI keyboard. If you follow all of the steps correctly, it will work something like this:

Video note: This will not work with normal paint. For this video I used Conductive paint.

What you will need:

- Arduino Uno R3 (this guide is only for a R3, I'm not sure if it will work on other models)
- 12 resistors (somewhere from 1M to 10M Ohm)
- jumper wires
- 11 alligator clips
- some conductive material (electric paint, aluminium foil etc.)
- a software program that can handle MIDI
- touchcapacitive library
- the code & a software file (are provided)

Step 1: Calibrating Touch Sensitivety

firstly, we need to determinate the sensitivety of our resistors. To do this, you will need to download the CapacitiveSensor library and install it into your Arduino folder. Then copy this sketch and upload it to your Arduino.

After you finished uploading the code and building the Arduino, open the serial monitor inside your ADE. If done correctly, you will see a row of values. If you're touching the end of the wire, the send-back value should be higher compared to the value when not touching the wire.

Now it's time to determinate at which value your Touch sensor should 'send' out a midi note. If you're reading a value of 50 when your not touching the wire and a value of 1000 when your touching the wire, you should keep the number around 700 in your head. When you've finished building the touch capacitive keyboard, it will sent out a midi note when the value is over 700.

Now it's time to start working on the actual keyboard..

Step 2: Uploading the Code

It's time to upload the code to your Arduino.

Remenber that value you needed to store in your mind? You need to put that value in the code. Everywhere in the code where stands a 500, you need to change in to your value.

static int lastInput1 = 0;

int newInput1 = total1;

if((lastInput1 < 500) && (newInput1 > 500)) {

for (int note=48;note<49;note++) {//from note 50 (D3) to note 69 (A4)

MIDImessage(noteON, note, ON); }};//turn note on

if((lastInput1 > 500) && (newInput1 < 500)) {

for (int note=48;note<49;note++) {//from note 50 (D3) to note 69 (A4)

MIDImessage(noteON, note, OFF); }};

lastInput1 = newInput1;

After you changed the value the code is ready to be uploaded.

Step 3: Changing the Arduino Software

Now it's time to change the default UNO-dfu_and_usbserial_combined software on your arduino to a MIDI software.

first download the hex file and the FLIP program to upload the hex file to your Arduino.

When you downloaded the file and FLIP, connect your Arduino to your computer. Now it's time to put your Arduino Uno R3 (this will only work on a Uno!) into DFU mode.

Put one wire into the Ground at the top and one to the Ground on the bottom. You need to touch the bottom wire to GND showed on the photo and the top wire to RESET on the photo at the same time. Your Arduino should be into DFU mode now.

Then it's time to upload the MocoLUFA hex file. Open FLIP, select your chip (16u), locate your MIDI.hex file and upload it via USB. Disconnect your USB cable from the computer and connect it again. The Arduino should come up as a MIDI/MocoLUFA device.

remember: When you need to change your ADE code, you need to put Arduino original hex file back. It can be found under C:\Program Files (x86)\Arduino\hardware\arduino\firmwares\atmegaxxu2

Step 4: Building the Circuit

build the circuit as in the pictures.

The end of the wires is where you would touch it. You can attach alligator clips to the ends of the wire so you can clip the wires to alliminium foil for example.

Step 5: Finishing the Midi Keyboard

your Touch capacitive keyboard should be finished by now. It can detect when you're holding a wire and send out a midi note. But we need also a program that can read MIDI and can produce sounds. I would suggest you use a DAW (Fl Studio, Ableton, Logic Pro etc.)

If your Touch capacitive keyboard is working as it should be, it will appear as a normal MIDI device in your DAW as shown. It will work like any normal MIDI keyboard, except that it can only play one note at the time! 

enjoy it!



licheong made it!(author)2016-07-10

Hey, your new code doesn't work. It only detect the sensor values in void setup(). To keep it detecting, that should be put in the loop() void.
And I think it's better to use 0 to 11 for the arrays instead of 1 to 12 ,as arrays always start at 0. And your keyboard is supposed to start at middle C, which has the MIDI number 60. If you start the for loop from 1, what you'll get by (60+i) is 61, that means it would be transposed to C#. A great example by the way. Hope it helps!

DonCesare made it!(author)2016-06-20

Great instructable, love it. If I needed more free pins from the arduino, could I use a shift register or any other IC? Like a 74hc454 or any other?
Thank you so much!

DonCesare made it!(author)2016-06-20

sorry i meant 74hc595

RobertK125 made it!(author)2016-03-10

and what notes does each input trigger?

garrettbrown made it!(author)2016-04-08

I'm not the author of this but I would assume that you can set that up in your DAW.

satvirp made it!(author)2016-03-30

ok thanks a lot

satvirp made it!(author)2016-03-30

Hi, i found an application call "LoopMIDI" to create a virtual COM port and another application called "Hairless MIDI Serial" to convert Serial input to MIDI, output to serial or input to serial or both. Will this work with your project and code or will i have to change the code. If it would work but you have to change the code, please could you write a code for this.

Bas+van+Straaten made it!(author)2016-03-30

I think it should work, however, due to my busy schedule at the moment, you should try it on your own.

satvirp made it!(author)2016-03-29

How would you revert arduino to default if you are not using the dualMocoLUFA software

satvirp made it!(author)2016-03-27

I would like to know one thing, if you update your arduino to the MIDI software is it possible to reset it to default.

Bas+van+Straaten made it!(author)2016-03-27

Hello, it is always possible to revert the software on your Arduino. However, I would advise you to download the dualMocoLUFA software, since this allows you to use your Arduino as a midi device and in normal mode by simply applying and removing a jumper wire. Good luck!

RobertK125 made it!(author)2016-03-10

this instructable is f@^&$#

RobertK125 made it!(author)2016-03-10

i used the updated sensor calibration sketch because the old one didnt work with my mega. i can upload the firmware and see it as a midi device but cannot see any midi output. is there a way i can check its outputting midi before i chage the firmware.

rachaelgladwin made it!(author)2015-12-02


I'd like to know how you would go about implementing an octave shift up and down buttons or semitone shift? I only need 8 keys which I have implemented already.

Any help would be great!

Thanks for the great tutorial! :)

rachaelgladwin made it!(author)2015-12-02

Note* I only need the 8 keys to play and that would leave 2 keys for the octave shift buttons :)

Bas+van+Straaten made it!(author)2015-12-09

You can modify the code a little bit, from:

sendMidi(0x90, 60 + i, 127);


sendMidi(0x90, 60 + i + octave * 12, 127);

where the variable octave will change when you press a button.

laserr made it!(author)2015-12-08

Great tutorial! I am a total Arduino newbie. I got the code working well. I would like to add MIDI CC1 (modulation wheel) by reading a potentiometer with an analog input. Can you or anyone else help?

Bas+van+Straaten made it!(author)2015-12-09

shouldn't be too difficult..

You need to read the value of the potentiometer and write it to the computer like this: Serial.Write(0xB0, controllerNumber, value/8);

yzerbeat made it!(author)2015-04-11

I love this project ! great work !!

i have a lil problem, i have a delay of a couple off seconds when i touch my wires.

The midi notes go on, but they have a big delay.

Does anyone have this problem or knows what i could be doing wrong ?
Thx in advance !!

sacchetta made it!(author)2015-09-13

This sounds like a latency issue. Are you using an A/D converter or dedicated audio card (a higher end one geared towards audio engineers). If you aren't then it's probably just your computer slowly processing the sound as it comes in.

makeosaurus made it!(author)2015-07-07

I have just got an arduino and was wondering how easy it is to restore the normal mode on the arduino once you are done as I dont want to wreck it!

makeosaurus made it!(author)2015-07-07

what is the DAW you are using??

VirgileD made it!(author)2015-05-21

Great project ! ! I'll try to see if that works for me.

But I've a question, do you think that we can remplace the electric paint or aluminium by piezo disk, or that mean that we have to change the code ? (I'm a brand new beginner in arduino)

minisac made it!(author)2015-04-25

I have just tested your updated code. It works perfectly. Thank you very much ! I added some buttons and a pot to play with pitch and velocity :) I'm now looking for a solution to play several notes in a same time. Does anybody know a way to do this ?

Bas+van+Straaten made it!(author)2015-04-25

good to hear! Unfortunately, I don't think it's possible to play more notes at a time!

minisac made it!(author)2015-04-27

Thanks for the answer. And do you think there is a way to cut the bass while mixing with a pot like an audio control surface ?

tareq.sultan1 made it!(author)2014-10-15

can any help with my error

'CapacitiveSensor' does not name a type

Andross.Montgomery made it!(author)2015-04-01

hey man, im having the same problem. How did you fix this?

Bas+van+Straaten made it!(author)2014-10-17

Did you instal the CapacitiveSensor library?

TommyT1 made it!(author)2015-02-28

does this project also include velocity for each key?

Bas+van+Straaten made it!(author)2015-02-28

No, the velocity for all notes is fixed. But use your imaginotion and program it yourself, because it is possible!

banyubening made it!(author)2014-12-22

hi... I need help, I make this project for a task,

initially went well, but now that I hold each cable has a lot of output in FL, and notes can not return

mwahyudinwachid made it!(author)2014-11-17

Hi, Creator.

It is interest. I need help.

Can you share the tutorial of FL Studio?


gutinho made it!(author)2014-05-08

Hi there! Nice work!! :)

I'm trying to build one my own, but the code, on arduino, it's getting an error " 'total1' was not declared in this scope"

Can you help me?

vanakaru made it!(author)2014-05-09

The code posted here is only a part of the whole. I do not know why he did not put the whole thing here.

I had some confusion before I realized what is missing.

#include <CapacitiveSensor.h>

CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3);
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);

int velocity = 100;//velocity of MIDI notes, must be between 0 and 127
//(higher velocity usually makes MIDI instruments louder)

int noteON = 144;//144 = 10010000 in binary, note on command

void setup() {
// Set MIDI baud rate:


void loop() {

long total1 = cs_2_3.capacitiveSensor(30);
long total2 = cs_2_4.capacitiveSensor(30);

if (total1 > 500) {

for (int note=48;note<49;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
MIDImessage(noteON, note, 0);}}//turn note off

if (total2 > 500) {
for (int note=49;note<50;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(500);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off

//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
look here too

gutinho made it!(author)2014-05-09

Oh thank you very much, Vanakaru!! :)

Bas+van+Straaten made it!(author)2014-10-17

yeah sorry, I just noticed the link to the actual code was gone. It's reuploaded now.

assemblyworker made it!(author)2014-07-03

Thanks for the tutorial, I have things up and running, one question. How can I create a loop where the sound stays triggered whilst I press the trigger and releases when I take my finger off? At the moment if I hold my finger down then the trigger will replay rapidly.


thegoodhen made it!(author)2014-05-31

Here is a tip: use #define something value, for instance #define cal 500 and then use cal instead of 500 in the code

Then you will just change the define on top of your file and it will change it everywhere.

nfrucot made it!(author)2014-03-24

Hi, brilliant instructable. i'm wondering if there is a way to send multiple midi notes/cc with a setup like that ?

Bas+van+Straaten made it!(author)2014-03-24

I don't know, should be possible, but I haven't figured it out. Maybe I'll try it in the future.

About This Instructable



Bio: Design student, wantrepeneur, lifelong learner. Oh, also running a small 3D printing business.
More by Bas van Straaten:How to Make a Cheap Arduino MIDI ControllerArduino DFU-programmer on Mac OSArduino Touch Capacitive MIDI Keyboard
Add instructable to: