F85 Vibration sensor

In this example we are going to connect to vibration sensor.

This example is super easy after doing the infrared motion detection with the HC-SR501 in a previous example, since basically same code will work.

I found this sensor to be excellent, it gives readings when I expect it to and not readings when I don’t expect it to. And you can configure the sensitivity of it a bit with the settings screw on it.

We do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry PI.

Pieces we use are:

  • Raspberry PI 2
  • Cobbler and Cobbler cable
  • F85 Vibration sensor (They cost $5.18 Aliexpress for 10 pieces, ($0.52 a piece) where I got this one ,same one is about $5.99 a piece on Amazon)
  • Wiring PI Xojo module from Paul Lefebvre

First thing is connecting the sensor:

F85 vibration sensor
F85 vibration sensor

This sensor comes with good markings so its very easy to wire it.

  • (5V) Red is the 5V input – I always use red for the power input.
  • (GPIOX) Yellow is the Data pin.
  • (GND) Blue is the ground, I always use blue for ground.

Spec on this sensor is: 

  • The working voltage of 3.3V to 5V
  • Product no vibration, vibration switch is closed on state, the output terminal output low level, the green light is lit
  • Product vibration, the vibration switch instantaneous disconnection, output the output high level, the green light is not bright

Connecting to the Cobbler:

Make sure your Raspberry PI is not powered on when you do the connections.

Cobbler for Raspberry PI
Cobbler for Raspberry PI

GPIO Header

In my example then I have it connected as follows:

  • Red to pin 2 (5V)
  • Blue to pin 25 (GND)
  • Yellow to GPIO 5 which is pin 29.

The Xojo code:

I have a timer to poll the sensor. we set the timer up and the pin mode in the Window Open event.

Sub Open()
Const kVibrationSensorPin = 5
GPIO.PinMode(kVibrationSensorPin, GPIO.INPUT)
Timer1.Mode = Timer.ModeMultiple
Timer1.Enabled = true
End Sub

In the Timer.Action event I got the following code:

(If you want it more responsive then you can increase the cycles of the for loop)

Sub Action()
Dim i as Integer
Const kVibrationSensorPin = 5
for n as Integer = 1 to 10
i = GPIO.DigitalRead(kVibrationSensorPin)
if i = 1 then
Listbox1.AddRow "Shaking detected"
end if

End Sub

Thats all there is to it!

Einhugur technical blog that involves Xojo and Einhugur Xojo plugin related topics

%d bloggers like this: