21 Piezo Midi drum pad using 3x ic 74HC4051 Multiplexer

I am new to the Arduino world, have already done some simple projects. but with the multiplexer I still have problems. I have to say that I can not program. :frowning: and ask for help, I have already built a Drumpad with 8 Piezo and Arduino nano.
and now I want to build one with 21 piezos and 3x 4051 multiplexer. I also built everything but did not find a sketch.I thank you for help

here the tutorial

here is the schematic for my project in the appendix

Piezo_Drum_Pad_v0_1.ino (1.62 KB)

I also built everything but did not find a sketch.

But the link is there in the video's description https://www.patreon.com/posts/midi-piezo-drum-6772329

And this is the code you posted? What is going on?

How to post images Image guide image guide

first i wanna thank you for your quick answer, and apologize for confusion,
i try to ask more specifically;

So the problem that i have is to find a code (as im not able to program by myself) that is working for my 21 piezos 3 mux MIDI drumpad, a code i can use directly OR a code that can be modified and changed

I knew the link in video´s description but i think i cannot use it as this code is not working with Multiplexer (Mux)
(correct me if im wrong)

Im gonna post;

1A)picture of my hardware (21 piezos drumpad working with 3 mux)
1B)circuit diagram for my piezo drumpad

  1. Piezo_Drum_Pad_v0_1
    :sketch i already posted in my first posting, isn’t working with mux but really nice to adjust parameters like sensitivity to my piezo

  2. MIDI_Controller_v1-2
    another code thats working with multiplexer but is NOT especially for piezos (i would prefere to use this sketch because its easy to edit and modify things, but it didn’t work with my piezo)

i know that theres another code thats working with piezos AND mux but (as far as i know) only with ONE multiplex.;

  1. https://forum.arduino.cc/index.php?topic=256333.msg1819216#msg1819216
    (saw you there;))
unsigned char PadNote[8] = {30,34,26,24,33,31,29,39};
unsigned char status;
int PadCutOff[8] = {200,200,200,200,200,200,200,250};
int MaxPlayTime[8] = {25,25,25,25,25,25,25,25};       
#define  midichannel 0;                 
boolean activePad[8] = {0,0,0,0,0,0,0,0};     
int PinPlayTime[8] = {0,0,0,0,0,0,0,0};             
boolean VelocityFlag  = true;
int pin = 0;
int hitavg = 0;
int pad = 0;
int r0 = 0;
int r1 = 0;
int r2 = 0;
int count = 0;
int multiplex[8];

void setup()
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

void loop(){

void readSensors (int analogPin) {
  for(count=0; count <= 7; count++)
    r2 = bitRead(count,0);
    r1 = bitRead(count,1);
    r0 = bitRead(count,2);
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    multiplex[count] = analogRead(analogPin);
void checkSensors (int analogPin)
  for(int pin=0; pin <=7; pin++)
    hitavg = multiplex[pin];
    if(hitavg > 200)
      if((activePad[pad] == false))
        hitavg = map(hitavg,0,1023,50,127);
        PinPlayTime[pad] = 0;
        activePad[pad] = true;
        PinPlayTime[pad] = PinPlayTime[pad] + 1;
    else if((activePad[pad] == true))
      PinPlayTime[pad] = PinPlayTime[pad] + 1;
      if(PinPlayTime[pad] > MaxPlayTime[pad])
       activePad[pad] = false;

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
  status = MESSAGE + midichannel;

To this sketch i want to know if theres any way to edit more multiplexer? I tried it out (loaded up to my arduino) but (surprise) only 8 from that 21 piezo worked :frowning:

Anyways thank you a lot for any ideas, advices or what ever :slight_smile:

and sorry for my bad english, i hope everythings understandable :slight_smile:

So the problem that i have is to find a code (as im not able to program by myself) that is working for my 21 piezos 3 mux MIDI drumpad,

That is the BIG problem. If you can not program then you can only ever do what other people do, and make the same errors as other people do.
We do not write code for you here but we do help you get it right. See http://forum.arduino.cc/index.php?topic=498033.0 for how to get code written for you.

So we can tell you want to do but we do not do it for you. Would you understand what to do if I told you?

Assuming it is wired up correctly ( we can not tell because you have not posted a schematic, only a Fritzing physical layout which is totally useless for checking a circuit ), then all you need to do is to put an address value on the three address pins of your multiplexer and then read analogue inputs 0, 1 and 3 to read three pads.

So write a function that reads a pad number passed to it and returns the value of that sensor. And call that function in place of the analogRead call. You also need to extend the array that hold the notes to be played for each pad. And change the #define of the word PADS.

However did you notice that some one on the comments to that video said that with a lot of sensors they can occasionally be missed? That is perhaps a result of the “high score” tracking that this program does.