Sound and Vibration Sensors
Sound and vibration sensors detect sound waves, noise, impacts, knocks, mechanical vibrations, and oscillations.
They are useful in:
- Security systems
- Machinery monitoring
- Robotics
- Smart homes
- Industrial automation
- Noise monitoring
- Vehicle systems
- Earthquake/impact detection
- IoT monitoring
- Voice-controlled systems
Basic concept:
Sound / Vibration ↓ Sensor ↓ Electrical Signal ↓ Arduino / ESP32 ↓ Data Processing ↓ Alarm / Display / Action
1. What Is Sound?
Sound is a mechanical wave produced by vibrations and transmitted through a medium such as air.
For example:
Speaker ↓ Air vibrates ↓ Sound wave ↓ Microphone ↓ Electrical signal
A sound wave can be described using properties such as:
- Frequency
- Amplitude
- Wavelength
- Phase
2. Frequency
Frequency tells us how many cycles occur per second.
Unit:
Hertz (Hz)
For example:
100 Hz → 100 cycles/second
Higher frequency generally means a higher-pitched sound.
Low frequency → Low pitch High frequency → High pitch
3. Amplitude
Amplitude represents the magnitude of a wave.
For a sound signal:
Higher amplitude ↓ Stronger sound pressure
Simplified:
Low amplitude: ────╱╲────╱╲──── High amplitude: ───╱╲────╱╲────╱╲───
Amplitude is related to loudness, but perceived loudness also depends on frequency and human hearing.
4. Microphone Sensor
A microphone converts sound into an electrical signal.
Basic system:
Sound ↓ Microphone ↓ Electrical Signal ↓ ESP32 ↓ Processing
Microphones are used in:
- Voice recording
- Sound detection
- Voice assistants
- Noise monitoring
- Security systems
5. Electret Microphone
A common microphone component in electronics is the electret microphone.
A module may contain:
Microphone ↓ Amplifier ↓ Analog / Digital Output
A microphone itself generates a relatively small signal, so an amplifier is often used.
6. Sound Sensor Module
Common hobby sound sensor modules may provide:
VCC GND AO DO
Where:
AO= Analog OutputDO= Digital Output
Concept:
Sound ↓ Microphone ↓ Amplifier ↓ ┌──────────────┐ │ AO → Analog │ │ DO → Digital │ └──────────────┘
7. Digital Sound Detection
The digital output normally uses a threshold.
For example:
Sound level < threshold ↓ LOW Sound level > threshold ↓ HIGH
The threshold can often be adjusted using a potentiometer on the module.
8. ESP32 Sound Detection
Example:
#define SOUND_PIN 27 #define LED_PIN 2 void setup() { Serial.begin(115200); pinMode(SOUND_PIN, INPUT); pinMode(LED_PIN, OUTPUT); } void loop() { int state = digitalRead(SOUND_PIN); if (state == HIGH) { digitalWrite(LED_PIN, HIGH); Serial.println("Sound detected"); } else { digitalWrite(LED_PIN, LOW); } delay(50); }
The exact HIGH/LOW behavior depends on the particular sound module.
9. Analog Sound Measurement
Analog output provides a continuously changing signal.
Sound ↓ Microphone ↓ Amplifier ↓ Analog waveform ↓ ADC ↓ ESP32
Example:
#define MIC_PIN 34 void setup() { Serial.begin(115200); } void loop() { int value = analogRead(MIC_PIN); Serial.println(value); delay(10); }
This gives an ADC reading, but the raw ADC value is not automatically a calibrated sound-pressure level in dB.
10. Sound Waveform
A microphone output can resemble:
Voltage /\ /\ /\ / \ / \ / \ / \___/ \___/ \___ ──────────────────────────────→ Time
The ESP32 can sample this waveform.
From the sampled signal, software can calculate properties such as:
- Peak amplitude
- RMS level
- Frequency
- Approximate sound level
11. Sampling
When a microcontroller measures an analog sound signal, it takes samples.
Continuous sound ↓ ADC sampling ↓ ● ● ● ● ● ● ● ● ↓ Digital data
The sampling rate is the number of samples taken per second.
For example:
10,000 samples/second = 10 kHz sampling rate
12. Nyquist Principle
To properly represent a signal, the sampling rate generally needs to be greater than twice the highest frequency of interest.
Fs > 2 × Fmax
For example, if you want to analyze frequencies up to 5 kHz:
Fs > 10 kHz
In practical systems, additional margin and appropriate filtering are important.
13. Sound Frequency Detection
If you want to determine the frequency of a sound, you can analyze the sampled waveform.
For example:
Microphone ↓ ADC ↓ Samples ↓ Frequency analysis ↓ 1000 Hz
Techniques such as FFT (Fast Fourier Transform) are commonly used.
14. FFT
FFT converts information from the time domain into the frequency domain.
Time domain:
Amplitude ↑ │ /\/\ /\/\ /\/\ └────────────────→ Time
Frequency domain:
Amplitude ↑ │ █ │ █ └────────┼────────→ Frequency 1 kHz
This allows us to identify dominant frequencies.
15. Sound Level and Decibels
Sound levels are commonly expressed in decibels (dB).
A simplified sound-pressure-level relationship is:
SPL = 20 log10(p / p₀)
where:
p= measured RMS sound pressurep₀= reference sound pressure
For air, the commonly used reference is:
p₀ = 20 µPa
However, simply reading an Arduino microphone module's ADC value and labeling it "dB" is not automatically accurate.
A calibrated microphone and appropriate calibration procedure are needed for reliable SPL measurements.
16. Why Cheap Sound Modules Aren't Proper Sound Meters
A typical hobby sound module may provide:
Microphone + Amplifier + Comparator
Its output depends on:
- Microphone sensitivity
- Amplifier gain
- Supply voltage
- Circuit design
- Distance from sound source
- Frequency
- Environmental noise
Therefore:
ADC = 2500
does not universally mean:
70 dB
Calibration is required.
17. Vibration Sensors
A vibration sensor detects mechanical movement or oscillation.
Example:
Motor ↓ Mechanical vibration ↓ Vibration sensor ↓ ESP32
Vibration can indicate:
- Normal operation
- Imbalance
- Mechanical impact
- Loose components
- Bearing problems
- Machine faults
18. SW-420 Vibration Sensor
The SW-420 is a common hobby vibration sensor.
A typical module provides:
VCC GND DO
Inside, a vibration-sensitive mechanical element changes state when vibration occurs.
The module's comparator produces a digital signal.
Concept:
Vibration ↓ SW-420 ↓ Comparator ↓ Digital Output ↓ ESP32
19. SW-420 Example
#define VIBRATION_PIN 27 #define LED_PIN 2 void setup() { Serial.begin(115200); pinMode(VIBRATION_PIN, INPUT); pinMode(LED_PIN, OUTPUT); } void loop() { if (digitalRead(VIBRATION_PIN)) { Serial.println("Vibration detected"); digitalWrite(LED_PIN, HIGH); } else { digitalWrite(LED_PIN, LOW); } delay(50); }
The actual output polarity varies by module.
20. Piezoelectric Vibration Sensor
A piezoelectric sensor can generate an electrical signal when mechanically stressed or vibrated.
Concept:
Mechanical vibration ↓ Piezoelectric material ↓ Electrical signal
Piezo elements are commonly used for:
- Knock detection
- Vibration detection
- Impact sensing
- Acoustic pickup
- Buzzers
21. Piezo Sensor
A piezo disc can be connected to a suitable input circuit.
Conceptually:
Piezo ├── Signal └── Ground ↓ ADC ↓ ESP32
The generated voltage can sometimes be surprisingly high during sharp impacts, so the input circuit should be designed to protect the microcontroller.
Do not blindly connect an unknown piezo element to an ESP32 ADC without considering voltage limiting/protection.
22. Piezo Knock Sensor
A piezo sensor can detect a knock on a surface.
Knock ↓ Surface vibrates ↓ Piezo ↓ Voltage pulse ↓ ESP32 ↓ "Knock detected"
Applications:
- Smart doors
- Security systems
- Machine monitoring
- Interactive devices
23. Accelerometer for Vibration
An accelerometer measures acceleration.
Common sensors include:
- MPU6050
- ADXL345
- LIS3DH
A 3-axis accelerometer measures:
X-axis Y-axis Z-axis
Concept:
Z ↑ | ●────→ X / ↓ Y
24. Accelerometer vs Simple Vibration Sensor
| Feature | SW-420 | Accelerometer |
|---|---|---|
| Output | Usually digital | Digital data |
| Vibration detection | Yes | Yes |
| Direction | No | X/Y/Z |
| Magnitude | Limited | Measurable |
| Motion analysis | Limited | Excellent |
| Advanced analysis | No | Yes |
| Typical use | Simple alarm | Motion/vibration monitoring |
25. MPU6050 for Vibration
The MPU6050 contains:
- 3-axis accelerometer
- 3-axis gyroscope
The accelerometer can measure changes in acceleration.
Machine ↓ Vibration ↓ MPU6050 ↓ Acceleration data ↓ ESP32 ↓ Analysis
You can monitor vibration over time.
26. Vibration Monitoring
Suppose a motor normally produces:
Normal: Small vibration
Later:
Abnormal: Large vibration
The ESP32 can compare the measured value with a threshold.
Vibration < threshold ↓ NORMAL Vibration > threshold ↓ WARNING
27. Predictive Maintenance
Industrial machines can be monitored continuously.
Machine ↓ Vibration Sensor ↓ ESP32 ↓ Data Logging ↓ Trend Analysis ↓ Maintenance Alert
For example:
Day 1 → Normal Day 10 → Slight increase Day 20 → Higher Day 30 → Abnormal
A rising vibration trend can indicate a possible mechanical problem.
However, proper diagnosis requires suitable sensors, mounting, signal processing, and domain-specific analysis.
28. Sound + Vibration Monitoring
You can combine both sensors.
MACHINE / \ ↓ ↓ Microphone Accelerometer ↓ ↓ └────┬────┘ ↓ ESP32 ↓ Machine Status
For example:
Normal sound + normal vibration ↓ NORMAL Abnormal sound + high vibration ↓ WARNING
This can provide more information than using one sensor alone.
29. Sound-Activated Light
A simple project:
Clap ↓ Microphone ↓ ESP32 ↓ Relay ↓ Light
Example logic:
Clap detected ↓ Light ON Second clap ↓ Light OFF
For a reliable clap detector, software should distinguish a clap from continuous background noise.
30. Vibration Security Alarm
A vibration sensor can be attached to a door/window.
Window ↓ Vibration Sensor ↓ ESP32 ↓ Buzzer
If someone shakes the window:
Vibration ↓ Sensor triggered ↓ ESP32 ↓ Alarm
31. Machine Health Monitor
A practical IoT project:
MOTOR ↓ ┌───────────────┐ │ │ ↓ ↓ Microphone Accelerometer ↓ ↓ └───────┬───────┘ ↓ ESP32 ↓ Wi-Fi / Cloud ↓ Dashboard
The dashboard could show:
Motor Status: NORMAL Vibration: LOW Sound: NORMAL Temperature: 34°C
32. Sound Sensor vs Microphone
These terms are often confused.
Microphone
Primarily converts sound into an electrical signal.
Sound Sensor Module
Usually combines:
Microphone + Amplifier + Comparator
and may provide a simple digital trigger.
Therefore:
Detailed audio analysis ↓ Microphone + ADC/audio interface Simple sound detection ↓ Sound sensor module
33. Digital vs Analog Sound Sensors
Digital
Sound > Threshold ↓ HIGH Sound < Threshold ↓ LOW
Good for:
- Alarm
- Clap detection
- Simple triggering
Analog
Sound waveform ↓ Variable voltage ↓ ADC
Good for:
- Signal analysis
- Frequency detection
- Relative amplitude analysis
34. Common Problems
Microphone
- Background noise
- Poor placement
- Incorrect gain
- ADC noise
Sound Module
- Threshold incorrectly adjusted
- False triggering
- Not calibrated for dB measurement
Vibration Sensor
- False triggers
- Mechanical mounting issues
- Excessive sensitivity
Accelerometer
- Sensor orientation
- Sensor noise
- Sampling issues
- Mechanical resonance
35. Filtering
Real-world sensor signals contain noise.
Example:
Raw signal ────────╱╲─╱╲──╱╲─╱╲────
Filtering can produce:
Filtered signal ──────╱╲────╱╲──────────
Common filtering concepts include:
- Moving average
- Low-pass filter
- High-pass filter
- Band-pass filter
The correct filter depends on what signal you want to preserve.
36. Sound and Vibration Frequency
Frequency analysis is useful for machinery.
For example:
Machine vibration ↓ Accelerometer ↓ Sampling ↓ FFT ↓ Frequency spectrum
Suppose a strong peak appears at:
50 Hz
That tells you the vibration signal has a strong component around 50 Hz.
The meaning of that frequency depends on the machine, rotational speed, harmonics, and mechanical system.
37. Practical Project: Knock-Controlled Device
Components:
- Piezo sensor
- ESP32
- LED
- Relay
Flow:
Knock ↓ Piezo ↓ ESP32 ↓ Detect pulse ↓ Toggle output
Example:
Knock → Light ON Knock → Light OFF
This is a good project for understanding event detection.
38. Practical Project: Vibration-Based Theft Alarm
Object ↓ Vibration Sensor ↓ ESP32 ↓ Timer / Verification ↓ Buzzer ↓ Alarm
A good design should avoid triggering on every tiny vibration. You can require:
Several vibration events within a short time ↓ Trigger alarm
39. Practical Project: Noise Monitor
Microphone ↓ ADC / Audio Interface ↓ ESP32 ↓ Signal Processing ↓ Relative Sound Level
Display:
┌──────────────────┐ │ SOUND MONITOR │ │ │ │ Level: HIGH │ │ Status: WARNING │ └──────────────────┘
For accurate legal/industrial noise measurement, use a calibrated measurement system rather than an uncalibrated hobby microphone.
40. Comparison Table
| Sensor | Detects | Output | Typical Application |
|---|---|---|---|
| Microphone | Sound | Analog/audio | Voice/audio |
| Sound module | Sound level/event | Analog/digital | Sound trigger |
| SW-420 | Vibration | Digital | Simple alarm |
| Piezo sensor | Vibration/impact | Analog pulse | Knock detection |
| Accelerometer | Acceleration/vibration | Digital data | Machine monitoring |
| Gyroscope | Angular motion | Digital data | Motion/orientation |
41. Choosing the Right Sensor
Choose a microphone when:
You need an electrical representation of sound.
Choose a sound sensor module when:
You only need simple sound detection.
Choose a piezo sensor when:
You need impact or vibration detection.
Choose an SW-420 when:
You need inexpensive digital vibration detection.
Choose an accelerometer when:
You need vibration magnitude, direction, or detailed motion data.
42. Overall Concept
SOUND / VIBRATION ↓ ┌────────────┼─────────────┐ ↓ ↓ ↓ Microphone Piezo Accelerometer ↓ ↓ ↓ Sound Impact Acceleration ↓ ↓ ↓ └────────────┼─────────────┘ ↓ ESP32 ↓ Signal Processing ↓ ┌──────────────┼──────────────┐ ↓ ↓ ↓ Display Alarm IoT Cloud
Key Points
Sound → Mechanical wave that can be converted into an electrical signal. Microphone → Converts sound into an electrical signal. Frequency → Number of cycles per second, measured in Hz. Amplitude → Magnitude of the signal. Vibration Sensor → Detects mechanical vibration. Piezo Sensor → Converts mechanical stress/vibration into an electrical signal. Accelerometer → Measures acceleration and can be used for detailed vibration analysis. FFT → Useful for analyzing frequency components. dB → Common logarithmic unit for sound level, but accurate dB measurement requires appropriate calibration.