I am trying to use a piezoelectric sensor to detect vibrations on nearby bounces of a ball on my desk but I am having trouble getting the results I want. I am new to Arduino so it may be something super simply but I am having a hard time just getting the sensor to detect me bending/tapping/flicking the sensor, let alone specific bounces. The serial monitor is outputting a variety of values from 0 to over 100 and even showing a "Strike Detected" when it is just sitting there.
I have added an image of my setup, linked the exact piezo sensor I am using, and added the code I have been using below. I am using a 1M ohm resistor and alligator clips with jumper wires to connect the pins of the piezo sensor to my breadboard. Do I need a different piezo sensor for my use case? I am missing something super simple in the code or wiring setup? Any advice on how I can get this thing to work would be greatly appreciated!
Piezo Sensor: https://www.sparkfun.com/piezo-vibration-sensor-large.html
// Pin Definitions
const int piezoPin = A0; // Analog pin connected to the piezo sensor
// Threshold for detecting a strike
const int threshold = 100;
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int sensorValue = analogRead(piezoPin); // Read the piezo sensor value
// Print the sensor value to the Serial Monitor
Serial.println(sensorValue);
// Detect a strike if the sensor value exceeds the threshold
if (sensorValue > threshold) {
Serial.println("Strike detected!"); // Print a detection message
delay(100); // Debounce delay to avoid multiple triggers
}
delay(100); // Small delay for stability
}



100is on the lower end of the full analog range of arduino, and can be just a noise. \$\endgroup\$