Typically, vibration sensors detect vibrations based on mechanical or optical principles and can be used to measure, display, and analyze linear velocity, displacement, and acceleration. Although humans have a very weak ability to perceive vibrations, sensors can provide this vibration status data. This provides critical data for equipment maintenance, allowing timely repairs and maintenance before equipment failure. Given that some failures are costly and time-consuming, using vibration sensors to detect and pinpoint defects is a good way to reduce costs and increase efficiency.
The weak analog voltage generated by the vibration sensor can be converted to digital output through the analog input pins of Arduino. This project implements vibration detection through three different programs: Example One detects vibration first and then displays the vibration value through the Serial monitor; Example Two includes simple analog pin reading techniques and Pulse-in technology; Example Three controls three different LEDs, where if the vibration value of a certain LED pin exceeds a predefined vibration value, that LED lights up.
The project BOM is as follows: 12v adapter x1, Arduino Uno x1, Arduino Nano x1, 51-000923 vibration sensor x1, SW-420 vibration sensor x1, traffic LED module x1, panel board x1, Dupont wire several.
Among them, the AAC 51-000923 vibration sensor is made of a rectangular piezoelectric ceramic plate, which can convert collected vibrations into voltage output; or convert the voltage signal applied to it into vibration, that is, it vibrates when voltage is applied. The AAC 51-000923 is 43mm long, with red and black leads and a connector. Creative projects generally use Arduino, and if the connector is not needed, it can be cut off, connecting Arduino and other MCU boards simply through the two leads.
Connect the black wire of the vibration sensor to the GND pin of Arduino and the red wire to Pin A0, and the wiring is complete.
Next, let’s look at Example Code 1:
int vib_sensor = A0; int vib_data = 0;
void setup() { // put your setup code here, to run once:Serial.begin(9600);pinMode(vib_sensor, INPUT); }
void loop() { // put your main code here, to run repeatedly:vib_data = analogRead(vib_sensor); Serial.println(vib_data);delay(100);}int vib_sensor = A0; int vib_data = 0; void setup() { // put your setup code here, to run once:Serial.begin(9600);pinMode(vib_sensor, INPUT); } void loop() { // put your main code here, to run repeatedly:vib_data = analogRead(vib_sensor); Serial.println(vib_data);delay(100);}
Here, int vib_sensor = A0; indicates that the vibration sensor is connected to the analog pin A0 of Arduino. The void setup() function activates the serial port with a data rate of 9600. The void loop() function reads and stores sensor data and displays it via the Serial monitor.
We connect the Arduino to the laptop, upload the above code, and after uploading, open the Serial Monitor, ensuring the data rate is set to 9600. Try tapping the vibration sensor, and you will see the readings on the Serial Monitor change.
Next, let’s look at Example Code 2:
int vs = A0; // vibration sensorvoid setup(){ pinMode(led, OUTPUT); pinMode(vs, INPUT); Serial.begin(9600); }void loop(){ long measurement =vibration(); delay(50); Serial.println(measurement); if (measurement > 50){ digitalWrite(led, HIGH); } else{ digitalWrite(led, LOW); }}long vibration(){ long measurement=pulseIn (vs, HIGH); //wait for the pin to get HIGH and returns measurement return measurement;}
Here, pin A0 is also used, and the pulseIn() function is used to measure the high and low of the input signal during vibration, lighting up the LED if related vibrations are detected.
After uploading the code, open the Serial monitor, ensuring the data rate is set to 9600. Tap the sensor, and the Serial Monitor readings will start to change, returning to zero when stopped. However, this example can only detect medium to strong levels of vibration.
Finally, let’s look at Example Code 3:
Example 3 can detect vibration intensity, with green, yellow, and red LEDs indicating low, medium, and strong vibration levels respectively. The working voltage of these three LEDs is 5v, and no current limiting resistors are needed. The specific connections are as follows: _ The GND pin of the Traffic LED module connects to the Arduino; _ The red LED connects to pin 13 of the Arduino board; _ The yellow LED connects to pin 12 of the Arduino board; _ The green LED connects to pin 11 of the Arduino board.
int yellow_led = 12; int green_led = 11; int vs = A0; // vibration sensorvoid setup(){ pinMode(red_led, OUTPUT); pinMode(yellow_led, OUTPUT); pinMode(green_led, OUTPUT); digitalWrite(red_led, LOW); digitalWrite(yellow_led, LOW); digitalWrite(green_led, LOW); pinMode(vs, INPUT); Serial.begin(9600); }void loop(){ long measurement =vibration(); delay(50); Serial.println(measurement); if ((measurement > 50)&&(measurement < 1000)){ digitalWrite(green_led, HIGH); digitalWrite(red_led, LOW); digitalWrite(yellow_led, LOW); delay(100); } if ((measurement > 1000)&&(measurement < 4000)){ digitalWrite(green_led, LOW); digitalWrite(yellow_led, HIGH); digitalWrite(red_led, LOW); delay(100); } if (measurement > 4000){ digitalWrite(red_led, HIGH); digitalWrite(green_led, LOW); digitalWrite(yellow_led, LOW); } else{ digitalWrite(red_led, LOW); digitalWrite(yellow_led, LOW); digitalWrite(green_led, LOW); }}long vibration(){ long measurement=pulseIn (vs, HIGH); //wait for the pin to get HIGH and returns measurement return measurement;}
This is an upgraded version of Example 2, where the void loop() function defines the vibration values that light up the three LEDs.
▼
“SIA Vice President: Global Semiconductor Industry Outlook””
Click 👇 to watch the video below