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.
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.
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.
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.
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.
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.
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.
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.
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.
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Read the good book "Electronic Engineer Self-study Handbook" + Mastery Edition Overview
- The 555 timer only has a trigger signal and no RC circuit. What is the voltage level at the output?
- How are the results of CST PCB simulation displayed?
- Arrow Live: Focus on "TI FPD-Link III Automotive Chipset", the ideal solution for automotive video transmission
- Application of “C2000+TMS570” dual-chip solution in automotive electric drive functional safety
- A complete list of filter circuits, save it for future use!
- BLDC brushless motor driver
- AD621 and AD620
- Introduction to the conventional methods and shortcut keys for drawing schematics in KiCad
- When a differential op amp is used as a voltage detector for a battery in a battery pack, what is the output voltage expression? Virtual short: V+=v- ...