Example Code for Arduino-Vibration Detection
Last revision 2025/12/29
In this tutorial, we'll show you the sensor usage. Watch the serial monitor and LED "L" state.
Hardware Preparation
- DFRduino UNO x1
- Flexible Piezo Film Vibration Sensor x1
- M-M/F-M/F-F Jumper wires
Software Preparation
- Arduino IDE, Click to Download Arduino IDE from Arduino®
Wiring Diagram
Note: Turn the switch to "D" side
Other Preparation Work
Note: The sensitivity potentiometer control the output threshold. When it rotates towards "MAX" direction, it need more swing to trigger sensor.
Sample Code
/*!
* @file piezoVibrationSensor.ino
* @brief This example The sensors detect vibration
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author linfeng([email protected])
* @version V1.0
* @date 2016-02-26
*/
#define sensorPin A1
#define ledPin 13
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
}
void loop()
{
int x = analogRead(sensorPin);
Serial.println(x);
if (x > 500)digitalWrite(13, HIGH);
else digitalWrite(13, LOW);
delay(50);
}
Result
Was this article helpful?
