How to Make a Touch Capacitive Piano Using Arduino

Publisher:温暖的拥抱Latest update time:2023-06-06 Source: elecfansKeywords:Arduino Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This tutorial is going to be very exciting for electronics makers as we will be designing our very own touch controlled capacitive piano using Arduino Nano. We will be adding recording and playback features to our piano. So far we have made a few piano projects using Arduino but this project is completely different as we will be using capacitive touch keys as our piano keys. So while learning how to make a fun piano to play, we will also explore how to design capacitive touch keys on PCB as you can try to make our keys look like real piano keys. The PCB looks and works like a piano thanks to its manufacturer PCBWay and we will also explore how we designed and manufactured this board but before that, let’s explore capacitive touch sensors and how they work.


How do capacitive touch sensors work?

We know that in order to form a capacitor with a certain capacitance value, we need two parallel conducting plates separated by a dielectric material. But how can we tell if the capacitance has changed just by touching the conducting plates with our finger? Our answer is based on our basic understanding of capacitors. As we all know, changing the area of ​​the conducting plates or the distance between two parallel conducting plates can change the capacitance value. Between the conducting plates and our finger, we have air as a dielectric. As a result, when we touch the plates with our finger, the increase in capacitance is indeterminate because our finger acts as a conducting object and the distance between the two conducting objects decreases. We know that the basic formula for the capacitance of a parallel plate capacitor is,

C = εA/d

Where "A" represents the area of ​​the conductive plate, "d" represents the distance between the two conductive plates, and "ε" represents the dielectric constant of AIR. As a result, increasing the area and decreasing the distance between two parallel conductive plates increases the capacitance value. In our case, touching the conductive plates decreases the distance while increasing the capacitance value. Can we detect this changing capacitance by connecting a conductive material to a resistor and a GPIO pin of a microcontroller? The answer is, we can't. Yes, connecting a voltage source to it will cause a small change in the analog voltage, but this is not a very reliable solution.


How to detect capacitance change in capacitive touch sensor?

So how can we tell if the capacitor value has changed? However, there is a better way to go about it. Let's take a look at the block diagram below. Think of it as a basic circuit consisting of a microcontroller (in this case, an Arduino Nano), a 1 megohm resistor, and a conductive plate. The two digital lines of the Arduino Nano are connected to a resistor loop with a 1 megohm resistor. This resistor also has a point connected to the conductive plate. While this plate acts as a single point for the capacitor, it can still introduce capacitance that changes when we touch it. However, this cannot be detected simply by detecting a change in voltage. A change in capacitance on this line is not as easy as sensing a switch in value on a GPIO pin.


How does the Capacitive Sensor Library work?

This is where the Arduino libraries come in handy. Many thanks to Paul Bagder and Paul Stoffregen, the authors of the “CapacitiveSensor” library. We can use this library to detect the change in capacitance when we touch that conductive plate. In this library, one digital pin is used as the send pin (as OUTPUT) and the other is used as the receive pin (as INPUT). The duration between when the send pin goes high and when the receive pin goes high is the only way to detect the change in capacitance. When you set the send pin to HIGH (or 5 volts), the resistor-capacitor pair creates a delay between when the send pin goes high and when the receive pin reads a high value from the send pin. The CapacitiveSensor library provides a function that sets the send pin to HIGH and then waits and counts until the receive pin is read as HIGH. This function returns a time value that can be used to detect changes in capacitance. When the time value increases or decreases, it indicates that the capacitance value has changed. When the capacitance is larger, the time it takes for the receive pin to go high is longer, and when the capacitance is smaller, the time it takes for the receive pin to go high is shorter. Therefore, we can determine what the normal state is and then check for changes every time the send pin toggles.


We will use the “CapacitveSensor” library to detect the change in capacitance. But before we go into the programming part, let’s create the circuit and PCB for our project. Here, we use the EasyEDA platform to create the schematic and PCB for our project. To detect the change in capacitance, we will use the “CapacitveSensor” library. Before we start programming, let’s start with the circuit and PCB of our project. The schematic and PCB of our project are created using the EasyEDA platform. On the EasyEDA platform, we have created a large number of PCB projects. These projects can be used to get the concept of how to design a PCB on EasyEDA.


Components needed to build a PCB piano using Arduino Nano

The following components are required to build a PCB piano using Arduino Nano.

Arduino Nano

Resistors (1Mega Ohm) x 8

Piezo Buzzer

18650 battery cell

18650 Battery Holder

18650 battery charging module

DC to DC voltage booster.

PCB Piano Circuit Diagram Using Arduino Nano

In the following circuit diagram, eight 1Mega Ohm resistors are connected to Digital Pin 2 of the Arduino Nano. Digital pins 3 to 10 are further connected to the other connection points of each resistor. In the following diagram, we have a slide switch labeled “RECODINGSWITCH”. Digital pin 12 of the Arduino Nano is connected to the “EN” pin of the slide switch. The “Vs” pin of the slide switch is connected to the “5V” pin of the Arduino Nano. The “GND” pin of the slide switch is connected to the “A4” pin of the Arduino Nano. The negative terminal of the buzzer is connected to the ground pin of the Arduino Nano.

poYBAGLiTJCAHkZJAAG3qUVu-cE130.png

We have connected eight 10uF capacitors to each resistor. The negative pin of each capacitor is connected to the ground pin of the Arduino Nano. We then have a power supply section that provides the proper 6.6V to the "Vin" pin of the Arduino Nano. The 18650 battery cells are connected to the 18650 battery charger module and the output of the charger module is connected to a DC to DC booster. The positive output pin (BOUT+) of the booster is connected to the "Vin" pin of the Arduino Nano and the negative output pin (BOUT-) of the booster is connected to the ground pin of the Arduino Nano.


Note: We can add capacitors if required. It is highly recommended to use small capacitors (20pF - 400pF) to stabilize the detected data. However, make sure that the capacitors are connected to ground as this will reduce the parallel body resistance. However, in my case, I did not use capacitors as it worked well for me without them. I have mentioned capacitors in the schematic above so you can easily add them during actual implementation. As specified in the “CapacitveSensor” library documentation, the value of the following capacitors must be between 20pF and 400pF.


PCB Overview

The PCB view of the above schematic is shown below. You can download the Gerber files of the project from our GitHub repository. Alternatively, you can visit the project on the EasyEDA platform for more details. Yellow is used for the top silk layer. While green represents the bottom silk layer. Red represents the top layer and blue represents the bottom layer.

pYYBAGLiTJWAOTDgAAV6BxXstRk183.png

Top layer of PCB:

Now, let's look at each layer of the PCB layer by layer. The top layer is shown in the image below. As you can see, the top layer is red. I designed each conductive plate to look like a piano. Each key of the piano is connected to each 1 megohm resistor individually.

pYYBAGLiTJqAc7dtAAFcf8bKAPg357.png

I used the rectangular shape that can be found in the PCB Tools section of EasyEDA, circled in red in the image below. Make sure the width of the keys is large enough so that you can touch each key with your finger. In my case, I managed to draw each key with a width of 10 mm or more.

pYYBAGLiTJ-AddTTAACLaxSvzfg582.png

Bottom layer of PCB:

On the bottom layer, we have a complete copper layer for connecting all the grounds. You can use the "Solid Region" option in EasyEDA's "PCB Tools". This is called the "Copper Pour" method. This step will convert the bottom layer into a common ground layer. We also have some other copper connections on this layer.

poYBAGLiTKSARNuEAAFtqny9A9c146.png

Top silk layer of PCB:

The image below represents the Top-Silk-Layer of the PCB. We can design our PCB by adding some silk layers or non-copper layers. I have marked the slide switches as "RECORD" and "PLAY". So that we can understand which mode we are using. We have the footprint of BUZZER on the top silk layer. "XL6009E1" is the footprint of the DC to DC boost module surrounded by a square area. We can add text and images using the corresponding PCB tools available on EasyEDA.

poYBAGLiTKmACyzOAAGPGVI_Pus600.png

Bottom silk layer of PCB:

On the bottom silk layer of the PCB, we have the Arduino Nano, 8 1Mega ohm resistors, 8 capacitors, a 18650 battery holder or footprint for a single cell battery and a charging module.

pYYBAGLiTK6ALujWAAFnEdu1VNw871.png

Programming the Piano PCB using Arduino Nano

The “CapacitiveSensor” library is very easy to use and they have provided a very good documentation on how to use the library. Before jumping into the program, let’s install the “CapacitiveSensor” library on the Arduino IDE. You need to download the zip file of the library. Then go to the “Sketch -> Include Library” section under the Arduino IDE toolbar. Add the zip file using the “Add .Zip Library…” option as shown in the following image. Then restart the Arduino IDE.

pYYBAGLiTLOAT-aKAAK5YDmPVCA234.png

Now you can download the code for this project from our github repository and open the "piano_pcb.ino" file in the "codes" folder. We have a custom header file called "piano_tones.h". This header file is included in the main file to get some predefined custom piano tones. Just like a piano, each tone refers to a note. Let's see what's inside the "piano_pcb.ino" file.

[1] [2] [3]
Keywords:Arduino Reference address:How to Make a Touch Capacitive Piano Using Arduino

Previous article:How to Build a Gesture-Controlled Raspberry Pi Media Player
Next article:How to Build a Portable Humidifier Using Arduino

Recommended ReadingLatest update time:2024-11-16 21:28

Arduino - Minimal System (Based on ATMEGA8-16PU)
【Basic Introduction】 Material preparation: ATMEGA8-16PU microcontroller. The program is downloaded directly through the ISP programmer, so there is no need to burn the Bootloader. (Optional) USB ISP programmer (If you don’t have a programmer, use Nano to make a downloader and compile and download using the chip’s fact
[Microcontroller]
Arduino - Minimal System (Based on ATMEGA8-16PU)
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号