Can input pins leak voltage into the next pin?

Hi Arduino’s,

I’m working on a midi drum trigger project and I am coming across a problem. Sometimes when I hit a pad it will send a midi note for the pad I hit AND the pad connected to the next pin on the Arduino (for example pin 0 and pin 1 or pin 1 and pin 2 but NOT pin 1 then pin 0). Now this can’t be cross talk between the pads because I currently only have one pad hooked up to the arduino.
I’m wondering if the input is coming in above 5v and then leaking into the next pin on the Arduino? I do have a 5.1v zener diode to protect the input as the maximum voltage input is 5.1v so I don’t see that as a possibility. Also note that the minimum value to trigger a note is fairly small (.15 v).

Maybe it’s my code?

//  Kerl Mera //
// Midi tests for midi drum pads //
// March 2013 //

/*
Circuit:
 Pad: A0
 1M resistor
 5.1v Zener Diode
 
 */

// Variables
char currentPad = 0;
char numOfPads = 3;
char padGroup = 0;

// Array [regular, DIY, bass Drum]
int slopeOneMin[] = {
  30, 50, 60};
int slopeOneMax[] = {
  180, 220, 150};
int slopeTwoMax[] = {
  700, 700, 600};
int slopeThreeMax[] = {
  1023, 1023, 1023};
char slopeOneVMin[] = {
  15, 25, 30};
char slopeOneVMax[] = {
  42, 60, 60};
char slopeTwoVMax[] = {
  84, 84, 90};
char slopeThreeVMax[] = {
  100, 100, 100};

unsigned char padNote[] = {
  38, 40, 46};
boolean padActive[] = {
  false, false, false};
unsigned long timeKeeper[] = {
  0, 0, 0};
int bounceTime[] = {70, 90, 40};

void setup() {
  Serial.begin(31250); // Baud rate for midi 
}

void loop() {
  // Loop through the available pins
  for(currentPad = 0; currentPad < numOfPads; currentPad++ ) {
    int firstValue = 0;
    int secondValue = 0;

    // Set the appropriate pad group
    if(currentPad == 0) {
      padGroup = 2;
    } 
    else if(currentPad == 1) {
      padGroup = 1; 
    }

    // Read the voltage in from the pin
    firstValue = analogRead(currentPad);

    // Test to see if the reading is above the threshold
    if(firstValue > slopeOneMin[padGroup] && (millis() > timeKeeper[currentPad] + bounceTime[padGroup])) {
      timeKeeper[currentPad] = millis();
      secondValue = analogRead(currentPad);

      if(firstValue > secondValue) {
        firstValue = constrain(firstValue, slopeOneMin[padGroup], slopeThreeMax[padGroup]);
        if(firstValue <= slopeOneMax[padGroup]) {
          firstValue = map(firstValue, slopeOneMin[padGroup], slopeOneMax[padGroup], slopeOneVMin[padGroup], slopeOneVMax[padGroup]);
        }
        else if(firstValue <= slopeTwoMax[padGroup]) {
          firstValue = map(firstValue, slopeOneMax[padGroup], slopeTwoMax[padGroup], slopeOneVMax[padGroup], slopeTwoVMax[padGroup]);
        }
        else {
          firstValue = map(firstValue, slopeTwoMax[padGroup], slopeThreeMax[padGroup], slopeTwoVMax[padGroup], slopeThreeVMax[padGroup]);
        }

        midiMSG(0x90, padNote[currentPad], firstValue);
      } 
      else {
        secondValue = constrain(secondValue, slopeOneMin[padGroup], slopeThreeMax[padGroup]);
        if(secondValue <= slopeOneMax[padGroup]) {
          secondValue = map(secondValue, slopeOneMin[padGroup], slopeOneMax[padGroup], slopeOneVMin[padGroup], slopeOneVMax[padGroup]);
        } 
        else if(secondValue <= slopeTwoMax[padGroup]) {
          secondValue = map(secondValue, slopeOneMax[padGroup], slopeTwoMax[padGroup], slopeOneVMax[padGroup], slopeTwoVMax[padGroup]);
        } 
        else {
          secondValue = map(secondValue, slopeTwoMax[padGroup], slopeThreeMax[padGroup], slopeTwoVMax[padGroup], slopeThreeVMax[padGroup]);
        }

        midiMSG(0x90, padNote[currentPad], secondValue);
      }

      padActive[currentPad] = true;
    } 
    else if (padActive[currentPad] == true) {
      padActive[currentPad] = false;
      midiMSG(0x80, padNote[currentPad], 0x00);
    }
  }
}

void midiMSG(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

The A/D pins work by charging a capacitor. If the impedance of the input is too high (100K Ohms?) the capacitor charge won't change fast enough. Ground the inputs you are not using and they will not trigger on the left-over charge.

kerl:
Now this can't be cross talk between the pads because I currently only have one pad hooked up to the arduino.

If the other inputs don't have anything connected to them then they will be floating. If your sketch then reads the floating pins, it can get arbitrary results which can be affected by activities on adjacent pins. If you want to leave the inputs enabled in your sketch but not connect the pins to your sensors, you need to pull the spare pins up (or down) so that they are at a defined and consistent state.

1 Like

PeterH:
If the other inputs don't have anything connected to them then they will be floating. If your sketch then reads the floating pins, it can get arbitrary results which can be affected by activities on adjacent pins. If you want to leave the inputs enabled in your sketch but not connect the pins to your sensors, you need to pull the spare pins up (or down) so that they are at a defined and consistent state.

I remember reading about floating pins before. If it has any connection at all to a sensor then it will not float anymore? I hooked up an audio jack to the unused inputs but they were still triggering false readings. I have not however connected a sensor to it to test if the Arduino will still trigger flase notes.
I will test this and report back.

kerl:

PeterH:
If the other inputs don’t have anything connected to them then they will be floating. If your sketch then reads the floating pins, it can get arbitrary results which can be affected by activities on adjacent pins. If you want to leave the inputs enabled in your sketch but not connect the pins to your sensors, you need to pull the spare pins up (or down) so that they are at a defined and consistent state.

I remember reading about floating pins before. If it has any connection at all to a sensor then it will not float anymore? I hooked up an audio jack to the unused inputs but they were still triggering false readings. I have not however connected a sensor to it to test if the Arduino will still trigger flase notes.
I will test this and report back.

Here is the deal. The arduino has just one ADC internal device that uses a single sample and hold capacitor to switch an external attached voltage from the selected analog input pin to the cap through a input pin demultiplexer. So when you read a pin that has a real signal wired to it, it charges the cap to the applied external voltage then the cap is switched to the ADC device for measurement conversion. So if you select a chip that has nothing wired to it the cap is going to have some remaining voltage charge from the last valid pin it did read and give you a ‘false’ reading for the unconnected pin. It’s not a true cross-talk problem, it’s basic to the multiplexed sample and hold method that the AVR ADC uses.

So either wire a real voltage to the unused analog input pins, or simply don’t read unused/unwired pins in your sketch. You can have the same problem with digital input pins as having nothing wired to them reading them will give invalid values.

Lefty

1 Like

Thank you for the help from both of you.
Connecting the pin to a sensor certainly fixed the problem. I assumed that since the analog pin was wired up to an audio jack then it would not be susceptible to false reading from an unconnected input pin.
The whole reason I was reading the pins without all the sensors hooked up was because I was trying to test out the code to make sure it worked before I hooked everything up. It turns out I would have spent less time confused if I had just hooked up all the sensors in the first place :fearful:

So again thanks to all. I will use my knowledge to help the community as all of you great hobbyist do :smiley:

thanks thats really help me

An audio jack with nothing plugged into is is no connection - unless the "back" contact which connects to the tip when there is nothing plugged in, is connected to ground.

Look at the date...