Let's Workshop: Captive Spring Vibration Sensor Module


Here is a quick introduction to using the Keyes captive spring vibration sensor module. Hopefully it will provide you with the confidence to start monitoring that knocking noise coming from the walls.

This example will demonstrate the use of an Arduino UNO in monitoring a digital pin state as the module is shaken.

Components

Wiring

Wire the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.

Coding

The code consists of a definition, setup and loop. First the D2 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send the value to the serial monitor so that the value can be read on the screen.

Load the code below into the Arduino IDE and upload it to your board.

/*
  A simple program designed to setup and demonstrate us of a captive spring vibration sensor module. BDAA100007
  
  The program monitors the connected digital pin and outputs the value to the
  serial monitor.
  
  modified 16th August 2019
  by Sebastian Karam - Flux Workshop
*/
int digitalpin = 2; // define signal pin
int vibration; // define variable to store value read from pin
  
void setup() {
  pinMode(digitalpin, INPUT); // set the signal pin as an input
  Serial.begin(9600); // launch the serial monitor
  Serial.println("Flux Workshop Example");
}
 
void loop() {
  vibration = digitalRead(digitalpin);  // read the level on D2
  Serial.println((String)"State: " + vibration); // send the result to the serial monitor
}

Running

With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this instance, the sensor was held still then shaken wildly for a few moments. You will notice that the output goes low when the sensor is triggered.

What to try next?

  • Use the output to alert your controller when someone knocks on the door.
  • Attach to a washing machine to keep track of spin cycles.
Previous article Let's Workshop: Keyes LDR Sensor Module Black Version
Next article Let's Workshop: ACS712 30A Current Sensor Module

Leave a comment

* Required fields