Help Making Drum Controller With Arduino Nano & 16 Channel Multiplexer

You wiring diagram is fine for now. We can see what you did wrong. The important thing is that you fix the circuit.

How long is the signal from one of the piezo pads? Will your code get around to checking each one fast enough to catch it?

Also there should not be any need to guess about the multiplexer. Just test it independent of the piezo circuitry. Read the mux output digitally, scanning all addresses slowly to see if each input works.

You can just ground an input or connect it to Vcc, and confirm LOW and HIGH are coming through on each channel.

You should have such simple sketches available for each hardware thing you hang on this. A single sensor sketch to test the piezos and get the correct circuit confirmed in the absence of all the junk your real code will need to do.

When stuff breaks later, they come in handy.

a7

The circuit you posted had the 1M resistor in series with the signal, where as the one I posed had the 1M resistor in parallel across the load. This is not a conventional arrangement because the sensors produce a charge not a voltage.

It looks like whoever designed the circuit you are using did not know this.

Jim's circuit is virtually the same as mine, but mine has added protection with the FET and extra diodes. I built mine after many hours of testing and long term testing at exhibitions like Maker Fairs and the like. If you have an oscilloscope you would be able to see this difference in the signal.

I am not saying that Jims's designs will not work, it will. But I suspect it will not last as long as the circuit I posted. Some times these things can take a few months chipping away the Arduino before it gives up working.

You can get over a 100V from these sensors if they are not terminated correctly.

Hmm okayy i will try to use your circuits. but i have a question, i didnt find the 1N4868 signal diode anywhere. Only the 1N4148, is there any typo or things i didnt know :slight_smile:

hi thank for joining in, you can take a look at my code first

and i will try to test the multiplexer using your method.

is this code good enough??

// CD74HC4067 Multiplexer Test Sketch

// Control pins for selecting channels (S0, S1, S2, S3)
const int S0_PIN = 2;
const int S1_PIN = 3;
const int S2_PIN = 4;
const int S3_PIN = 5;

// Enable pin (EN). This pin controls whether the multiplexer is active.
// LOW = active (channels are connected), HIGH = inactive (all channels disconnected).
// Connect this to your Arduino's digital pin
const int EN_PIN = 6;

// The common SIG/COM pin of the multiplexer.
// Connect this to an analog input pin on your Arduino (e.g., A0)
const int MUX_OUT_PIN = A0;

void setup() {
  Serial.begin(9600); // Start serial communication for debugging output
  Serial.println("Starting CD74HC4067 Multiplexer Test...");

  // Set control pins and enable pin as OUTPUTs
  pinMode(S0_PIN, OUTPUT);
  pinMode(S1_PIN, OUTPUT);
  pinMode(S2_PIN, OUTPUT);
  pinMode(S3_PIN, OUTPUT);
  pinMode(EN_PIN, OUTPUT);

  // Set the multiplexer output pin as an INPUT
  pinMode(MUX_OUT_PIN, INPUT);

  // Activate the multiplexer (set EN_PIN to LOW)
  digitalWrite(EN_PIN, LOW);
}

void loop() {
  // Loop through all 16 channels (0 to 15)
  for (int channel = 0; channel < 16; channel++) {
    // Select the current channel
    // We use bitwise operations to set the S0, S1, S2, S3 pins based on the channel number.
    // S0 gets bit 0, S1 gets bit 1, S2 gets bit 2, S3 gets bit 3.
    digitalWrite(S0_PIN, (channel & 0x01));      // Check if the first bit is set
    digitalWrite(S1_PIN, (channel & 0x02) >> 1);  // Check if the second bit is set, then shift
    digitalWrite(S2_PIN, (channel & 0x04) >> 2);  // Check if the third bit is set, then shift
    digitalWrite(S3_PIN, (channel & 0x08) >> 3);  // Check if the fourth bit is set, then shift

    // Add a small delay to allow the multiplexer to stabilize after switching channels.
    // While the CD74HC series is very fast, a tiny delay doesn't hurt.
    delayMicroseconds(50); // 50 microseconds should be more than enough

    // Read the analog value from the selected channel
    int sensorValue = analogRead(MUX_OUT_PIN);

    // Print the channel number and the read value to the Serial Monitor
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(": ");
    Serial.println(sensorValue);

    // Pause for a moment before checking the next channel,
    delay(200); // 200 milliseconds
  }
}

and this is for testing the piezo :

// Analog pin where the piezo pad is connected
const int PIEZO_PIN = A0;

// Threshold for detecting knocks
const int KNOCK_THRESHOLD = 50; // Example initial value

void setup() {
Serial.begin(9600); // Start serial communication to see the output
Serial.println("Start Piezo Pad Test...");
}

void loop() {
// Read the analog value from the piezo pad
// When the piezo receives vibration/pressure, it generates a voltage.
// AnalogRead converts that voltage to a value between 0-1023.
int piezoValue = analogRead(PIEZO_PIN);

// Print the raw value from the piezo to the Serial Monitor
Serial.print("Piezo Value: ");
Serial.println(piezoValue);

// Detect a knock if the piezo value exceeds the threshold
if (piezoValue > KNOCK_THRESHOLD) {
Serial.println(">>> KNOCK DETECTED! <<<");
// Allow a short pause after detection to avoid double detection of a single knock
delay(100);
}

// Allow a short pause between readings for stability
delay(10);
}

yes i will fix my circuit, thank you :smiley:

i designed this circuit i combine yours with

is this fine? i have 2 design. one with the 1K resistor and one with 10K resistor

for the circuit to test the multiplexer this is what i get

you can see on the right side where the comment "Testing The Multiplexer" is placed

Try this link:

hmm okay it does says that there is diode 1N4868 but where to buy it? (i live in indonesia)

Sorry I have no idea, I am in an entirely different part of the world. I would get them from https://lcsc.com/ or
https://Alliexpress.com. I have had good luck with both but LCSC is a quality distributor. Hopefully you can order from as well, You need to be sure the diodes you use can handle the current involved. A simple 1N4002 or better may work. If it is for the gate protection of the MOSFET (2N7000) most any diode would work, schottky would be OK.

Hmm okay. But 1N4148 will also work right? Because its expensive to ship accross the world

Get rid of that, it is not needed and will only slow down the reading rate of the sensors. With a lot of sensors you need them to be as quick as possible to make sure you don't miss anything.

Although your Serial print debug messages are fine for initial debugging these will take a considerable time to complete. Also 9600 is very slow and will contribute to missing hits, so first set it to the fastest speed your serial monitor window will operate at. But in the end once the correct flow through the code is confirmed, these print statements should be commented out.

There is no way you can test the multiplexer until you get the first part of the code working because the signals will not last long enough to work.

It takes just under 0.1 mS to read an analogue signal once. You have 22 sensors to get round before you scan the array again, and you seem to read each one at least twice.

alright i will change that in the code but what about the circuits ?

should i use 115200 instead???

Yes

It's wrong

Yes that would help, but will it not go faster?

The first multiplexer looks fine, the second doesn't have any inputs to it to multiplex.

The difference between 1K and 10K will hardly make any difference.

the second one is for this

no i mean this circuits that i have updated

hmm alright but the circuit fine right? the one that has the piezo connected to the multiplexer?