Quantcast
Channel: SparkFun Tutorials
Viewing all articles
Browse latest Browse all 1123

Piezo Vibration Sensor Hookup Guide

$
0
0

Piezo Vibration Sensor Hookup Guide a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t515

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 - Large with Mass

SEN-09197
$2.95

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.

SparkFun RedBoard - Programmed with Arduino

DEV-12757
$19.95
94
Resistor Kit - 1/4W (500 total)

COM-10969
$7.95
89
Breadboard - Self-Adhesive (White)

PRT-12002
$4.95
24
Jumper Wires Standard 7" M/M - 30 AWG (30 Pack)

PRT-11026
$1.95
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 device interpret the world.

What is an Arduino?

What is this 'Arduino' thing anyway?

Analog vs. Digital

This tutorial covers the concept of analog and digital signals, as they relate to electronics. It will discuss what each signal looks like, where each type of signal are prevalent, and some examples of analog and digital electronic components.

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 - Large

SEN-09196
$2.95
Piezo Vibration Sensor - Large with Mass

SEN-09197
$2.95
Piezo Vibration Sensor - Small Vertical

SEN-09199
$2.95
Piezo Vibration Sensor - Small Horizontal

SEN-09198
$2.95
1

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 (or use Codebender), then upload!

NOTE: For this example, we're hosting the code on codebender, which not only features code-sharing, but also allows anyone to upload and debug Arduino sketches from within a web browser. Plus, it works on lower-tech machines, like Chromebooks!

There are codebender plugins for Chrome, Chromium, and Firefox. Visit the codebender plugin page for help installing the codebender plugin.

Once the circuit is set up and code is uploaded, open your serial monitor, and set the baud rate to 9600 bps. Or, you can use the embedded serial monitor below.

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.

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.

learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado


Viewing all articles
Browse latest Browse all 1123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>