0
\$\begingroup\$

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
}

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 100 is on the lower end of the full analog range of arduino, and can be just a noise. \$\endgroup\$ Commented Jan 23 at 16:45
  • \$\begingroup\$ the sensor does not have good contact with the table ... try taping it down \$\endgroup\$ Commented Jan 23 at 16:46

1 Answer 1

2
\$\begingroup\$

Here are some suggestions to improve your test setup.

  1. Look at the signal output on an oscilloscope. Without seeing the signal, you are flying blind. The important things to record are amplitude, frequency range, and duration of the signal.
  2. The sensor outputs voltage in response to strain, so you need to have good strain transfer from the structure to the sensor. Use epoxy to mount the sensor to the structure. The thinner the bond line the better. Thin double sided tape works, but epoxy will give you the strongest signal strength.
  3. You can build a mechanical amplifier for the signal:

Mechanical amplifier for a piezoelectric transducer

As you shake the table, you cause the weight to swing, which causes the sensor to strain. I first saw this in one of Forrest Mims III books from Radio Shack where he claimed to be able to detect a train passing by 0.8 km (0.5 miles) away.

  1. Change the resistance the sensor is seeing. By adding a resistor in parallel with the sensor you create a high pass filter with corner frequency: $$f = 1 / \left(2 \pi R C\right)$$ where R is the resistance and C is the capacitance (480 pF according to the datasheet). A 1 MOhm resistor will start to attenuate frequencies below about 330 Hz. Attenuation is good if the signal has a lot of low frequency junk that you are trying to remove. Attenuation is bad if that's where your signal is.
  2. Add a unity gain buffer between the transducer and the ADC. Piezoelectric transducers output their maximum voltage when connected to an infinite impedance. The ADC may be presenting too low of an impedance, and attenuating your signal.
  3. Reduce the cable length from the transducer to the Arduino. Cable capacitance attenuates the signal.
  4. You might need an electrical amplifier. Here is a simple circuit I've used before:

Electrical piezoelectric transducer amplifier

In this example I'm showing a transducer outputting 10 mV amplitude at 100 Hz. The circuit amplifies it fifty times, and adds a 2.5 V DC offset so you are in the center of the Arduino's ADC range. The first op-amp stage amplifies the signal one hundred times. The DC block removes any offset from the first stage. The summing circuit adds the offset to the signal, but attenuates by two in doing so. The down side of this circuit is that it requires a negative supply. I'm sure there is a more elegant way of doing this.

  1. Change the sensor to a piezoceramic one. The sensor you are using is inexpensive, but in general doesn't output much signal. A PZT sensor will output approximately ten times the signal strength.
\$\endgroup\$
1
  • \$\begingroup\$ This is very helpful, thank you very much for your feedback! I will follow up if I have any additional questions about what you have provided. Have a great day! \$\endgroup\$ Commented Jan 29 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.