Example 27: Vibration Sensor
About 1 min
Example 27: Vibration Sensor
Experiment Overview
A vibration sensor (SW-420) outputs a digital signal when vibration is detected, suitable for anti-theft alarms, collision detection, and similar applications. The sensor internally uses a spring-type contact that disconnects and outputs HIGH when vibration occurs.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| VIB | GPIO4 | Vibration sensor digital output (DO) |
JSON Configuration Example
{
"peripherals": [
{
"id": "vibration_01",
"name": "Vibration Sensor",
"type": 18,
"enabled": false,
"pins": [4],
"params": {}
}
]
}Peripheral Execution Linkage
Scenario: Vibration Alarm (Event Trigger)
Feature: Trigger buzzer alarm for 2 seconds when vibration is detected
Web UI Configuration Steps
Step 1: Ensure Buzzer Peripheral is Configured
- Peripheral ID:
buzzer_gpio - Type: GPIO Output
Step 2: Create Rule
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Vibration Alarm - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 3: Configure Trigger (Event Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Event Trigger Respond to interrupt events Event Type 100GPIO interrupt event Event Source vibration_01Vibration sensor peripheral ID
Step 4: Configure Actions (3 actions required)
Action 1: Buzzer ON
- Click Add Action button
- Fill in:
- Action Type: Select HIGH
- Target Peripheral: Select
buzzer_gpio
Action 2: Delay 2 Seconds
- Click Add Action button again
- Fill in:
- Action Type: Select Delay
- Action Parameter:
2000
Action 3: Buzzer OFF
Click Add Action button a third time
Fill in:
- Action Type: Select LOW
- Target Peripheral: Select
buzzer_gpio
Click Save button
Detection Method Comparison
| Method | Peripheral Type | Advantage | Disadvantage |
|---|---|---|---|
| Interrupt Trigger | type: 18 | Fast response, power-efficient | May trigger multiple times |
| Polling Detection | type: 11 | Simple and reliable | Uses CPU |
Notes
- Sensitivity Adjustment: Some modules include a potentiometer for sensitivity adjustment
- False Triggers: At high sensitivity, wind and sound can trigger the sensor
- Interrupt Method Recommended: Use rising edge interrupt (type: 18) to avoid polling overhead
- Debouncing: A single vibration may produce multiple triggers; set a 1-2 second cooldown period
