SquareWear 2.0 Touch Sensing and Digital Piano Demo

Looking for new projects to do with SquareWear 2.0? Here is an idea: combine SquareWear 2.0 with touch sensing to make a digital piano! It works as a standalone project and no additional hardware is required. Take a look at the video first:

How does this work? First, SquareWear 2.0 has a built-in buzzer, so it can already make sound. Next, touch sensing is detected in software. It basically exploits the principle of capacitive sensing: every time you touch an Arduino pin, it slightly alters the capacitance of the pin. This change of capacitance can be detected using a variety of methods. The simplest is to set the pin to digital input mode, and turn on the internal pull-up resistor. This will start charging the capacitor. By detecting the time it takes to charge the capacitor, you can infer the capacitance, and in turn tell if a finger touch has occurred on the pin. That’s it! Because SquareWear maps out available pins to large pin pads, this makes it particularly well-suited for touch sensing.

So I wrote a quick demo as a proof-of-concept. First, I found a function that implements the capacitive sensing from the Arduino playground website. It basically returns a touching sensing value, which can then be compared to a threshold. You may need to adjust the threshold to increase or decrease the sensitivity. The demo scans through all 12 pins available on the SquareWear 2.0 and plays a tone for 125 milliseconds if a pin touch is detected. As a result, the buzzer makes a chiptune type of sound. The code also uses the on-board pushbutton to switch between three octaves: C3, C4, and C5. The LED will blink when a tone is played.

A few notes and quirks:

  • The code works the best if you plug in a USB cable connected to your computer.
  • You can also moisten your figures to help increase the touch sensitivity.
  • If you unplug the USB cable, it generally helps if you use one hand to hold the battery, or the VCC or GND pin. You may need to cover the ISP pins on the back side to avoid touching them. Holding the battery, VCC or GND helps amplify small capacitive changes.
  • The MOSFET pins (D3, D5, D6) do not seem to work well without the USB cable. To be honest, I was surprised that these pins even worked at all, because the pads are not directly connected to the pins (rather, the connection is through a MOSFET). So if you need, you can modify the source code to disable these pins.

The demo code is available in the SquareWear 2.0 software package on Github. The direct download link is below:

I will keep posting new project ideas in the upcoming weeks. SquareWear 2.0 is available for purchase at the Rayshobby Shop. At a price of $22 and with a load of built-in components, it’s a great little gadget to help you learn Arduino programming, and build wearable as well as general-purpose electronic projects. Hope you like this demo and your support is greatly appreciated!

One thought on “SquareWear 2.0 Touch Sensing and Digital Piano Demo

Leave a Reply