This tutorial is to design a smart alarm through a raspberry pi board and vibration sensor and buzzer alarm sensor.The vibration sensor will output high level voltage when it detect vibration and output low level voltage when no vibration. According to this feature, the raspberry pi check the level signal from vibration sensor,The buzzer sensor will alarm once receive the high level signal.To explore this character,you can install security alarm on your windows to prevent thieves from entering.


Experimental Parts

Raspberry Pi3 x1
Buzzer Alarm Sensor Module x1
Vibration Sensor x1
Breadboard x1
male to male jumper wire
male to female jumper wire


The vibration sensor and buzzer alarm sensor need to be used in this project.
The working volatage of vibration sensor is 3.3V-5V and this project use the 3.3V as power supply.When there is no vibration,it output low level voltage and the light signal turns on;When there is any vibration, it output high level voltage and the light signal turns off.
The schematic diagram is as follows:

Vibration Sensor module


The working volatage of buzzer alarm sensor is 3.3V-5V and this project use the 3.3V as well.When it receive low level voltage, the buzzer sensor will alarm;When it receive high level voltage,the buzzer sensor won't alarm.
The schematic diagram is as follows:
Untitled Sketch_vibration

Pay more attention to the anode and cathode, otherwise it would burnout your raspberry pi board and sensor.You can connect the GND of the sensor to OV, VCC to 3.3V. Connect the buzzer sensor to pinout20 (BCM No) and vibration sensor to pinout 21(BCM No).You could visit the article for your referenc if you want to learn more about the raspberry pi IO port : How to read Raspberry Pi i/o pin diagram (GPIO pin graph)


You could choose the connect the raspberry pi to monitor, or login in pi via SSH.

1)Write the code

Add new file named vibration.py under the /home/pi file path via nano editor (the name is arbitrary)

sudo nano vibration.py

Write the sample code in new file

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

class Sw40(object):
"""docstring for Senal"""
def __init__(self, pin , buzzer):
self.buzzer = buzzer