Piezo Vibration Sensor Hookup Guide

Pages
Contributors: jimblom
Favorited Favorite 14

Introduction

Piezo sensors are flexible devices that generate electric charge when they’re stressed. This characteristic makes piezos an ideal solution for low-power flex, touch, and vibration sensing. In more advanced applications, piezos can be the foundation for energy harvesting. Piezo's are the perfect sensor for catching when your fridge is running or as the power source for energy harvesting shake-lights.

Piezo Vibration Sensor - Small Horizontal

Piezo Vibration Sensor - Small Horizontal

SEN-09198
$9.95
2
Piezo Vibration Sensor - Large

Piezo Vibration Sensor - Large

SEN-09196
$5.50
Piezo Vibration Sensor - Small Vertical

Piezo Vibration Sensor - Small Vertical

SEN-09199
$9.95
Piezo Vibration Sensor - Large with Mass

Piezo Vibration Sensor - Large with Mass

SEN-09197
$6.50

Piezo's have the potential to produce very large AC voltage spikes -- ranging upwards of ±50V. Because they produce such high voltages, large resistors are often used to “load down” the piezo sensor in vibration-sensing applications. Zener diodes can also be used to clamp voltages down to safe levels.

Suggested Materials

This tutorial serves as a quick primer on piezo vibration sensors, and demonstrates how to hook them up and use them. Beyond the sensor, the following materials are recommended:

Arduino Uno -- We'll be using the Arduino's analog-to-digital converter to read in the voltage produced by the piezo sensor. Any Arduino-compatible development platform -- be it a RedBoard, Pro or Pro Mini -- can substitute.

Resistor Kit -- To dampen the piezo sensor's AC voltage spikes, a large load resistor -- somewhere around 1MΩ -- is used. This resistor kit includes multiple 1MΩ's, in case you want to combine a few in series.

Breadboard and Jumper Wires -- The piezo sensor's legs are spaced by 0.2" and are breadboard compatible. We'll stick them and the resistor into a breadboard, then use the jumper wires to connect from breadboard to Arduino.

Resistor Kit - 1/4W (500 total)

Resistor Kit - 1/4W (500 total)

COM-10969
$8.95
189
Breadboard - Self-Adhesive (White)

Breadboard - Self-Adhesive (White)

PRT-12002
$5.50
48
SparkFun RedBoard - Programmed with Arduino

SparkFun RedBoard - Programmed with Arduino

DEV-13975
$21.50
50
Jumper Wires Standard 7" M/M - 30 AWG (30 Pack)

Jumper Wires Standard 7" M/M - 30 AWG (30 Pack)

PRT-11026
$2.45
20

Suggested Reading

Piezos are an great entry-level component for beginners, but there are still a few basic electronics concepts you should be familiar with. If any of these tutorial titles sound foreign to you, consider skimming through that content first.

Analog to Digital Conversion

The world is analog. Use analog to digital conversion to help digital devices interpret the world.

What is an Arduino?

What is this 'Arduino' thing anyway? This tutorials dives into what an Arduino is and along with Arduino projects and widgets.

Analog vs. Digital

This tutorial covers the concept of analog and digital signals, as they relate to electronics.

Alternating Current (AC) vs. Direct Current (DC)

Learn the differences between AC and DC, the history, different ways to generate AC and DC, and examples of applications.

Vibration Sensor Overview

Piezo vibration sensors come in a variety of shapes and sizes. Here is a selection from the SparkFun catalog:

Piezo Vibration Sensor - Small Horizontal

Piezo Vibration Sensor - Small Horizontal

SEN-09198
$9.95
2
Piezo Vibration Sensor - Large

Piezo Vibration Sensor - Large

SEN-09196
$5.50
Piezo Vibration Sensor - Small Vertical

Piezo Vibration Sensor - Small Vertical

SEN-09199
$9.95
Piezo Vibration Sensor - Large with Mass

Piezo Vibration Sensor - Large with Mass

SEN-09197
$6.50

Some piezo sensor's include weights at the end to help encourage vibration.

AC Voltage Source

Piezo sensors are unique because they produce an alternating current (AC) voltage when stressed, converting mechanical energy to electrical. If you hooked an oscilloscope up to a piezo sensor, you might see waveforms like this when the sensor shakes:

Piezo flicked, unloaded

The signals above were generated by simply inserting a large, weighted piezo into a breadboard and flicking it a few times. Note the voltage spikes are reaching almost +20V and -12V. Signals at that level have the potential to permanently damage a microcontroller's analog-to-digital converter (ADC) pins.

To dampen those voltage spikes, we have a few simple tricks up our sleeve. The easiest fix is to load the piezo with a large resistor. By placing a 1MΩ resistor in parallel with the sensor, for example, we can drop the voltage spikes down to safer levels.

Piezo sensor loaded with 1M, connected to ADC

In the graph above, the sensor is loaded with a 1MΩ resistor and connected to an Arduino ADC. The voltages spike between -0.5 and +5V are safely within the tolerable range of the ATmega328's I/O pins.

More complex piezo damping circuits might include zener diodes to clamp the voltage or op amps to buffer a signal, but this simple resistor-loading circuit is a good place to start.

Example Circuit

Using the 1MΩ load resistor dampening method described above, here's a simple example circuit demonstrating how to hook up the vibration sensor:

Piezo hookup example

The Piezo is grounded on one end, and a generated voltage is routed to the Arduino's A0 ADC pin. Reading the voltage at that pin should give us an idea of how much the piezo is moving.

Example Code

Here is a really simple Arduino example based on the circuit above. Copy and paste this into your Arduino IDE, then upload!

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

If you have not previously installed an Arduino library, please check out our installation guide.

language:c
/******************************************************************************
Piezo_Vibration_Sensor.ino
Example sketch for SparkFun's Piezo Vibration Sensor
  (https://www.sparkfun.com/products/9197)
Jim Lindblom @ SparkFun Electronics
April 29, 2016

- Connect a 1Mohm resistor across the Piezo sensor's pins.
- Connect one leg of the Piezo to GND
- Connect the other leg of the piezo to A0

Vibrations on the Piezo sensor create voltags, which are sensed by the Arduino's
A0 pin. Check the serial monitor to view the voltage generated.

Development environment specifics:
Arduino 1.6.7
******************************************************************************/
const int PIEZO_PIN = A0; // Piezo output

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  // Read Piezo ADC value in, and convert it to a voltage
  int piezoADC = analogRead(PIEZO_PIN);
  float piezoV = piezoADC / 1023.0 * 5.0;
  Serial.println(piezoV); // Print the voltage.
}

Once the circuit is set up and code is uploaded, open your serial monitor, and set the baud rate to 9600 bps.

You should be seeing 0.00's stream by endlessly. Try shaking the sensor to see the voltages go up.

Serial terminal

Your eye's probably aren't fast enough to catch all of those numbers change. You can either introduce a delay to the end of the loop (e.g. delay(250);), or you can view the output in the serial plotter, found in newer versions of the Arduino IDE. Open the plotter by going to Tools > Serial Plotter.

Serial plotter

Now, you can create oscilloscope measurements of your own! The graph helps demonstrate the piezo sensor's voltage spikes and ringing. Try flicking, shaking, or stomping the ground to see how those movements affect the measurements of the piezo sensor.

Once you've gotten a handle on that, you can find a "vibration threshold" that will fit your project needs and have your Arduino look for any measurements above that value to detect vibrations.

Resources and Going Further

For more information on piezoelectricity and piezo sensors, check out some of these resources:

Now that you've got your Arduino sensing those good vibrations, what kind of shake-sensing project are you going to start? Need some inspiration? Check out some of these related tutorials:

Wake-on-Shake Hookup Guide

A basic hookup guide for getting started with the SparkFun Wake-on-Shake. The board gives you the ability to put your project into hibernation until bumped or shaken awake using the ADXL362 accelerometer. This means you can design projects meant to stay inert for long periods of time, possibly even several years, depending on the battery type used to power the project.

MMA8452Q Accelerometer Breakout Hookup Guide

How to get started using the MMA8452Q 3-axis accelerometer -- a solid, digital, easy-to-use acceleration sensor.

LSM9DS1 Breakout Hookup Guide

A hookup guide for the LSM9DS1, which features a 3-axis accelerometer, 3-axis gyroscope, and 3-axis magnetometer. It's an IMU-in-a-chip!

Blynk Board Washer/Dryer Alarm

How to configure the Blynk Board and app to notify you when your washer or dryer is done shaking.