How to use a Piezo element to detect vibration using Arduino

Summary of How to use a Piezo element to detect vibration using Arduino


This tutorial demonstrates using a piezoelectric element to detect vibrations such as knocks on a door or table. The piezo generates a voltage when deformed by vibrations, which an Arduino reads via analog input. When the signal exceeds a threshold, the Arduino sends "Knock!" to the serial monitor. A 1-megohm resistor is connected in parallel with the piezo for protection. Sensitivity can be adjusted by changing the threshold in the code. The piezo sensor is attached securely to a solid surface for effective detection.

Parts used in the Knock Sensor Project:

  • Arduino Board
  • Piezoelectric disc
  • 1 Megohm resistor
  • Solid surface (for mounting the piezo)

This tutorial shows you how to use a Piezo element to detect vibration, in this case, a knock on a door, table, or other solid surface.

Piezo element to detect vibration using Arduino

A piezo is an electronic device that produces a voltage when it undergoes physical deformation from a vibration, sound wave, or mechanical strain. Likewise, applying voltage to a piezo element causes it to vibrate and generate sound. Piezoelectric devices can be utilized for both producing tones and sensing tones.

The sketch utilizes the analogRead() command to interpret the piezos output, converting the voltage range of 0 to 5 volts to a numerical range of 0 to 1023 through analog-to-digital conversion (ADC).

When the sensor’s output exceeds a specific threshold, the Arduino will transmit the message “Knock!” to the computer through the serial port.

Access the serial monitor in order to view this text.

Circuit

Piezos are polarized, allowing voltage to flow through them (or out of them) in a particular orientation. Attach the low voltage black wire to the ground and the high voltage red wire to analog pin 0. Furthermore, add a 1-megohm resistor in parallel with the Piezo element to constrain the voltage and current generated by the piezo and safeguard the analog input.

Piezo elements can be obtained without a plastic enclosure. These will appear as a metal disc and are simpler to operate as input sensors. PIezo sensors are most effective when they are firmly pressed against, taped to, or glued to their sensing surface.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:

Piezo element to detect vibration using Arduino schematic

Code

In the code below, the incoming piezo data is compared to a threshold value set by the user. Try raising or lowering this value to increase your sensor’s overall sensitivity.

/* Knock Sensor
This sketch reads a piezo element to detect a knocking sound.
It reads an analog pin and compares the result to a set threshold.
If the result is greater than the threshold, it writes
“knock” to the serial port, and toggles the LED on pin 13.

Major Components in Project

Hardware Required

  • Arduino Board
  • (1) Piezo electric disc
  • (1) Megohm resistor
  • solid surface

For more detail: How to use a Piezo element to detect vibration using Arduino


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top