Labs / Electronic modules

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.4 · License: CC BY 4.0 · Driver code (sensors/vibration_driver): MIT License

Contents
GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)
GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

I. Module Introduction

Spring-type vibration sensor module based on SW-18010P whose core component is SW-18010P, a sealed spring-type non-directional vibration trigger switch. It internally consists of a spring wound from thin pins and a thick pin. At rest, the spring is separated from the thick pin, keeping the switch in an " open circuit (OFF)" state; when subjected to external vibration (collision, shaking), the spring makes instantaneous contact with the thick pin due to resonance, turning the switch " conductive (ON)" and outputting a low level; after the external force disappears, the spring resets and the switch returns to the open circuit state.

Its key features include:

The relationship and working principle among vibration switches, ball switches and spring switches:

Vibration switch is a general term, which is mainly divided into two categories in the industry: spring switches and ball switches. A spring switch realizes the on-off of the circuit through the deformation of its internal spring caused by vibration force to contact with or separate from the pins, which is suitable for vertical installation and focuses on detecting the magnitude of vibration force. A ball switch makes the metal ball roll to conduct the circuit through angle change, which is suitable for flat installation and focuses on detecting the tilt angle. The two together constitute a vibration sensing element that converts vibration or angle signals into electrical signals by means of mechanical structure displacement.

Common vibration switches SW series fall into two categories:

  • SW-18xxx Spring-loaded vibration switches (e. g., SW-18010P, SW-18015P, etc.):
    • Inside the component, there is a thin metal spring and a central electrode, which are separated under normal conditions; when vibration occurs, the spring shakes to come into contact with the electrode, thus realizing on/off switching.
    • Features: High sensitivity, capable of detecting slight vibrations, but prone to generating jitter signals.
  • SW-20xx Ball-type vibration switches (e. g., SW-200D, SW-200DR, etc.):
    • Inside the device, there is a small metal ball placed in a cylinder; when subjected to vibration, the ball moves to come into contact with the electrode.
    • Features: Relatively low sensitivity, but more stable triggering and better anti-jitter performance.

👉 So the SW-18010P you asked about belongs to the spring-switch type vibration sensor.

This section of knowledge is referenced from: Understanding the Relationship and Working Principles Among Vibration Switches, Ball Switches, and Spring Switches.

II. Introduction to Major Chips

This module mainly relies on SW-18010P sealed spring-type non-directional vibration-sensing trigger switch to achieve signal changes.

2.1 Chip Overview

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)
GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

2.2 Pin Definition

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

2.3 Functional Block Diagram

None.

2.4 Performance Parameters

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

2.5 Reference Circuit

None.

2.6 Chip Configuration

None.

None.

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the source project of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_Spring-Type Vibration Sensor Module Based on SW-18010P_v1.1_2025-09-21.pdf 2.2 MB

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)
GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

This module uses digital output DIN: when stationary DIN outputs a high level, and when vibrating DIN outputs a low level.

It also features a dual-indicator design: the power indicator (LED1) staying on indicates the module is powered on; the vibration indicator (LED2) being on indicates vibration is detected.

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

The module is based on SW-18010P as the core, and cooperates with components such as voltage comparator LM393, indicator light, filter capacitor, etc. , to convert mechanical vibration into stable electrical signal output. The overall circuit is divided into the following parts:

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and connect the spring-type vibration sensor module based on SW-18010P to communicate with the main controller via the DIO interface.

Here, we first use the HY2.0-4P connection cable to connect the module to the GraftPort-RP2040 development board's DIO0 interface:

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 6

DIN

Sensor level signal input pin

Pin 7

NC

-

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

Enter the spring_vibration_driver to search, as shown below:

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

Click to copy the local installation command:

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

Here, we can use the mip tool to import module driver library code. The following are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/sensors/spring_vibration_driver

After importing the vibration sensor module - MicroPython driver code, copy the following main.py code into our project:

# MicroPython v1.23.0
# -*- coding: utf-8 -*-   
# @Time    : 2025/8/23 PM 4:08
# @Author  : 缪贵成
# @File    : main.py
# @Description : Rolling ball vibration sensor driver test file

# ======================================== Import Related Modules ==========================================

import time
from machine import Pin
from vibration_sensor import VibrationSensor

# ======================================== Global Variables =============================================

# ======================================== Functions ==============================================

def vibration_callback() -> None:
    """
    Vibration callback function, triggered when vibration is detected.

    Notes:
        This function is triggered by an interrupt and scheduled for execution through micropython.schedule.

    ==========================================

    Vibration callback function, triggered when vibration is detected.

    Notes:
        This function is called from interrupt, scheduled via micropython.schedule.
    """
    print("Vibration detected callback triggered!")

# ======================================== Custom Classes =============================================

# ======================================== Initialization Configuration ============================================

# Power-up delay to ensure hardware stability
time.sleep(3)
print("FreakStudio: Vibration Sensor Test Start")
# Initialize the vibration sensor, GPIO pin 6 as input, handled by the callback function
sensor = VibrationSensor(pin=Pin(6), callback=vibration_callback, debounce_ms=10)
sensor.init()
print("Sensor initialized with callback and debounce 50ms.")

# ======================================== Main Program ===============================================

try:
    start_time = time.ticks_ms()
    while True:
        # Poll to read the sensor status
        current_state: bool = sensor.read()
        print(f"Current vibration state: {current_state}")

        # Print the status dictionary every 2 seconds
        if time.ticks_diff(time.ticks_ms(), start_time) > 2000:
            status: dict = sensor.get_status()
            print(f"Sensor status: {status}")
            start_time = time.ticks_ms()

        time.sleep(0.2)

except KeyboardInterrupt:
    # Exit on user interrupt
    print("KeyboardInterrupt detected. Exiting test...")

finally:
    # Safely release resources
    sensor.deinit()
    print("Sensor deinitialized. Test completed.")

Burn the code, open the terminal, and use the mpremote tool to connect to the main controller. The output is as follows:

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)

It can be seen that when we tap the sensor gently, the relevant interrupt callback function will be triggered continuously:

IV. Drivers

spring_vibration_driver.zip 11 KB

None.

VI. Revision History

Document Version

Date of Modification

Modifier

Modified Content

v1.0

2025-08-31

Hou Junhan

Ling Gaoxing

Initialize the document

v1.1

2025-09-21

Li Zisheng

Added PCB routing precautions for Version 2.8

Revised Section 3, Instructions for Circuit Source Project and Module Usage, and added a secondary heading:

3.1 Circuit Source Engineering, 3.2 Module Usage Instructions, 3.3 Application Experiments

The BOM sheet has not been finally checked, the driver has not been re-verified, and the 3.3 application experiment

Not yet specified.

v1.2

2025-12-29

Li Zisheng

Added application experiments and production files

v1.3

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.2.

v1.4

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

SW-18010P Vibration Switch.pdf 1.1 MB

7.1 Unique Icons for PCB Silk Screen

GraftSense - Spring-type Vibration Sensor Module Based on SW-18010P (Open Version)