loading
Using only an Arduino, a few resistors, a buzzer, and some bits of aluminum foil, you can create your own touch-sensor piano keyboard in just a few minutes! Using an Arduino Uno, you can create a piano with up to 18 keys; or with an Arduino Mega, you can get over 60 keys! Other Arduino boards should work with this project with little to no modification to the code.

 

Step 1: Parts and Material

You'll first want to collect all of the parts you will need for the project:

• An Arduino (or Arduino-compatible) microcontroller board.
    • Any Arduino board should work: Uno, Leonardo, Mega, Pro Mini, etc.
• Eight 2.2 Megaohm (2.2 MΩ) resistors
    • Anywhere between 1 MΩ and 4.7 MΩ should work
    • You need one resistor per piano key
    • A 2.2 MΩ resistor has a color code of Red-Red-Green or Red-Red-Black-Yellow
• A piezo buzzer
• Some spare wires or jumper cables
• Aluminum foil
    • A foot or two should do
• Tape
• A surface to tape your keys to
    • We used a scrap piece of cardboard, but it can be anything you like, even the tabletop itself!

Equipment that you may need:

• Soldering iron and solder
    • You can probably get by without an iron by wrapping wires together instead of soldering, but the connection will not be as reliable
• Scissors to cut aluminum foil and tape

Advertisement

<p>Hi there,</p><p>I made this the other day but I used a breadboard instead of directly wiring the pieces to each other. I thought I should upload a diagram of the wiring I used just in case anybody else wants to make this using a breadboard. I also made some adjustments in the code to work for the amount and size of keys I had (about 1&quot; wide by 2&quot; long), including mrizkalla's adjustments to stop the loop effect. I've uploaded it to my Google Drive and it can be found by clicking here: https://drive.google.com/folderview?id=0B53IAtyS3-7NbF9jTmFMd1U4eU0&amp;usp=sharing</p>
<p>Wonderful, thanks, Megan! I would love to see some pictures of the project!</p>
<p>Hi Tyler,</p><p>Here are some pics from when I did the project and a video of me playing Ode To Joy on it... worked pretty well!</p><p>Thanks for the comment!</p>
<p>Where can I see the video of this working circuit . I am having a little problem. Cant hear the change in notes.??</p>
<p>That's awesome! Thanks!</p>
<p>i had a bunch of students make this as a crash course in soldering and programming, it was a hit. </p>
Please tell me how you connected the buzzer.<br>I made the same as you did but the buzzer is continuously making sound.<br>
<p>Our project almost worked! But, the buzzer won't stop playing until next key is pressed or unplugging Arduino. We tried to add a ELSE statement, to add delay, to remove for loop but none of these methods worked. Do you have any advice? We assemble circuits exactly like yours and used your code. </p>
<p>You must add the time 250 in line &quot; </p><p>tone(BUZZER_PIN, notes[i], 250); // Plays the note corresponding to the key pressed</p><p>&quot;</p>
<p>Tyler, i have the same problem, please tell us how to repair it</p>
<p>It works well, it was easy an funny.</p>
<p>IT SHOWS FOLLOWING ERROR MESSAGE WHENEVER I UPLOAD IT...PLZZ HELP</p><p>Arduino: 1.6.8 (Windows 7), Board: &quot;Arduino/Genuino Uno&quot;</p><p>C:\Users\Admin\AppData\Local\Temp\Rar$DIa0.942\CapSensePiano\CapSensePiano.ino:14:30: fatal error: CapacitiveSensor.h: No such file or directory</p><p> #include &lt;CapacitiveSensor.h&gt;</p><p> ^</p><p>compilation terminated.</p><p>exit status 1</p><p>Error compiling for board Arduino/Genuino Uno.</p><p>This report would have more information with</p><p>&quot;Show verbose output during compilation&quot;</p><p>option enabled in File -&gt; Preferences.</p>
<p>I need some help.<br><br>1. My keyboard is playing only 1 note. I cant make out the difference.</p><p>2. How can I print the capacitance reading onto serial monitor so I know what values the arduino is picking and calculating.<br><br>3. What do the Number of samples mean.<br><br>I am using only 5 keys. </p>
<p>Im having a problem with the library for this project it keeps telling me that the &quot;author&quot; is missing inside the library i have gone to the location of the problem but i still don't know whats wrong i have also tried to add the author myself but it wont accept it i need help can anyone answer my question?</p>
<p>Hey! This is my first project on the arduino and i know nothing about coding, when i try to upload the sketch there is an error. i have the library downloaded. This is the error code:</p><p> Arduino: 1.6.6 (Windows 10), Board: &quot;Arduino/Genuino Uno&quot;</p><p>C:\Users\Tardis2\AppData\Local\Temp\arduino_a6247a94239e09e2459cc5b5f1317b51\CapSensePiano.ino:17:21: fatal error: pitches.h: No such file or directory</p><p> #include &quot;pitches.h&quot;</p><p> ^</p><p>compilation terminated.</p><p>exit status 1</p><p>Error compiling.</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p>
Hi!<br>When you are installing the code u have to (in the beginning)press and hold down the reset button until u see the less blinking on the arduino.<br>I hope that helped ;)
can any other sheet can be replaced for aluminium foil
<p>برنامه درست شد </p>
<p> ؟برنامه خطا می دهد . چه کار کنم </p>
<p>It's wrong that you can only get 18 on an Arduino Uno or 60 on Mega, because you can use shift registers like 74HC595. This one take 3 pins and give 8, but there is an instructable for giving 16 of 3 pins (http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595)</p>
<p>Unfortunately, using a shift register to expand the pin count won't work here, since this project requires inputs rather than outputs. That &quot;Multiplexing with Arduino&quot; Instructable is focused on supporting an array of LEDs, rather than buttons.</p><p>It might be possible to do a similar &quot;scanning&quot; process for the piano that normal button matrices use, but that is another, more complicated project.</p>
<p>OK, that's true, they're inputs, but there also are shift registers for inputs. Take by example the CD4021B. What about this?</p>
<p>when I tried to upload the code, it said :</p><p>avrdude: stk500_getsync(): not in sync: resp=0x00</p><p>can someone help?</p>
<p>Try a different port like if it is COM1 then try COM3 or any other port</p>
<p>I made Arduino Piano with 4 Keys....may be I have used 1 m ohm resistor that would have caused it not to play good, but results are encouraging.</p><p>Need to know how I can change the length of note to be played in program ?</p><p>It would be great help :)</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/io_Yb5gZYlo" width="500"></iframe></p>
<p>Awesome make! You can make the tones only play for a certain length of time by adding a timeout to the tone() function. For example, change this:</p><p> tone(BUZZER_PIN, notes[i]);</p><p>to this:</p><p> tone(BUZZER_PIN, notes[i], 500);</p><p>That will make the tone play for half a second (500 milliseconds) before cutting off.</p><p>Hope that helps!</p>
<p>Great, thanks mate !!!</p>
<p>Hi! I have no idea why the note D4 can't be played properly when I touch it. It played a weird sound. The note B4 also cant' be played at all. Any idea how to fix this?</p><p>Thanks!</p>
<p>I'm new to programming, so I have a question regarding the code. If I plan on using momentary switches for the keys instead of aluminum foil, would you happen to know how the code should change for this? I feel like it might be simpler, because I don't think I would need the capacitive sensor with a switch like that. I don't really know hahaha Please help if you can! :-)</p>
<p>This is my first arduino project. Turned out great. I followed megantissington's breadboard diagram and used the code that she uploaded to google drive. The only change I made was adding C5 to complete the octave. </p><p>Here's a video:</p><p>https://www.youtube.com/watch?v=iNsObVeigsw</p>
<p>Has anyone tried dripping water on the touchpads. Do they respond the same to water as the do to a finger?</p>
<p>Hi there,</p><p>Thank you for this beautiful update.</p><p>I made this up with little modification. Instead of buzzer I used LEDs, Means when I press a key corresponding LED glows. </p><p>I have set CAP_THRESHOLD to correct value by try-n-error method. </p><p>But I came across one strange issue.</p><p>1. When I connect Arduino UNO only to PC with USB cable it works absolutely fine.</p><p>2. When i connect both USB and POWER cable(12v, 1A) to Arduino, these LED keep blinking when I pressthe keys.</p><p>3. After programming the Arduino, I disconnect the USB cable , and connect the POWER cable, these does not works. While pressed keys, sometime LED blinks.</p><p>Now I am not getting any clue about this :( . Please update if you know any possible reason for this.</p><p>I will be updating my project details and PIC soon.</p><p>Thanks</p><p>Souvik</p>
<p><a href="https://learn.sparkfun.com/tutorials/installing-an-arduino-library" rel="nofollow">https://learn.sparkfun.com/tutorials/installing-an...</a></p><p>Try this tutorial for installing the libraries. It is much more clear than the arduino site explanation and code worked immediately after installing the libraries properly.</p><p>john</p>
<p>Hi Tyler,</p><p>I hate to bother you with this especially because you have addressed it so many times before. I am getting the following errors each time I try to compile the library and or sketches.</p><p>I have followed the arduino tutorial and tried following the instructions here, but to no avail. Can you help me get this code loaded and working? I am planning to teach this to my grandson as soon as I can get it working right. I absolutely love your projects and the fact that you are helping so many people is just amazingly generous and kind. I would greatly appreciate it if you could kind of walk me through the process and get this working.</p><p>Thank you,</p><p>John</p><p>sketch_nov14a:32: error: 'CapacitiveSensor' does not name a type </p><p>sketch_nov14a.ino: In function 'void setup()': <br>sketch_nov14a:39: error: 'keys' was not declared in this scope <br>sketch_nov14a.ino: In function 'void loop()': <br>sketch_nov14a:50: error: 'keys' was not declared in this scope </p>
<p>Hi, just a quick question. When i press a key, the sound plays perfectly fine, and does what it is supposed to do. However whenever i let go of the key, it keeps playing the same note even though i am not touching the key. Is this supposed to happen? If it isn't, how would i fix this? </p>
The code doesn't work. I have installed the library correctly (I think, because it shows on my libraries when the arduino program is opened) and I cannot get the code to verify without this error : <br>CapSensePiano:32: error: 'CapacitiveSensor' does not name a type <br>CapSensePiano.ino: In function 'void setup()': <br>CapSensePiano:37: error: 'keys' was not declared in this scope <br>CapSensePiano.ino: In function 'void loop()': <br>CapSensePiano:47: error: 'keys' was not declared in this scope <br> <br>I really suck with code. That's why I use this site to make cool things without a lot of coding. Can you help me out?
Hello! Which Arduino are you using? It looks like there is a separate version of the library for the Arduino Due (which is included in the library .zip file). <br><br>Does the sample &quot;CapacitiveSensorSketch&quot; Arduino code that came with the library verify correctly for you? If not, then there may be something wrong with the way the library is set up on your computer.
i am using arduino uno but am experiencing the same problem as omadison<br> 12
<p>Hi! Sorry for the delayed response; do you have the Capacitive Sense Arduino library properly installed? Make sure that this library is installed before trying to run the sketch.</p>
<p>sorry i want to ask you</p><p>both program and Material are right but when i tough tHe Aluminum foil </p><p>it don`t have sound<br>this is the program<br>/*</p><p>Capacitive-Touch Arduino Keyboard Piano</p><p>Plays piano tones through a buzzer when the user taps touch-sensitive piano &quot;keys&quot;</p><p>Created 18 May 2013</p><p>Modified 23 May 2013</p><p>by Tyler Crumpton and Nicholas Jones</p><p>This code is released to the public domain. For information about the circuit,</p><p>visit the Instructable tutorial at <a href="http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/" rel="nofollow">http://www.instructables.com/id/Capacitive-Touch-...</a></p><p>*/</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &quot;pitches.h&quot;</p><p>#define COMMON_PIN 2 // The common 'send' pin for all keys</p><p>#define BUZZER_PIN A4 // The output pin for the piezo buzzer</p><p>#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings</p><p>#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)</p><p>#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard</p><p>// This macro creates a capacitance &quot;key&quot; sensor object for each key on the piano keyboard:</p><p>#define CS(Y) CapacitiveSensor(2, Y)</p><p>// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:</p><p>int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale</p><p>//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale</p><p>//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale</p><p>// Defines the pins that the keys are connected to:</p><p>CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};</p><p>void setup() {</p><p>// Turn off autocalibrate on all channels:</p><p>for(int i=0; i&lt;8; ++i) {</p><p>keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);</p><p>}</p><p>// Set the buzzer as an output:</p><p>pinMode(BUZZER_PIN, OUTPUT);</p><p>}</p><p>void loop() {</p><p>// Loop through each key:</p><p>for (int i = 0; i &lt; 8; ++i) {</p><p>// If the capacitance reading is greater than the threshold, play a note:</p><p>if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) &gt; CAP_THRESHOLD) {</p><p>tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed</p><p>}</p><p>}</p><p>}</p>
<p>sorry i want to ask you</p><p>both program and Material are right but when i tough tHe Aluminum foil </p><p>it don`t have sound<br>this is the program<br>/*</p><p>Capacitive-Touch Arduino Keyboard Piano</p><p>Plays piano tones through a buzzer when the user taps touch-sensitive piano &quot;keys&quot;</p><p>Created 18 May 2013</p><p>Modified 23 May 2013</p><p>by Tyler Crumpton and Nicholas Jones</p><p>This code is released to the public domain. For information about the circuit,</p><p>visit the Instructable tutorial at <a href="http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/" rel="nofollow">http://www.instructables.com/id/Capacitive-Touch-...</a></p><p>*/</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &quot;pitches.h&quot;</p><p>#define COMMON_PIN 2 // The common 'send' pin for all keys</p><p>#define BUZZER_PIN A4 // The output pin for the piezo buzzer</p><p>#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings</p><p>#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)</p><p>#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard</p><p>// This macro creates a capacitance &quot;key&quot; sensor object for each key on the piano keyboard:</p><p>#define CS(Y) CapacitiveSensor(2, Y)</p><p>// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:</p><p>int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale</p><p>//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale</p><p>//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale</p><p>// Defines the pins that the keys are connected to:</p><p>CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};</p><p>void setup() {</p><p>// Turn off autocalibrate on all channels:</p><p>for(int i=0; i&lt;8; ++i) {</p><p>keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);</p><p>}</p><p>// Set the buzzer as an output:</p><p>pinMode(BUZZER_PIN, OUTPUT);</p><p>}</p><p>void loop() {</p><p>// Loop through each key:</p><p>for (int i = 0; i &lt; 8; ++i) {</p><p>// If the capacitance reading is greater than the threshold, play a note:</p><p>if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) &gt; CAP_THRESHOLD) {</p><p>tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed</p><p>}</p><p>}</p><p>}</p>
<p>sorry i want to ask you</p><p>both program and Material are right but when i tough tHe Aluminum foil </p><p>it don`t have sound<br>this is the program<br>/*</p><p>Capacitive-Touch Arduino Keyboard Piano</p><p>Plays piano tones through a buzzer when the user taps touch-sensitive piano &quot;keys&quot;</p><p>Created 18 May 2013</p><p>Modified 23 May 2013</p><p>by Tyler Crumpton and Nicholas Jones</p><p>This code is released to the public domain. For information about the circuit,</p><p>visit the Instructable tutorial at <a href="http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/" rel="nofollow">http://www.instructables.com/id/Capacitive-Touch-...</a></p><p>*/</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &quot;pitches.h&quot;</p><p>#define COMMON_PIN 2 // The common 'send' pin for all keys</p><p>#define BUZZER_PIN A4 // The output pin for the piezo buzzer</p><p>#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings</p><p>#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)</p><p>#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard</p><p>// This macro creates a capacitance &quot;key&quot; sensor object for each key on the piano keyboard:</p><p>#define CS(Y) CapacitiveSensor(2, Y)</p><p>// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:</p><p>int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale</p><p>//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale</p><p>//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale</p><p>// Defines the pins that the keys are connected to:</p><p>CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};</p><p>void setup() {</p><p>// Turn off autocalibrate on all channels:</p><p>for(int i=0; i&lt;8; ++i) {</p><p>keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);</p><p>}</p><p>// Set the buzzer as an output:</p><p>pinMode(BUZZER_PIN, OUTPUT);</p><p>}</p><p>void loop() {</p><p>// Loop through each key:</p><p>for (int i = 0; i &lt; 8; ++i) {</p><p>// If the capacitance reading is greater than the threshold, play a note:</p><p>if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) &gt; CAP_THRESHOLD) {</p><p>tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed</p><p>}</p><p>}</p><p>}</p>
<p>sorry i want to ask you</p><p>both program and Material are right but when i tough tHe Aluminum foil </p><p>it don`t have sound<br>this is the program<br>/*</p><p>Capacitive-Touch Arduino Keyboard Piano</p><p>Plays piano tones through a buzzer when the user taps touch-sensitive piano &quot;keys&quot;</p><p>Created 18 May 2013</p><p>Modified 23 May 2013</p><p>by Tyler Crumpton and Nicholas Jones</p><p>This code is released to the public domain. For information about the circuit,</p><p>visit the Instructable tutorial at <a href="http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/" rel="nofollow">http://www.instructables.com/id/Capacitive-Touch-...</a></p><p>*/</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &quot;pitches.h&quot;</p><p>#define COMMON_PIN 2 // The common 'send' pin for all keys</p><p>#define BUZZER_PIN A4 // The output pin for the piezo buzzer</p><p>#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings</p><p>#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)</p><p>#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard</p><p>// This macro creates a capacitance &quot;key&quot; sensor object for each key on the piano keyboard:</p><p>#define CS(Y) CapacitiveSensor(2, Y)</p><p>// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:</p><p>int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale</p><p>//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale</p><p>//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale</p><p>// Defines the pins that the keys are connected to:</p><p>CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};</p><p>void setup() {</p><p>// Turn off autocalibrate on all channels:</p><p>for(int i=0; i&lt;8; ++i) {</p><p>keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);</p><p>}</p><p>// Set the buzzer as an output:</p><p>pinMode(BUZZER_PIN, OUTPUT);</p><p>}</p><p>void loop() {</p><p>// Loop through each key:</p><p>for (int i = 0; i &lt; 8; ++i) {</p><p>// If the capacitance reading is greater than the threshold, play a note:</p><p>if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) &gt; CAP_THRESHOLD) {</p><p>tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed</p><p>}</p><p>}</p><p>}</p>
<p>sorry i want to ask you</p><p>both program and Material are right but when i tough tHe Aluminum foil </p><p>it don`t have sound<br>this is the program<br>/*</p><p>Capacitive-Touch Arduino Keyboard Piano</p><p>Plays piano tones through a buzzer when the user taps touch-sensitive piano &quot;keys&quot;</p><p>Created 18 May 2013</p><p>Modified 23 May 2013</p><p>by Tyler Crumpton and Nicholas Jones</p><p>This code is released to the public domain. For information about the circuit,</p><p>visit the Instructable tutorial at <a href="http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/" rel="nofollow">http://www.instructables.com/id/Capacitive-Touch-...</a></p><p>*/</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &quot;pitches.h&quot;</p><p>#define COMMON_PIN 2 // The common 'send' pin for all keys</p><p>#define BUZZER_PIN A4 // The output pin for the piezo buzzer</p><p>#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings</p><p>#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)</p><p>#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard</p><p>// This macro creates a capacitance &quot;key&quot; sensor object for each key on the piano keyboard:</p><p>#define CS(Y) CapacitiveSensor(2, Y)</p><p>// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:</p><p>int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale</p><p>//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale</p><p>//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale</p><p>// Defines the pins that the keys are connected to:</p><p>CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};</p><p>void setup() {</p><p>// Turn off autocalibrate on all channels:</p><p>for(int i=0; i&lt;8; ++i) {</p><p>keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);</p><p>}</p><p>// Set the buzzer as an output:</p><p>pinMode(BUZZER_PIN, OUTPUT);</p><p>}</p><p>void loop() {</p><p>// Loop through each key:</p><p>for (int i = 0; i &lt; 8; ++i) {</p><p>// If the capacitance reading is greater than the threshold, play a note:</p><p>if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) &gt; CAP_THRESHOLD) {</p><p>tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed</p><p>}</p><p>}</p><p>}</p>
<p>sorry i want to ask you<br>both program and Material are right but when i tough tHe Aluminum foil </p><p>it don`t have sound<br>this is the program<br>/*</p><p> Capacitive-Touch Arduino Keyboard Piano</p><p> Plays piano tones through a buzzer when the user taps touch-sensitive piano &quot;keys&quot;</p><p> Created 18 May 2013</p><p> Modified 23 May 2013</p><p> by Tyler Crumpton and Nicholas Jones</p><p> This code is released to the public domain. For information about the circuit,</p><p> visit the Instructable tutorial at <a href="http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/" rel="nofollow"> http://www.instructables.com/id/Capacitive-Touch-...</a></p><p>*/</p><p>#include &lt;CapacitiveSensor.h&gt;</p><p>#include &quot;pitches.h&quot;</p><p>#define COMMON_PIN 2 // The common 'send' pin for all keys</p><p>#define BUZZER_PIN A4 // The output pin for the piezo buzzer</p><p>#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings</p><p>#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)</p><p>#define NUM_OF_KEYS 8 // Number of keys that are on the keyboard</p><p>// This macro creates a capacitance &quot;key&quot; sensor object for each key on the piano keyboard:</p><p>#define CS(Y) CapacitiveSensor(2, Y)</p><p>// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:</p><p>int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_C5}; // C-Major scale</p><p>//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale</p><p>//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale</p><p>// Defines the pins that the keys are connected to:</p><p>CapacitiveSensor keys[] = {CS(3), CS(4), CS(5), CS(6), CS(7), CS(8), CS(9), CS(10)};</p><p>void setup() { </p><p> // Turn off autocalibrate on all channels:</p><p> for(int i=0; i&lt;8; ++i) {</p><p> keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);</p><p> }</p><p> // Set the buzzer as an output:</p><p> pinMode(BUZZER_PIN, OUTPUT); </p><p>}</p><p>void loop() { </p><p> // Loop through each key:</p><p> for (int i = 0; i &lt; 8; ++i) {</p><p> // If the capacitance reading is greater than the threshold, play a note:</p><p> if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) &gt; CAP_THRESHOLD) {</p><p> tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed</p><p> }</p><p> }</p><p>}</p>
<p>So I have the circuit hooked up and I did it on a bread board. However, when I use pin 2 as the send pin it does not work. if I unplug the wire in pin 2 it sends it perfectly, but continually plays iwthout touching. I must add, I am also using pop cans instead of pieces of aluminum. Any suggestions?</p><p>Angela</p>
<p>Hello Angela!</p><p>It might be worthwhile to try lowering the CAP_THRESHOLD value (if you haven't already), since the cans will probably have a different capacitive characteristic. Try lowering it to the point were it triggers automatically and then raise it up a bit from there.</p><p>Hope that helps!</p>
<p>Heyy, i am trying to make this project. but it shows up the same error as capacitance type not defined. i have properly installed the libraries (pitches.h) but still the error shows up. please help me as i am not that good at coding. </p>
<p>Hi there!</p><p>You shouldn't need to do anything special with the &quot;pitches.h&quot; file; you can just leave it in the same folder as the &quot;.ino&quot; file. You will, however, need to install the &quot;CapactiveSensor&quot; library for your Arduino installation. You can download that library here:</p><p><a href="https://github.com/arduino-libraries/CapacitiveSensor/archive/master.zip" rel="nofollow">https://github.com/arduino-libraries/CapacitiveSen...</a></p><p>Here is a guide for installing libraries if you need help with that:</p><p><a href="http://arduino.cc/en/Guide/Libraries" rel="nofollow">http://arduino.cc/en/Guide/Libraries</a></p><p>Hope that helps!</p>
<p>So I have the circuit hooked up and I did it on a bread board. However, when I use pin 2 as the send pin it does not work. if I unplug the wire in pin 2 it sends it perfectly, but continually plays iwthout touching. I must add, I am also using pop cans instead of pieces of aluminum. Any suggestions?</p><p>Angela</p>

About This Instructable

167,948views

382favorites

License:

More by tylercrumpton:Built-in Vertical/Horizontal Remote Stand Design and Print a Tripod-Mountable Smartphone Case Capacitive-Touch Arduino Keyboard Piano 
Add instructable to: