Incorrect analog values when using piezo + potentiometer

Hello

I'm using an Arduino Pro Micro to send Midi notes when triggered by a piezo sensor.

When I'm connecting the piezo only with a defined threshold, everything works great.
(My analog input reads 0 when nothing is hit, and approx 400 when hit)

But when i'm connecting a potentiometer to adjust the threshold manually, my piezo analog input is never equal to 0 anymore, but always around 25% of the potentiometer value...

Why is that?
Am i supposed to add other components to "cancel" the potentiometer value ?

Here is my wiring :

And my code

#include <MIDIUSB.h>

const int potentiometer = A0;  
const int piezotrigger1 = A1;  

void setup() {
  Serial.begin(9600);  //debug
  pinMode(piezotrigger1, INPUT);
}

void loop() {
  int potentiometerValue = analogRead(potentiometer); 
  int piezo1Value = analogRead(piezotrigger1) * 100;

  Serial.println(potentiometerValue);
  Serial.println(piezo1Value);
  
  if (piezo1Value > 250) {
      noteOn(0, 60, 127);   
      MidiUSB.flush();
      noteOff(0, 60, 0);  
      delay(100);
  }
}

Thank you all very much for your help,

There is only one ADC on the Pro Micro. The usual approach when switching between analog inputs is to read each input twice, to cancel the charge on the input sampling capacitor left over from previous conversions.

Try adding a 0.1uF capacitor from A0 to ground.

Or try this to put some time between reads:

int potentiometerValue = analogRead(potentiometer); 
Serial.println(potentiometerValue);

int piezo1Value = analogRead(piezotrigger1) * 100;
Serial.println(piezo1Value);

BUT - There is another potential issue... You are only reading for an instant each time through the loop, and every program step takes some time. Even with noting else in the loop, the looping takes time and you can't read the analog input continuously.

If you are trying to sense a drum-hit you might miss the actual hit, missing it altogether or just picking-up some "ringing", etc.

And the print statements take more time than most things...

If you can get enough signal for a digital input, and interrupt may work better.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.