Piezo Sensor keeps reading something

Hello, I'm very new to these electronic and hardware stuff but i wanted to try and make a drum controller (tatacon).
I followed a guide that used an Arduino Micro and figured a Pro Micro should work. guide mentioned a 3.3v but i bought a 5v. My piezo sensor keeps reading something so i tried testing in one by one and it apparently it picks up some reading. I tried using a 1M ohm resistor but i don't know where to connect it and i'm worried i might need to buy a new microcontroller with a 3.3v output.

Here's the code i tried using to test :

const int ledPin = 13;      // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100;  // threshold value to decide when the detected sound is a knock or not


// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin
int ledState = LOW;         // variable used to store the last LED status, to toggle the light

void setup() {
 pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
 Serial.begin(9600);       // use the serial port
}

void loop() {
  // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(knockSensor);    
 
  // if the sensor reading is greater than the threshold:
  if (sensorReading >= threshold) {
    // toggle the status of the ledPin:
    ledState = !ledState;  
    // update the LED pin itself:        
    digitalWrite(ledPin, ledState);
    // send the string "Knock!" back to the computer, followed by newline
    Serial.println("Knock!");        
  }
  delay(100);  // delay to avoid overloading the serial port buffer
}

When i connect the pro micro, the reading keeps saying "Knock!".
When i changed the code to some kind of value reading it either sends the highest value or just 0 then returns to 1023 and keeps going down until i press it again.

Any help would be very much appreciated

2 requests, please reply to both of them.

  1. Please post schematics.
  2. Please post a link to the sensor datasheet.

Which guide is that?

This tutorial gives an example of how to wire the sensor:

https://docs.arduino.cc/built-in-examples/sensors/Knock/

I'm so sorry for wasting you, @Railroader, and @jremington 's time.. I tried moving the power to GND and it worked flawlessly ? Thank you for trying to help. I did end up using the resistor by connecting the piezo sensor's negative and positive terminals with the resistor.

the arduino is a pro micro clone

If you're still curious the guide is :

As for the code :

Schematics (i really tried, i don't know if this is proper, sorry) :

Sensor datasheet? (again i'm new to this, sorry) :

Again thanks a lot for trying to help :folded_hands: :heart:

should i close this topic?

Glad you got it working!

The connections of the discs look strange. Please find out about datasheet and post it.

you mean the color?, i'll try find one that looks like mine


mine looks like this
I'm kinda lost?

That is a generic piezo buzzer disk, used in billions of devices, usually to make noise. What sorts of data are you looking for?

Tells me nothing, never played with them.
The piccture supplied by the OP was signed "+" resp "-" for the terminals and the polarity looked like wrong in the picture.

Tells me nothing but hopefully @jremington takes on the post.

You might try experimenting with a piezo disk sometime!

The piezo disk bends or distorts when voltage is applied, and conversely, voltage is generated when the disk is bent. The polarity is usually irrelevant.

The disks are essentially capacitors.

Lesson one is taken.

Outch. That's an unfamiliar territory,,,,

Now, how can the OP get ahead?

According to post #5, the problem is solved! The crude wiring diagram is correct.

Sh-t, I missed that!

Hi, @loltheoof123
Welcome to the forum.

Picture of a hand drawn schematic is better if you don't have CAD program.
Hand drawn is quicker and only needs pen(cil) and ruler, multi-colour diagrams can be confusing.
Cut and pasting images, due to resolution can cause reading problems to.

Tip, Unless necessary make all wires horizontal or vertical with right angle joints rather than diagonal lines.

It just takes practice and observation of some of the simple circuits to get the hang of it.

Tom.... :smiley: :+1: :coffee: :australia:

Ahh, now i know. Thanks.
I'll probably look into it soon.

Idk i messed ones with resistor and one without, apparently the resistor did something so i connected them all to resistors and it worked.