edit

Grove - Piezo Vibration Sensor

Grove-Piezo Vibration Sensor is suitable for measurements of flexibility, vibration, impact and touch. The module is based on PZT film sensor LDT0-028. When the sensor moves back and forth, a certain voltage will be generated by the voltage comparator inside of it. A wide dynamic range (0.001Hz~1000MHz) guarantees an excellent measuring performance. And, you can adjust its sensitivity by adjusting the on-board potentiometer with a screw.

Version

Product Version Changes Released Date
Grove - Piezo Vibration Sensor V1.1 Initial Jul 2014

Features

  • Standard grove socket
  • Wide dynamic range:0.1Hz~180Hz
  • Adjustable sensitivity
  • High receptivity for strong impact

Tip

More details about Grove modules please refer to Grove System

Platforms Supported

Arduino Raspberry Pi BeagleBone Wio LinkIt ONE

Caution

The platforms mentioned above as supported is/are an indication of the module's hardware or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Applications

  • Vibration Sensing in Washing Machine
  • Low Power Wakeup Switch
  • Low Cost Vibration Sensing
  • Car Alarms
  • Body Movement
  • Security Systems

Getting Started

Play With Arduino

Hardware

The Grove - Piezo Vibration Sensor outputs a logic HIGH when vibration was detected. We can use any of Arduino pins to read the data. Here is an example of Piezo Vibration Sensor controlling LED. When the vibration was detected, this sensor outputs a logic high signal (the sensitivity can be changed by adjusting the potentiometer), an LED lights up.

  • Step 1. Prepare the below stuffs:
Seeeduino V4 Base Shield Grove - Piezo Vibration
enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now
  • Step 2. Connect the module to the D2 of base shield using the 4-pin grove cable, we use digital pin13 on board LED as output.
  • Step 3. Plug the Basic Shield into Arduino.
  • Step 4. Connect Arduino to PC by using a USB cable.

Note

It may output low level even though originally output high level when you increase the threshold voltage by clockwise adjusting the potentiometer.

Software

  • Step 1. Copy and paste code below to a new Arduino sketch.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
const int ledPin=13;
void setup() {
    Serial.begin(9600);
    pinMode(ledPin,OUTPUT);
}

void loop() {
    int sensorState = digitalRead(2);
    Serial.println(sensorState);
    delay(100);
    if(sensorState == HIGH)
    {
        digitalWrite(ledPin,HIGH);
    }
    else
    {
        digitalWrite(ledPin,LOW);
    }
}
  • Step 2. The LED will be on when vibration is detected.

Play With Raspberry Pi (With Grove Base Hat for Raspberry Pi)

Hardware

  • Step 1. Things used in this project:
Raspberry pi Grove Base Hat for RasPi Grove - Piezo Vibration
enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now
  • Step 2. Plug the Grove Base Hat into Raspberry.
  • Step 3. Connect the Grove - Piezo Vibration Sensor to port 12 of the Base Hat.
  • Step 4. Connect the Raspberry Pi to PC through USB cable.

Note

For step 3 you are able to connect the piezo vibration sensor to any GPIO Port but make sure you change the command with the corresponding port number.

Software

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Download the source file by cloning the grove.py library.
1
2
cd ~
git clone https://github.com/Seeed-Studio/grove.py
  • Step 3. Excute below commands to run the code.
1
2
cd grove.py/grove
python grove_piezo_vibration_sensor.py 12

Following is the grove_piezo_vibration_sensor.py code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
from grove.gpio import GPIO


class GrovePiezoVibrationSensor(GPIO):
    def __init__(self, pin):
        super(GrovePiezoVibrationSensor, self).__init__(pin, GPIO.IN)
        self._on_detect = None

    @property
    def on_detect(self):
        return self._on_detect

    @on_detect.setter
    def on_detect(self, callback):
        if not callable(callback):
            return

        if self.on_event is None:
            self.on_event = self._handle_event

        self._on_detect = callback

    def _handle_event(self, pin, value):
        if value:
            if callable(self._on_detect):
                self._on_detect()

Grove = GrovePiezoVibrationSensor


def main():
    import sys

    if len(sys.argv) < 2:
        print('Usage: {} pin'.format(sys.argv[0]))
        sys.exit(1)

    pir = GrovePiezoVibrationSensor(int(sys.argv[1]))

    def callback():
        print('Detected.')

    pir.on_detect = callback

    while True:
        time.sleep(1)


if __name__ == '__main__':
    main()

Success

If everything goes well, you will be able to see the following result

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
pi@raspberrypi:~/grove.py/grove $ python grove_piezo_vibration_sensor.py 12
Detected.
Detected.
Detected.
Detected.
Detected.
Detected.
Detected.
Detected.
^CTraceback (most recent call last):
  File "grove_piezo_vibration_sensor.py", line 84, in <module>
    main()
  File "grove_piezo_vibration_sensor.py", line 80, in main
    time.sleep(1)
KeyboardInterrupt

You can quit this program by simply press Ctrl+C.

Play With Raspberry Pi (with GrovePi_Plus)

Hardware

  • Step 1. Prepare the below stuffs:
Raspberry pi GrovePi_Plus Grove - Piezo Vibration
enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now
  • Step 2. Plug the GrovePi_Plus into Raspberry.
  • Step 3. Connect Grove-Piezo Vibration to A0 port of GrovePi_Plus.
  • Step 4. Connect the Raspberry to PC through USB cable.

Software

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Git clone the Github repository.
1
2
cd ~
git clone https://github.com/DexterInd/GrovePi.git
  • Step 3. Excute below commands to detect the vibration.
1
2
cd ~/GrovePi/Software/Python
python grove_piezo_vibration_sensor.py

Here is the grove_piezo_vibration_sensor.py code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import time
import grovepi

# Connect the Grove Piezo Vibration Sensor to analog port A0
# OUT,NC,VCC,GND
piezo = 0

grovepi.pinMode(piezo,"INPUT")

while True:
    try:
        # When vibration is detected, the sensor outputs a logic high signal
        print grovepi.analogRead(piezo)
        time.sleep(.5)

    except IOError:
        print "Error"
  • Step 4. We will see the vibration display on terminal as below.
1
2
3
4
5
6
7
8
9
pi@raspberrypi:~/GrovePi/Software/Python $ python grove_piezo_vibration_sensor.py
1023
1023
1023
1023
18
17
18
17

Note

We also can use grovepi.digitalRead(2) to read the vibration status with attaching the sensor to D2 port of GrovePi.

Resources

Projects

Grove Starter Kit For Arduino - Piezo Vibration Sensor: Teaches you how to use the Piezo vibration sensor in the Arduino Grove starter kit.

Seat Monitor: Using ARTIK cloud to monitor cabin seat state.

Tech Support

Please submit any technical issue into our forum.