Drum kit

Hi every one, I'm not sure if this is the right spot for this topic but here goes.

I've been working on a drum kit using and old set of guitar hero drums from my old xbox and i've wired all the piezos up like todbot has them wired here : Spooky Arduino Projects #4 – Musical Arduino – todbot blog now my problem is that when i have the anologRead() function repeated to read more then two inputs, I'm using all six for the project. The arduino seems to read all the piezos as if they are being hit. But if i only read from two It functions normally. Please help me, i'm adding the source for review.

thanks Jeff

// I'm combining the knock sensor code and the midi out code to
// play the midi equivalent of a cymbol when I bang the cymbol

  #define drumchan      1
  
  #define CrashNote    49    // defining Crash ...
  #define KickNote     36    // ... Kick ...
  #define SnareNote    38    // ... Snare ...
  #define EsnareNote   40    // ... electric Snare..
  #define HatNote      46    // ... hihatopen ...
  #define TomNote      43    // ... tom ...
  
  
  
int ledPin = 13; // this is our led pin just to visualize the notes being hit may be ommited

// setting up the anolog pins

int snare = 0;
int esnare = 1;
int tom = 2;
int hat = 3;
int cymbol = 4;
int kick = 5;

byte SnarVal = 0;
byte EsnarVal = 0;
byte TomVal = 0;
byte HatVal = 0;
byte CymAVal = 0;
byte KicVal = 0;

int statePin = LOW;
int THRESHOLD = 1;


void setup(){
  pinMode (ledPin, OUTPUT);
  Serial.begin(31250); // set the Serial to midi
}


void loop(){
  SnarVal = analogRead(snare);    // read the snare input
  EsnarVal = analogRead(esnare);    // read the esnare input
  TomVal = analogRead(tom);    // read the tom input
  HatVal = analogRead(hat);    // read the hat input
  CymAVal = analogRead(cymbol); // read the cymbol input
  KicVal = analogRead(kick);    // read the kick input
  
    if (SnarVal >= THRESHOLD) {
     statePin = !statePin;
    digitalWrite(ledPin, statePin);
    noteOn(drumchan, SnareNote, 0x45);        // set new note for the snare drum
   delay(10);
   noteOff (drumchan, SnareNote, 0);
    }
    
    if (EsnarVal >= THRESHOLD) {
     statePin = !statePin;
    digitalWrite(ledPin, statePin);
    noteOn(drumchan, EsnareNote, 0x45);        // set new note for the Esnare drum
   delay(10);
   noteOff (drumchan, EsnareNote, 0);
    }
    
    if (TomVal >= THRESHOLD) {
     statePin = !statePin;
    digitalWrite(ledPin, statePin);
    noteOn(drumchan, TomNote, 0x45);        // set new note for the Tom drum
   delay(10);
   noteOff (drumchan, TomNote, 0);
    }
    
    if (HatVal >= THRESHOLD) {
     statePin = !statePin;
    digitalWrite(ledPin, statePin);
    noteOn(drumchan, HatNote, 0x45);        // set new note for the Hat drum
   delay(10);
   noteOff (drumchan, HatNote, 0);
    }

    if (CymAVal >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    noteOn(drumchan, CrashNote ,0x45);    // set new note for Crash Symbol
    delay(10);
    noteOff(drumchan, CrashNote, 0); 
}
  
    if (KicVal >= THRESHOLD) {
     statePin = !statePin;
    digitalWrite(ledPin, statePin);
    noteOn(drumchan, KickNote, 0x45);        // set new note for the kick drum
   delay(10);
   noteOff (drumchan, KickNote, 0);
    }
}
/*
void noteOn(byte cmd, byte data1, byte data2){
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}
*/

// Send a MIDI note-on message.  Like pressing a piano key
// channel ranges from 0-15
void noteOn(byte channel, byte note, byte velocity) {
  midiMsg( (0x90 | channel), note, velocity);
}

// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
  midiMsg( (0x80 | channel), note, velocity);
}

// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
  digitalWrite(ledPin,HIGH);  // indicate we're sending MIDI data
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
  digitalWrite(ledPin,LOW);
}

Bump.

The arduino seems to read all the piezos as if they are being hit. But if i only read from two It functions normally

I would use 220K pull down resistor on each of the analogue inputs in place of the 1M.

Great thanks Grumpy_Mik. I'll give that a try when I get home, is there a reson I'd need 220K in place of 1M?

Yes, 1M is a very high impedance, this is not discharging the input capacitor when the multiplexer switches so it holds the charge from one channel to the next giving the effect you see. With a lower pull down resistor you help remove this charge. If it is still a problem try dropping it a bit more.

I get it now, I'm not using an external multiplexer, do you mean the arduino has an internal multiplexer?

Super thanks for the help!! I will post my findings when I find them!

It worked! Although I've yet to solder it all together, strickly breadboard atm. I find it is a bit finiky on the breadboard, I'll solder it up tomorrow.