loading
So I did a project that was originally posted on instructables and tried to make it work. This is less of a tutorial and more of a 'this is what I tried to do and how it turned out.' Also for anyone who tried to do the same instructable as me, this has a couple of things I found out along the way.
the original instructable - https://www.instructables.com/id/How-to-build-an-Air-Guitar-with-Arduino-aka-the-A/

Step 1: The Stuff

The first thing I did was get all of the stuff I needed to complete it:

1. the arduino (arduino uno was what I was using)

2. an ultrasonic sensor,
used to detect the distance between your hands, which changes the pitch in the note ( http://www.mouser.com/ProductDetail/Parallax/28015/?qs=sGAEpiMZZMuVJC7Vq%252bMl53IruZP3FEtl )

3. an accelerometer, which detects movement for vibrato ( http://www.amazon.com/gp/product/B00CD2JIBK/ref=oh_details_o00_s00_i00?ie=UTF8&psc=1 )

4. conductive fabric for the gloves ( https://www.sparkfun.com/products/10056 )

5. 10K resistors, 1M potentiometers, a 10uf capacitor, lots of wire, a soldering iron and flux (especially if you solder like I do), all of this I found at Radio Shack

6. and of course a pair of gloves. I just used regular winter gloves. 

Step 2: The Schematic / the Code

This is the schematic and the code I used from the other instructable. The only difference I made was I wanted to use two gloves instead of a glove and stick. That way if you wanted to mime any other instrument you could, for instance if  I wanted to play it like a harp or something. That decision was purely visual-based. 


------------------------------------------------------
// An array containing the waveform
// of a guitar sound
char waveform[] =
{125, 148, 171, 194, 209, 230, 252, 255,
253, 244, 235, 223, 207, 184, 169, 167,
163, 158, 146, 131, 126, 129, 134, 127,
105, 80, 58, 51,38, 22, 12,  2, 10, 35,
58, 75, 89, 103, 120, 141, 150, 148, 145,
144, 140, 129, 116, 105, 95, 86, 75, 72,
73, 76, 88, 103, 117, 121, 120, 115, 120,
143, 159, 162, 156, 155, 163, 184, 202,
214, 215, 211, 213, 212, 205, 196, 182,
162, 142, 118, 99, 84, 68, 54, 40, 28,
19, 10,  7,  0,  0,  5,  9, 14, 21, 33,
49, 59, 65, 75, 92, 110};

// We use this waveform to change the
// volume of the output
char waveformVolume[] =
{125, 148, 171, 194, 209, 230, 252, 255,
253, 244, 235, 223, 207, 184, 169, 167,
163, 158, 146, 131, 126, 129, 134, 127,
105, 80, 58, 51,38, 22, 12,  2, 10, 35,
58, 75, 89, 103, 120, 141, 150, 148, 145,
144, 140, 129, 116, 105, 95, 86, 75, 72,
73, 76, 88, 103, 117, 121, 120, 115, 120,
143, 159, 162, 156, 155, 163, 184, 202,
214, 215, 211, 213, 212, 205, 196, 182,
162, 142, 118, 99, 84, 68, 54, 40, 28,
19, 10,  7,  0,  0,  5,  9, 14, 21, 33,
49, 59, 65, 75, 92, 110};
// An array used as a buffer to avoid
// erroneous punctual distance
// measurements
unsigned int distance_buffer[] = {16000,
16000, 16000, 16000, 16000, 16000, 16000,
16000, 16000, 16000, 16000, 16000, 16000,
16000, 16000, 16000};

const int distance_length = 3;
int distance_index = 0;

// The overflow values for 2 octaves
int frequencies[] = { 39, 42, 44, 47,
50, 52, 56, 59, 63, 66, 70, 74, 79,
84, 89, 94, 100, 105, 112, 118, 126,
133, 141, 149};

// Initial pitch
int pitch = 160;

// Initial volume and acceleration
// parameter
int lastAcc = 0;
float volume = 0;

//audio playback on pin 3
byte speakerpin = 3;

//index variable for position in
//waveform
volatile byte waveindex = 0
volatile byte currentvalue = 0;

// Pin used for ultra-sonic sensor
const int pingPin = 7;

// Pins for the potentiometers
const int sustainPin = 1;
const int sensitivityPin = 2;

// Pins for each finger of the left
// hand
const int finger1 = 9;
const int finger2 = 10;
const int finger3 = 11;
const int finger4 = 12;

int fingerValue = 0;

long duration, inches, cm;

void setup() {

pinMode(3,OUTPUT); //Speaker on pin 3

pinMode(finger1,INPUT);
pinMode(finger2,INPUT);
pinMode(finger3,INPUT);
pinMode(finger4,INPUT);


/**************************
    PWM audio configuration
****************************/
//set Timer2 to fast PWM mode
//(doubles PWM frequency)
bitSet(TCCR2A, WGM21);
bitSet(TCCR2B, CS20);
bitClear(TCCR2B, CS21);
bitClear(TCCR2B, CS22);

//enable interrupts now that registers
// have been set
sei();


/*************************
Timer 1 interrupt configuration
*************************/
//disable interrupts while
// registers are configured
cli();

/* Normal port operation, pins disconnected
from timer operation (breaking pwm) */
bitClear(TCCR1A, COM1A1);
bitClear(TCCR1A, COM1A1);
bitClear(TCCR1A, COM1A1);
bitClear(TCCR1A, COM1A1);

/* Mode 4, CTC with TOP set by register
OCR1A. Allows us to set variable timing for
the interrupt by writing new values to
OCR1A. */
bitClear(TCCR1A, WGM10);
bitClear(TCCR1A, WGM11);
bitSet(TCCR1B, WGM12);
bitClear(TCCR1B, WGM13);

/* set the clock prescaler to /8.  */
bitClear(TCCR1B, CS10);
bitSet(TCCR1B, CS11);
bitClear(TCCR1B, CS12);

/* Disable Force Output Compare for
Channels A and B. */
bitClear(TCCR1C, FOC1A);
bitClear(TCCR1C, FOC1B);

/* Initializes Output Compare
Register A at 160 to set the
initial pitch */
OCR1A = 160;

//disable input capture interrupt
bitClear(TIMSK1, ICIE1);
//disable Output
//Compare B Match Interrupt
bitClear(TIMSK1, OCIE1B);
//enable Output
//Compare A Match Interrupt
bitSet(TIMSK1, OCIE1A);
//disable Overflow Interrupt
bitClear(TIMSK1, TOIE1);

// enable interrupts now that
// registers have been set
sei();
}

// Timer overflow handler
ISR(TIMER1_COMPA_vect) {

/* timer1 ISR.  Every time it
is called it sets speakerpin to the
next value in waveform[]. Frequency
modulation is done by changing the
timing between successive calls of
this  function, e.g. for a 1KHz tone,
set the  timing so that it runs
through waveform[] 1000 times
a second. */

// reset waveindex if it has reached
// the end of the array

if (waveindex > 102) {
  waveindex = 0;
}

//Set the output value
if (volume > 0.03) {
  analogWrite(speakerpin,
   waveformVolume[waveindex]);
}
waveindex++;

// Update the pitch
OCR1A = pitch;



void loop()
{
// Desactivate interputs, send a ping
// message and wait for the answer.
cli();
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
duration = pulseIn(pingPin, HIGH, 2000);
sei();
// convert the time into a distance
// in centimetres
// and store in buffer
distance_buffer[distance_index++
  % distance_length] = duration / 20;

//Find in the buffer the shortest
// distance measured
cm = 16000;
for(int i = 0; i < distance_length; i++) {
  cm = min(cm, distance_buffer[i]);
}

// Check which fingers are pressed
fingerValue = 5;
if(!digitalRead(finger4)){
  fingerValue = 4;
}
if(!digitalRead(finger3)){
  fingerValue = 3;
}
if(!digitalRead(finger2)){
  fingerValue = 2;
}
if(!digitalRead(finger1)){
  fingerValue = 1;
}

// Update the sustain and
// sensitivity values
float sustain =
map(analogRead(sustainPin), 0,
  1024, 101, 130) / 100.0;
int sensitivity =
    map(analogRead(sensitivityPin),
    0, 1024, 100, 200);

// Update the volume
volume = volume / sustain;
if (volume < 0) {
  volume = 0;
}

// Check the accelerometer
int acc = analogRead(0);
int accDiff = lastAcc - acc;

// Update the volume value
if (accDiff > 5 * (200 - sensitivity)) {
  volume += (float)
   pow(accDiff,
       sensitivity / 100.0) / 50000;
}
lastAcc = acc;

// Check that volume is not higher than 1
if(volume > .95) {
  volume = .95;
}

// Update the volume in the waveform
for(int i = 0; i <= 102; i++) {
  waveformVolume[i] =
   ((waveform[i] - 127) * volume) + 127;
}

// Set the pitch according to the distance
// between the two hands and the
// fingers pressed
if(cm < 102 && cm > 0) {
  if(cm > 30) {
   pitch = frequencies[7 +
    (((cm - 30) / 24) * 4 + fingerValue - 1)];
  }else{
   pitch = map(cm, 0, 30, 39, 79);
  }
}else{
  pitch = frequencies[7 +
   (((102 - 30) / 24) * 4 + fingerValue - 1)];
}

// Delay to avoid bouncing signals
delay(50);
}

------------------------------------------------------

Step 3: The Gloves

I started out making the ground for the left hand glove. I made a ground about palm width for reassurance (even though if it's in any way touching the fabric, it's going to be grounded). Sewing the fabric to the glove was just an easy way to attach it and make sure it stayed. You'll do the same with the fingers, accept those will all go to resistors and back into the arduino. The gloves I had were already fingerless, mostly because the ones I found around the house were two small. Of course using a full glove will work; it's probably easier because it'll stay on better. But this way anyone in the house could play the same pair. 

Step 4: The Hardware

The sensor: 
The way the sensor is used in this project is in two parts. The actual sensor and the receiver (on the left) will be in the left hand. The tricky part is soldering off the transmitter (on the right) without burning the chip. It's extremely helpful to have extra hands when dealing with this piece. Another thing that's helpful is a solder vacuum. It's just a tube with a bulb on it and it sucks up the solder once it gets hot and liquifies. If you do it that way you could probably separate the two in a matter of minutes. Solo, it took me a few hours, because I had to stop once I thought the chip was getting too hot. Luckily I didn't burn it. When soldering the ground to the transmitter, there's a prong with a black base, so I figured that prong was ground. The other prong needs a really long wire to go back to the accelerometer so it can detect itself. It needs to be about wingspan so you can still spread your hands as far apart as you want.

The arduino: 
Once you start soldering and if you do like I do and want to attach things to the arduino as you go, it's going to be moving around a bit. So I mounted mine. I just found a piece of styrofoam with cardboard attached to it, cut out a shape big enough for it to fit onto and used thumbtacks to attach the arduino to it.

The accelerometer: 
Be careful when you look for an accelerometer to use. I made the mistake of ordering one that wasn't mounted to anything yet. It's about as big as a finger nail, if that, when it's still in the casing. When you take the actual chip out it's probably about the size of a diamond in an earring. Also I had a three axis accelerometer but the original instructable works with one. I only ended up using the x-axis and of course the power and the ground. 

Step 5: The Work / the Fail

These are mostly just pictures of getting everything together and all the soldering work. 

The story of how this project ended is not a happy one. I had everything soldered the first time, but all of my connections were finicky. Since I've never done a project like this, I had my dad take a look at it the second time to double check things. Well, when all of the soldering work was done and everything was for sure going to stay, we turned on the arduino…and nothing happened. So we unplugged it and took it all apart. We left the arduino on (to see if that's where the problem was, and it came on so it was fine) and began plugging things back in. Any time we plugged the ground in, it would short itself out. Well after taking everything apart the third time, we discovered that the accelerometer was the culprit. I'd burned it. Checking everything else, we found out that was literally the only problem. Thus the fail, one chip that wasn't working... 
<p>Failure is always an option. I'm glad you posted this, it's a good thing for folks to see how things can not work out. Did you eventually get it working?</p>
<p>i didn't it. i don't know if i said this but it was the accelerometer that burned out and since it was for class i couldn't turn it in like that. since then though between other classes and projects i haven't been able to touch it. thank you for the encouragement though. i'm part idiot so i feel a little better about it. :) </p>

About This Instructable

1,693views

10favorites

License:

More by cltillman:Arduino/LED/MP3  Arduino Gloves (An Attempt) 
Add instructable to: