Easy Basics: Project 043d Vibration sensor module, LEDs, SD Card or Micro SD Card Module, active piezo bu

of Acoptex.com in UNO

Basics: Project 043d

Project name: Vibration sensor module, LEDs, SD Card or Micro SD Card Module, active piezo buzzer

Tags: Arduino, SW-420, Vibration sensor module, Piezoelectric, Piezo, Shake switch, Vibration switch, LED, KY-002, Vibration Shock sensor, Vibration knock sensor, 801S, SD card, micro SD card, SD card adapter, active piezo buzzer

Attachments: sketch

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables F-M, M-M

4. Vibration sensor (Vibration switch) module (there are a lot of variations) 1 pc

5. Breadboard any size 1pc

6. Resistor 200 Ohm-470 Ohm 2 pcs

7. LED (green and red) 2 pcs

8. Micro SD card with adapter 1 pc

9. SD card module 1 pc

10. Active piezo buzzer 1 pc


We will learn how to connect vibration sensor module, LEDs, active piezo buzzer and SD card module to Arduino board and log vibration data on SD card.

Many Applications can created by measuring Vibration level, but sensing vibration accurately is a difficult job.  The vibration sensor module is based on vibration switch component which can detect the weak vibration signals. The sensor can work for vibration-related modules.

A vibration switch is a device that recognizes the amplitude of the vibration to which it is exposed and provides some sort of response when this amplitude exceeds a predetermined threshold value. The switch response is typically an electrical contact closure or contact opening. The electrical contact may be either an electromechanical relay or solid-state triac.

The main principle of vibration switch is that, conductive vibration spring and trigger pin are precisely placed in switch ontology and bond to curing position through adhesive. Normally, the spring and the trigger pin do not contact. Once shook, the spring will shake and contact with trigger pin to conduct and generate trigger signals.

Let's check different types (analog and digital) vibration sensor modules. It can be also a modules with both signals (analog and digital).

Understanding the digital vibration sensor module

The vibration sensor SW-420 Comes with breakout board that includes comparator LM 393 and Adjustable on board potentiometer  for sensitivity threshold selection, and signal indication LED. This sensor module produce logic states depends on vibration and external force applied on it. When there is no vibration this module gives logic LOW output. When it feels vibration then output of this module goes to logic HIGH. The working bias of this circuit is between 3.3V to 5V DC. Its omnidirectional in nature meaning any angle can trigger the sensor.

Understanding the analog piezoelectric vibration sensor module

The Piezo Vibration Sensor is based on piezoelectric transducer. It is well known that  piezoelectric materials responds to strain (deflection) changes or applied force by generating a measurable output voltage.  This output voltage is proportional to the strength of shock or vibration.  So you can measure and characterize the vibration.


  • Working Voltage: 3.3V or 5V
  • Working Current: <1mA
  • Operating Temperature Range: -10 ℃ ~ + 70 ℃
  • Interface Type: Analog Output

Understanding the SD card module

You can read more about it here.

Understanding the piezo buzzer

You can read more about it here.

Signals and connections of active piezo buzzer

Active piezo buzzer pin marked with (+) sign should be connected to Arduino Uno board digital pin which sends a signal, the other pin of active piezo buzzer should be connected to Arduino Uno board GND.

Signals and connections of the SD card module

You can read more about it here.

Signals and connections of any vibration sensor module

VCC (5V or +)  - connect to 5V pin of Arduino board. 

GND (or G or -) - ground pin of Arduino board

S - can be digital signal output or analog signal output (depends on vibration sensor module - if digital module will be digital signal output, in other cases analog signal output

D0 (or Dout) - Digital output to Arduino board. Connect to digital Arduino pin

A0 (or Aout) - Analog output to Arduino board. Connect to analog Arduino pin.

The "A0", is a serial signal 0-5 volts that when no vibration it outputs 0 volts, when level of vibration very high, 5 volts. The "D0", is configured with the trim pot and is brought high when the vibration level reaches a desired point.

Connect the long leg of the LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the negative leg, called the cathode) to the GND. Resistor connected for long leg.

Build the circuit

SD card module -> Arduino Uno

VCC -> 3.3V or 5V (check module’s datasheet)

CS   -> 4 This can be the hardware SS pin - pin 10 (on most Arduino boards) or pin 53 (on the Mega) - or another pin specified in the call to SD.begin(). Note that even if you don't use the hardware SS pin, it must be left as an output or the SD library won't work. Different boards use different pins for this functionality, so be sure you’ve selected the correct pin in SD.begin().

MOSI -> 11

CLK   -> 13

MISO -> 12


Note: different Arduino boards have different SPI pins. If you’re using another Arduino board, check the Arduino SPI documentation.

The following picture shows the needed connections with the Arduino Uno 

1. If you have digital vibration sensor module

2. If you have analog vibration sensor module

3. If you have digital and analog vibration sensor module


The output can be a digital signal (D0) LOW or HIGH, depending on the amount of water on the surface. If the amount of water exceeds a certain predefined threshold value, the modules outputs LOW, otherwise it outputs HIGH. The threshold value for the digital signal can be adjusted using the potentiometer.

The output can be a analog signal and so you’ll get a value between 0 and 1023. Please note that the analog value returned will vary depending on what voltage is provided for the sensor.

In this code we create a loggingVibration() function function that we call in the loop() to log the moisture to the DATA.txt file in the SD card.

File Naming

FAT file systems have a limitation when it comes to naming conventions. You must use the 8.3 format, so that file names look like “NAME001.EXT”, where “NAME001” is an 8 character or fewer string, and “EXT” is a 3 character extension. People commonly use the extensions .TXT and .LOG. It is possible to have a shorter file name (for example, mydata.txt, or time.log), but you cannot use longer file names

Step by Step instruction

  1. Most SD cards work right out of the box, but it's possible you have one that was used in a computer or camera and it cannot be read by the SD library. Formatting the card will create a file system that the Arduino can read and write to. It's not desirable to format SD cards frequently, as it shortens their life span. You’ll need a SD reader and computer to format your card. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. See additional info here.
  2. Format the SD card as FAT16 or FAT32. Insert the SD card in your computer. Go to My Computer and right click on the SD card. Select Format...  
  3. A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.
  4. Insert the formatted SD card in the SD card module.
  5. Connect the SD card module and vibration sensor module to the Arduino Uno board.
  6. Open Arduino IDE.
  7. Plug your Adruino Uno board into your PC and select the correct board and com port
  8. Open up serial monitor and set your baud to 9600 baud
  9. Verify and upload the the sketch to your Adruino Uno board.
  10. When no vibration is detected, Vibration sensor output is 0 (low voltage),otherwise its output is 1(high voltage). If Arduino get 0 (no vibration) from vibration sensor it will turn on green LED and turn off Red LED. If Arduino get 1 from vibration sensor, it will turn on Red LED and turn off green LED.
  11. When the vibration level will be more then 100 (set threshold), it will turn on Red LED, active piezo buzzer and turn off green LED.
  12. Let this project run for a few hours to gather a decent amount of data, and when you’re happy with the data logging period, shut down the Arduino and remove the SD from the SD card module.
  13. Insert the SD card to a SD card reader connected to your computer (PC), open it, and you should have a DATA.txt file with the collected data.
  14. You can open the data with a text editor, or use a spreadsheet to analyse and process your data.


We have learnt how to connect vibration sensor module, LEDs, active piezo buzzer and SD card module to Arduino board and log vibration data on SD card.


  • SD library included in Arduino IDE
  • SPI library included in Arduino IDE


  • See attachments on the begining of this project description. 

Other projects of Acoptex.com
Easy Merry Xmas to everyone of Acoptex.com, Not selected 24-12-2019

Published at 12-11-2017
Viewed: 794 times