Skip to content

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 LabelGPIO PinConnected Device
VIBGPIO4Vibration sensor digital output (DO)

JSON Configuration Example ​

json
{
  "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

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Vibration Alarm
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 3: Configure Trigger (Event Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Event TriggerRespond to interrupt events
    Event Type100GPIO interrupt event
    Event Sourcevibration_01Vibration sensor peripheral ID

Step 4: Configure Actions (3 actions required)

Action 1: Buzzer ON

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select HIGH
    • Target Peripheral: Select buzzer_gpio

Action 2: Delay 2 Seconds

  1. Click Add Action button again
  2. Fill in:
    • Action Type: Select Delay
    • Action Parameter: 2000

Action 3: Buzzer OFF

  1. Click Add Action button a third time

  2. Fill in:

    • Action Type: Select LOW
    • Target Peripheral: Select buzzer_gpio
  3. Click Save button

Detection Method Comparison ​

MethodPeripheral TypeAdvantageDisadvantage
Interrupt Triggertype: 18Fast response, power-efficientMay trigger multiple times
Polling Detectiontype: 11Simple and reliableUses CPU

Notes ​

  1. Sensitivity Adjustment: Some modules include a potentiometer for sensitivity adjustment
  2. False Triggers: At high sensitivity, wind and sound can trigger the sensor
  3. Interrupt Method Recommended: Use rising edge interrupt (type: 18) to avoid polling overhead
  4. Debouncing: A single vibration may produce multiple triggers; set a 1-2 second cooldown period

FastBee | fastbee.cn