Vibrations Sensor

  1. Introduction:

This experiment demonstrates how to detect vibrations using a vibration switch module and a Raspberry Pi Pico microcontroller. The vibration switch module produces a digital signal that indicates the presence of a vibration or shock. The Raspberry Pi Pico reads this digital signal and displays a message on the console when vibration is detected.



  1. Scope:

The scope of this experiment includes:

  • Understanding how to interface a vibration switch module with a Raspberry Pi Pico.

  • Developing a simple program in both C and MicroPython to detect and report vibrations.

  • Learning to configure the necessary software and hardware setup.

  • Displaying real-time messages on the console upon vibration detection.





  1. Prerequisite:

3.1. Hardware:

  • Pico microcontroller

  • Vibration module

  • Breadboard

  • Jumper wires

  • USB cable (to connect the computer)

3 .2. Software:

  • Thonny Software(For micro python)

  • MicroPython firmware installed on Raspberry Pi Pico

  • ubuntu Terminal(For embedded C)

  • CMake,Pico SDK,GNU Arm Embedded Toolchain,WSL.



  1. Connection Details:

Vibration Module Output to GPIO 16 on the Raspberry Pi Pico.

Vibration Module Ground (GND) to Pico GND.

Vibration Module VCC to Pico 3.3V.

UART Serial Console: Use a micro-USB cable to connect the Pico to the PC, then open PuTTY and select the correct COM port and baud rate (115200).



  1. Working Principle:

The vibration switch module contains a vibration-sensitive mechanism that sends a high (1) signal when a vibration is detected and a low (0) signal when there is no vibration. The Raspberry Pi Pico reads this signal through its GPIO pin and prints "Vibration detected!" to the console when it reads a high signal.

vibration switch is a device that recognizes the amplitude of the vibration to which it is exposed and provides some sort of response when this amplitude exceeds a predetermined threshold value.

The switch response is typically an electrical contact closure or contact opening. The electrical contact may be either an electromechanical relay or solid-state device.

Vibration Switch Working Principle

Vibration Switch is working according to the pendulum switching principle.

A swinging permanent magnet holds a magnetic switch situated below in a particular position. Due to vibration, the magnetic field between Reed Switch and magnet changes.

Thus the switch is actuated resulting in the stoppage of the equipment. The responding sensitivity of the system can be changed by adjusting the gap between switch and magnet. Thus vibrations with amplitude below a set value can be suppressed.









  1. Application code:

  • MicroPython:

import machine

import time


# Define the GPIO pin for the vibration switch

vibration_pin = machine.Pin(16, machine.Pin.IN)


while True:

if vibration_pin.value(): # Check if vibration is detected

print("Vibration detected!")

time.sleep(0.1) # Add a small delay to reduce spamming the console


  • Embedded C:

#include <stdio.h>

#include "pico/stdlib.h"


// Define the GPIO pin where the vibration switch is connected

#define VIBRATION_PIN 16


int main() {

stdio_init_all(); // Initialize standard I/O

gpio_init(VIBRATION_PIN); // Initialize the vibration pin

gpio_set_dir(VIBRATION_PIN, GPIO_IN); // Set the vibration pin as input


while (true) {

if (gpio_get(VIBRATION_PIN)) { // Check if vibration detected

printf("Vibration detected!\n");

}

sleep_ms(100); // Add a small delay to reduce spamming the console

}


return 0;

}



  1. Hardware Image:



  1. Output:

On detecting vibration, the console displays:

Vibration detected!



  1. Video Demonstration:





  1. Appendix:

  • Common CMakeLists:

cmake_minimum_required(VERSION 3.12)


# Pull in SDK (must be before project)

include(pico_sdk_import.cmake)


project(pico_experiments C CXX ASM)


set(CMAKE_C_STANDARD 11)

set(CMAKE_CXX_STANDARD 17)


if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")

    message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")

endif()


# Initialize the SDK

pico_sdk_init()


add_compile_options(-Wall

        -Wno-format          # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int

        -Wno-unused-function # we have some for the docs that arent called

        )

if (CMAKE_C_COMPILER_ID STREQUAL "GNU")

    add_compile_options(-Wno-maybe-uninitialized)

endif()


# Hardware-specific examples in subdirectories:

add_subdirectory(expt_10_LCD)

  • CMakeLists:

cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)


project(Vibration_Detection C CXX ASM)

set(CMAKE_C_STANDARD 11)

set(CMAKE_CXX_STANDARD 17)


pico_sdk_init()


add_executable(Vibration_Detection main.c)

target_link_libraries(Vibration_Detection pico_stdlib)

pico_add_extra_outputs(Vibration_Detection)

  1. References:







Class Schedules:
# Topic Date & time Action

Curriculum

0% Completed (0/1)