How to properly setup an undefined numbers of piezos for drumming ?

Hello everybody !
I'm currently into a really cool project which gives me quite hard times. To begin, I'm a big noob in electronics, but I'm decent in programming. So i'm able to understand, learn or correct myself easily when it's about code, but I'm really in the dark for everything concerning electronics despite the fact that I read so much about it recently...

My projet

My goal is to make my own MIDI drum kit. Not a new idea, but the difference is that I want to use lot of pads. I bought some WII, XBOX and PS drum kits that I disassembled to get just de pads.
Then I bought an Arduino Uno, not a mega because I'm a beginner and I can totally start with a small amount of pads, also I wanted the perfect solution in terms of compatibility etc.

STEP ONE : 1 pad

So, I first made a prototype with 1 pad, which was very easy to do, since there is billion of officials and unofficials tutorials about how to connect a piezo to the Arduino. So basically, on my breadboard its like that (except im on A0 not A2) :

So I connected my pad to the Arduino with a 1 Mohm resistor in parallel and I made a program which function very very well. You can read it the :

// Standard MIDI library for Arduino
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

// Variables
const int ledPin = 13; // control LED
const int knockSensor = A0; // First analog in pin
const int threshold = 250; // threshold of 250 is hard enough so it's stable, but soft enough so you dont have to hit hard
int sensorReading = 0;
MIDI_CREATE_DEFAULT_INSTANCE();

// Here I setup the test LED on digital pin 13, start the MIDI engine and start the serial connection
// so I can send both verification strings and MIDI information to the computer
void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  MIDI.begin();
  Serial.begin(115200); // this value of 115200 is for the serial to be understood by Hairless serial to MIDI convertor
  											// so when I hit the pad, it plays sounds in Ableton, Maschine, whatever I want
}
 

void loop() {
sensorReading = analogRead(knockSensor); // I read the piezo hit
if(sensorReading >= threshold) // If its above the treshold
  {
    int nouValeur = map(sensorReading, 0, 1023, 0, 127); // mapping hit value to MIDI velocity value to send proper MIDI info
    digitalWrite(ledPin, HIGH); // light the LED
    MIDI.sendNoteOn(42,nouValeur,1); // send a note
    delay(10);
    digitalWrite(ledPin, LOW); // shut the light
    MIDI.sendNoteOff(42,nouValeur,1); // shut the note send
    }
   
  }

The only challenge here was to set proper threshold and delay so the signal is clean when I hit the pad with a drumstick, to integrate the MIDI library and finally to find a software that makes the informations i send available in any of my favourites music softwares (Ableton Live, Maschine, ...), this software is Hairless Serial to MIDI, btw.

STEP TWO : X pads

It's when I'm getting troubles.
At first I believed that all I needed to do was to reproduce the same schematic but "duplicate it" x times. So I tried with 4 pads. I used the same strategy on my breadboard : each pad is connected in parallel with a 1 M ohm resistor, but all are connected to ground. You can see it there :

The code, take the old one, but just loop on the 4 pins :

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

const int ledPin = 13;
int myToms[] = {14,15,16,17 }; // On Arduino UNO, digital pin AO = 14, A1 = 15, etc.
int laNote[] = { 60,61,62,63 }; // Do, Do#, Re, Re#
const int threshold = 250;
int sensorReading = 0;
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  MIDI.begin();
  Serial.begin(115200);
}
 
 
void loop() {
  
for(int i=0; i<4; i++) // For each of the digital input
{
sensorReading = analogRead(myToms[i]); // we store it into the variable
if(sensorReading >= threshold)
  {
    int nouValeur = map(sensorReading, 0, 1023, 0, 127);
    digitalWrite(ledPin, HIGH);
    MIDI.sendNoteOn(laNote[i],nouValeur,1);
    delay(10); 
    digitalWrite(ledPin, LOW);
    MIDI.sendNoteOff(laNote[i],nouValeur,1);
    }
    }
   
  }

So here are the 2 issues :

  • The pad on the left is OK, like with my 1st program, the second one is still ok, the third one I have to hit a bit hard, the fourth one I have to hit VERY hard.

  • When I hit a pad, it seems it send electricity in others pins, I say that because when i connect the Arduino to a music software, hiting a pad = having multiples notes at the same time.

For the hitting force issue, I'vre tried to play with resistances, puting higher or lower values and I got totally lost with that : nothing seemed to be better. About that "leaking" issue, I thought it could be useful to put some diodes, as i heard diodes are usefull when you want to make the current going in one way only, but when i watch some others schematics, i see no diodes and only 1 Mohms resistors everywhere, so I really don't know what is wrong and what to do.

Here is the MIDI xylophone someone made and posted on instructables : http://cdn.instructables.com/FB6/VMRG/H4AGICO1/FB6VMRGH4AGICO1.LARGE.jpg
I have no idea why this is working and why there is ground directly linked to these analog pins, and many other things i cannot understand.

Any help would be really appreciated ! :slight_smile:

Here is the MIDI xylophone someone made and posted on instructables : http://cdn.instructables.com/FB6/VMRG/H4AGICO1/FB6VMRGH4AGICO1.LARGE.jpg
I have no idea why this is working

It is instructables, the reason it is working is because they lie.

When I hit a pad, it seems it send electricity in others pins,

Not quite. What is happening in an Arduino is that there is only one A/D converter with a switch to select one of the inputs to read. On the real input to the A/D is a small capacitor called a sample and hold capacitor that holds the voltage while it is being converted. The reason why one input affects the other is that the new voltage has not replaced the old voltage on the capacitor. This is because the input impedance of the voltage is very high.

It is recommended that you have a 10K input impedance, what you have is a 1M, that is 1,000K or 100 times higher than recommended.

However if you put a 10K resistor on the output of the sensor then you will kill the voltage from it and see nothing at all.

One way round this is to have an amplifier on the output of each sensor. If you use a simple FET you can use digital inputs rather than analogue inputs but you loose the ability to set a simple threshold. Attached is a circuit I have used, enable the internal pull up resistor on the digital input pin. You will get contact bounce of about 30mS for each hit but you can get round that in software.

Actually I think I may have resolved my issues by adding one missing cable between the 2 parts of my breadboard haha

Hi,
Please take Grumpy_Mike's advice about the buffer circuit.
Also I would be putting 5.1V zener diodes across each analog input to ground to protect the analog inputs from too high a voltage from the piezos.
Or a schottky from analog input to +5V.

See attached diagram.

Tom.... :slight_smile:

Thanks for both of your answers.

Questions :

  • "However if you put a 10K resistor on the output of the sensor then you will kill the voltage from it and see nothing at all."
    I still dont understand why a 10k kill the voltage and a 1 Mohm doesnt, I guess its basic electronics...

  • If so, why every, like the totality of the billions tutorials use 1 Mohm resistors with piezo ?

  • TomGeorge, If I understand, you are placing resistors in series, not in parrallel, why ? Everywhere its in parrallel :slight_smile:

  • Finally, I've read that Arduino can handle the hits from piezos, how can I calculate how much piezo it can handle and, is there any chance that, on the MIDI xylophone tutorial, the 4 ground going directly to inputs are serving this purpose of "discharge" the circuit ?

The four grounds are providing a common referance, you need them to make sensible measurements.

10 K will kill the voltage because because the power needed to raise a specific voltage at a specifics resistance is a lot higher when the resistance is low than whe. It is high.

Web pages follow each other and one stuped method gets peopergated by ignorent people. The fact that 1M works for one chanel is thought to be profe that it works for many channels shuts shows you how stupid some people x
Can be.