How to Use a Vibration Sensor or Shake Switch with Arduino Uno

In this post we will look at how to use a Vibration Sensor (also known as a Shake Switch) with the Arduino Uno. A common Vibration Sensor or Shake Switch used with the Arduino Uno has a technical model number known as SW-18015P or SW-18020P. We can also refer to them as SW-180 series Vibrator Sensors or Shake Switches.

Vibration Sensor or Shake Switch SW-18015P / SW-18020P
Figure 1 - Vibration Sensor or Shake Switch SW-18015P / SW-18020P













As shown above, a Vibration Sensor or Shake Switch looks like a cylindrical capacitor in shape.

The Vibration Sensor or Shake Switch
Inside the Vibration Sensor or Shake Switch there is a complex mechnical spring system wound around a central shaft. The following diagram based on the SW-180 vibration sensor series datasheet depicts the working principle of a vibration sensor.

Working principle of a Vibration sensor or Shake switch
Figure 2 - Working principle of a typical Vibration sensor or Shake switch















The internal spring mounted system moves when the sensor is acted uopn by external stimuli. The resultant movement within the Vibration Sensor or Shake switch results in a change in electrical voltage. This change in voltage can be measured by any micro-controller unit such as an Arduino Uno. Let us see how in the next section.

Parts Needed for Vibration Senbsor or Shake Switch with Arduino
You will need the following items for using a Vibration sensor or Shake switch with the Arduino Uno:
  1. Arduino Uno R3 board
  2. USB-A to USB-B cable
  3. A SW-180 series vibration sensor or shake switch
  4. A breadboard
  5. Some jumper wires

The Breadboard Circuit for Vibration Senbsor or Shake Switch
The breadboard setup for connecting the vibration sensor with the Arduino Uno is shown below for reference.

Using Vibration Sensor (Shake Switch) with Arduino Uno
Figure 3 - Using Vibration Sensor (Shake Switch) with Arduino Uno


















The connection are explained below for easy understanding.

  1. Connect one leg of the vibration sensor or Shake switch with Arduino Uno's analog pin A5
  2. Connect the other leg of the vibration sensor or Shake switch with Arduino Uno's 5V power supply pin

The Arduino C Sketch for Vibration Senbsor or Shake Switch
After the circuit has been built, use the following C sketch to interface the Vibration sensor or Shake switch with the Arduino Uno. The main point to note here is that when the sensor does not vibrate then the analog values will be greater than 1022. So in order to react to vibration pay attention to the logic writen in the if statement below.

// variable to store analog value read from the vibration sensor
int sensorReading;
int sensorPin = A5;

void setup()

{
   Serial.begin(9600);
}

void loop()

{
   sensorReading = analogRead(sensorPin);

   // normally when nothing is vibrating or shaking

   // the sensor values on the analog pin A5
   // will be between 1023 to 1024
   if (sensorReading < 1022)
   {
      Serial.print("Things started moving: ");
      Serial.println(sensorReading);
   }

   // check every 5 seconds
   delay(5000);
}

Interesting Applications of the Vibration Senbsor or Shake Switch
The SW-180 series vibrations switch can be utilized for building some interesting real worl applictaions such as:
  1. Anti-theft alarms
  2. Monitoring moving machinery/equipment
  3. Instruments / Toys
  4. Sport Equipments
Conclusion
This is how a SW-180 series vibration switch or shake switch is interfaced with an Arduino Uno.
This example has multiple fundamentals such as: reading analog I/O, fundamentals of interfacing with sensors, using sensor datasheets, using the Serial Monitor for sketch debugging and so on. These and many other things have been covered in detail in my book "Learn Arduino Prototyping in 10 Days".


If you liked this post, then your encouragement by performing a G+ and a share is most welcome and highly appreciated!

No comments:

Post a Comment