Labs / Bipes + MicroPython / 7 Sensors: Enable Programs to "Perceive the World"

7.7 Shake your phone to wake the screen? Here’s how to detect minor vibrations! —— Ball-type vibration sensor module based on SW-520D

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Young makers, let's unlock a fun module that "reacts the moment you touch it" 🎮!

The vibration bracelets we usually use, the collision alarms of remote-controlled cars, and even the vibration alerts on mobile phones all rely on tiny devices capable of detecting vibrations behind the scenes.

Today, we’re going to get to know the module that can "capture the instant of vibration" — the ball-type vibration sensor module based on the SW-520D ✨ It enables the development board to detect: 👉 Is there any vibration right now? Is it being shaken?

1. Module Introduction

When we shake an object by hand, we can feel the vibration, but how does the development board "sense" it? That's exactly the job of the SW-520D ball-type vibration sensor module.

It is a switch-type vibration sensor: there is a metal ball inside the module. When the module is shaken or vibrated, the ball will roll and contact the internal electrodes, and the module will output a trigger signal; when stationary, the ball returns to its original position and the signal is cut off. Simply put, it is just like a "small switch triggered by vibration".

Compared with analog sensors, it has the following characteristics:

In graphical programming, these blocks are commonly used with ball tilt sensors:

In practical projects, it is often used for the following purposes:

Quick Science: What is a ball-type vibration sensor?

Inside the module, there is a metal ball and two electrodes. When stationary, the ball does not come into contact with the electrodes, and the module outputs a high level; when vibration occurs, the ball rolls and touches the electrodes, the circuit is connected, and the module outputs a low level. It is just like a "small switch controlled by the rolling of a ball" — simple yet sensitive!

2. Wiring Instructions

To make the development board "sense" vibrations, the first step remains the same — connect the module correctly!

7.7 Shake your phone to wake the screen? Here’s how to detect minor vibrations! —— Ball-type vibration sensor module based on SW-520D

We will connect the ball-type vibration sensor module based on SW-520D to the digital interface DIO0 of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 6

DIN

Sensor level signal input pin

Pin 7

NC

-

📌 Note

3. Example: Detect vibration and print a prompt

Experiment Objective: Detect vibrations in the environment in real time; print "Vibration detected!" on the terminal when the module is shaken or collided, and do not print anything when it is stationary.

Little Life Inspiration: The motion-sensing game controllers we use rely on similar sensors to detect shaking movements, so now let's make a tiny "shake-sensing detector" ourselves!

The graphical program is as follows:

7.7 Shake your phone to wake the screen? Here’s how to detect minor vibrations! —— Ball-type vibration sensor module based on SW-520D

Building Block Assembly Steps:

  1. infinite loop
    • Use the repeat while true block to make the program continuously detect the vibration status;
  2. Read vibration status
    • Use the read digital input block;
    • Select the pin connected to the sensor: Pin 14 / GPIO11;
  3. conditional judgment
    • Use the if not read digital input block (since it outputs a low level when vibrating, and not is used to identify the trigger state);
  4. Trigger Feedback
    • Add the print "Launch the ball" block when the condition is true;
    • Add delay 20 milliseconds block to avoid duplicate printing caused by slight vibration.

Experimental Effect:

📌 You can try: Stick the module to the table, tap the table with your hand, and see if it gets triggered!

Graphical blocks will be automatically converted into MicroPython code, and the running results will be displayed:

7.7 Shake your phone to wake the screen? Here’s how to detect minor vibrations! —— Ball-type vibration sensor module based on SW-520D

Directly importable building blocks:

Rolling ball vibration sensor module.xml 2 KB

Tips

  1. If no vibration is detected:
  • Check if the correct pins are selected (Pin 14 / GPIO11) and if the wiring is secure;
  • Try increasing the vibration amplitude, for example, shake the module vigorously;
  1. False trigger prevention:
  • You can increase the delay time (e. g., 300 milliseconds) to filter out minor jitter.
  1. Advanced Gameplay:
  • Pair it with LED building blocks, which will light up when shaken, to make a "vibration alarm light".

✨ Interactive Mini Quiz

  1. Think about it: Why do we use if not read digital input to detect vibration? What will happen to the program if we remove the not?
  2. Try this: Fix the module to a small cart, push the cart to let it hit an obstacle, and see if it can trigger the vibration detection!

Summary

  1. The ball-type vibration sensor based on SW-520D is a switch-type trigger module;
  2. It detects "whether there is vibration" through the rolling of internal ball bearings, rather than the intensity of the vibration;
  3. Outputs a low level when vibrating, and a high level when stationary;
  4. Through conditional judgment, interesting functions such as vibration alarm and interactive triggering can be realized.