Arduino musical glove in use

I spent the last month attempting to design a musical instrument using nothing but an Arduino Uno, basic supplies, and the (very) limited musical knowledge in my head. In the end, I decided upon constructing a musical glove.

Arduino musical glove without the glove

The musical glove plays individual notes as each of four fingers touches the thumb. At a basic level, each finger acts like a switch and is wired to complete a circuit when touched to the thumb; when this happens, a note is emitted via a small piezo-electric speaker, with different notes for each finger. The trick was identifying which finger was being pressed when, so as to be able to play a variety of notes. To get the right frequency for the notes, I worked off of the PlayMelody Arduino tutorial here. My prototype featured leads taped to pennies to create a larger conductive surface; each penny and wire was then taped to a glove. While functional, it was uncomfortable and bulky at best. It was hard to get the coins to touch at just the right angle, too, but once they connected they created a nice pure sound. I knew I was on the right track.

My final design used conductive thread sewn into each of the glove fingers, and each of those threads was wired to a lead which went back to the Arduino (through a breadboard). This was much more comfortable to use as it did not look much different than a normal glove, nor did it have any strange bulky areas. Most importantly, it was easy to use and very intuitive.

Arduino musical glove setup

As a final step, I taped two quarters separated by the slightly-conductive material velostat to act as a variable resistor to control volume. I decided the simplest place to add this function would be in the palm of the hand. The result was a fun musical glove that could play various simple tunes such as Mary Had a Little Lamb.

Arduino musical glove

To expand the project, I could make each section of the fingers a different note, yielding perhaps up to twelve different notes. I could also potentially add buttons on the glove to change octaves, and it was also suggested I could make two gloves that worked together.

This was a fun project and I learned quite a bit from it. Below is the code I used along with some more photos. Feel free to experiment with it yourself!

/* Musical Glove
 * -----------
 *
 * Program to play simple tunes using finger-operated
 *   instrument.

 * Tones are created by quickly pulsing a speaker on and off
 *   using PWM, to create signature frequencies.

 * Each note has a frequency, created by varying the period of
 *  vibration, measured in microseconds. We'll use pulse-width
 *  modulation (PWM) to create that vibration.

 * We calculate the pulse-width to be half the period; we pulse
 *  the speaker HIGH for 'pulse-width' microseconds, then LOW
 *  for 'pulse-width' microseconds.
 *  This pulsing creates a vibration of the desired frequency.
 *
 */

// TONES  ==========================================
// Start by defining the relationship between
//       note, period, &  frequency.
#define  Cnote     3830    // 261 Hz
#define  Dnote     3400    // 294 Hz
#define  Enote     3038    // 329 Hz
#define  Fnote     2864    // 349 Hz
#define  Gnote     2550    // 392 Hz
#define  Anote     2272    // 440 Hz
#define  Bnote     2028    // 493 Hz

// SETUP ============================================
// Set up speaker on a PWM pin (digital 9, 10 or 11)
const int speakerOut = 5;
const int indexIn = 1;
const int middleIn = 2;
const int ringIn = 3;
const int pinkyIn = 4;


void setup() {
  pinMode(speakerOut, OUTPUT);
  pinMode(indexIn, INPUT);
  pinMode(middleIn, INPUT);
  pinMode(ringIn, INPUT);
  pinMode(pinkyIn, INPUT);
}

// FINGERS  =======================================
// Each finger has its own note
int indexF = Fnote;
int middleF = Gnote;
int ringF = Anote;
int pinkyF = Bnote;

// Initialize core variable
int tone_ = 0;
int indexValue = 0;
int middleValue = 0;
int ringValue = 0;
int pinkyValue = 0;

// PLAY TONE  ==============================================
// Pulse the speaker to play a tone for a particular duration
void playTone() {
  // UP
  digitalWrite(speakerOut,HIGH);
  delayMicroseconds(tone_ / 2);

  // DOWN
  digitalWrite(speakerOut,LOW);
  delayMicroseconds(tone_ / 2);
}

void loop() {
  // Read current at each finger
  indexValue = digitalRead(indexIn);
  middleValue = digitalRead(middleIn);
  ringValue = digitalRead(ringIn);
  pinkyValue = digitalRead(pinkyIn);

  // Check if current is > 0 for each finger; if so, play associated tone
  if (indexValue > 0) {
    tone_ = indexF;
    playTone();
  }
  else if (middleValue > 0) {
    tone_ = middleF;
    playTone();
  }
  else if (ringValue > 0) {
    tone_ = ringF;
    playTone();
  }
  else if (pinkyValue > 0) {
    tone_ = pinkyF;
    playTone();
  }
}