Overview
In this guide, we will build an Anti-Theft Alarm using Vibration Sensor & Raspberry Pi Pico with MicroPython Code. The Anti-theft alarm system works with the help of a Vibration Sensor installed in and around the vehicle. An impact or the movements inside the car activates the sensors. It, in turn, triggers the alarm system and sounds the alarm. Finally, the alarm goes off and alerts the owner/people.
In this project, the level signal of the vibration sensor is detected by the Raspberry Pi Pico. When vibration is detected, the buzzer is controlled to sound to achieve the effect of an anti-theft alarm. Earlier we made Laser Security System project using Raspberry Pi Pico.
Components Required
In this guide, I used Elecrow Raspberry Pi Pico Starter Kit to test different Modules. You can buy the kit and perform some other operations as well. From this kit, you can use the following components.
1. Raspberry Pi Pico Board – 1
2. Vibration Sensor – 1
3. Buzzer – 1
4. Breadboard – 1
5. Jumper Wires – 4
6. Micro-USB Cable – 1
Vibration Sensor
A vibration sensor also called a vibration switch, is a commonly used alarm detection sensor.
The switch is in the open-circuit OFF state when it is at rest. When it is touched by an external force and reaches the corresponding vibration, the conductive pin will generate instantaneous conduction and become an instantaneous ON state. When the external force disappears, the open-circuit OFF state will be restored.
Circuit Diagram & Connection
The connection diagram for interfacing the Vibration Sensor with Raspberry Pi Pico is given below.
Connect the VCC, GND & Digital Output Pin of Vibration Sensor Module to 3.3V, GND & GP0 Pin of Raspberry Pi Pico Board.
MicroPython Code/Program
Open your Thonny IDE & Copy the following code & paste it to the editor window.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from machine import Pin,PWM import utime vibrate = Pin(0, Pin.IN, Pin.PULL_UP) buzzer = PWM(Pin(14)) def playtone(frequency): buzzer.duty_u16(1000) buzzer.freq(frequency) def bequiet(): buzzer.duty_u16(0) if __name__ == '__main__': while True: if vibrate.value() == 0: for i in range(10) : playtone(555) utime.sleep_ms(50) bequiet() utime.sleep_ms(50) bequiet() |
Now you can run this code to test the working of the circuit. When you shake the circuit or even if a motion is detected by the Vibration Sensor, the alarm will turn ON.









