class 11 · unit II · acoustic and vibration sensors
Sound and vibration: one physics, two sensors
A voice in the air and a fault in a motor are the same thing: something shaking back and forth. Today, how we catch both, and then we record them on the board.
Theory runs to slide 12; the lab is one block at the end (slides 13 to 16). Keep the INMP441 and MPU6050 in their bags until then.
last class
Every sensor is a chain. Today we follow two of them.
Today's two chains: air pressure → diaphragm → I2S, and acceleration → proof mass → I2C.
Two minutes. Take one exit ticket from Class 10 that named a datasheet number well.
Two experiments with your phone, before any board.
1 · hum
Open any free spectrum-analyser app. Hum a low note, then a high one. Watch the peak move.
Your voice is a pressure wave in air. The app shows its frequency.
2 · touch
Put the phone flat on a running laptop near its fan, or on a table while someone taps it. Watch the same app.
The laptop shakes; the table shakes. The phone's microphone and accelerometer both feel it.
Same picture, different medium. That is today's lesson in one minute.
Any spectrum or "frequency analyser" app works; ask one student to share their screen if the projector allows. If no one has an app, hum into the deck later in the lab instead.
A wave is something going back and forth. Only the medium changes.
Both are described by the same two numbers:
Hz
frequency · how often
size
amplitude · how strong
In air we usually measure pressure with a microphone. On a machine we usually measure acceleration with an accelerometer.
Which sensor you pick follows from two questions: what medium, and which frequencies?
Line thickness in the air drawing shows compression. Class 8's Fourier idea applies to both.
try it live · pick a task
Where does the task sit, and which sensor covers it?
task
Log scale, 0.5 Hz to 20 kHz. Sensor bands: MPU6050 accelerometer up to its 260 Hz filter setting; INMP441 about 60 Hz to 15 kHz per its datasheet; the wide-band vibration sensor and piezo bands are typical values that vary by part. Task frequencies are rough ranges.
microphones
Inside a MEMS microphone: a moving plate and a fixed one.
Sound pressure pushes the diaphragm. The gap to the back plate changes, so the capacitance changes.
A tiny amplifier and ADC inside the package turn that into numbers, sent out over I2S, a bus made for audio.
"MEMS" = micro-electro-mechanical systems: moving parts a fraction of a millimetre across, made like a chip. Phones carry several.
The diaphragm in the drawing moves continuously. Where the sound port sits (top or bottom of the package) depends on the part; the INMP441 module's port is on the board's underside or top depending on the breakout, so check yours before the lab.
Microphone datasheets speak in decibels. Five minutes on what that means.
dB = 20 × log10( amplitude ÷ reference )
change
amplitude
+6 dB
about 2×
+20 dB
10×
+60 dB
1,000×
Two references you will meet: dB SPL (relative to the quietest audible pressure) and dBFS (relative to the largest number the ADC can output, so it is always 0 or negative). Your lab prints dBFS.
A log scale again, like Class 2's bandwidth chart. The everyday levels are rough. 94 dB SPL is exactly 1 Pa, the standard test level on microphone datasheets.
read the datasheet
The INMP441, by the numbers that matter.
24-bit
output over I2S
sent in a 32-bit slot; the lab shifts it down
60 Hz–15 kHz
frequency response
speech fits easily; very low hums do not
61 dB
signal-to-noise ratio
how far a 94 dB sound sits above the mic's own hiss
−26 dBFS
sensitivity at 94 dB SPL
a 1 Pa tone reads 26 dB below full scale
120 dB SPL
acoustic overload point
louder than this and it distorts
L/R pin
channel select
tie to ground for the left channel, as in our wiring
Figures as given in the InvenSense INMP441 datasheet; confirm against your copy. Ask: is 60 Hz–15 kHz enough for keyword spotting at 16 kHz sampling? (Yes: we only keep up to 8 kHz anyway.)
vibration
Inside a MEMS accelerometer: a tiny mass on springs.
When the chip accelerates, the mass lags behind and the springs stretch. The gap between moving and fixed fingers changes, so the capacitance changes.
Same trick as the microphone: motion becomes capacitance becomes numbers. One structure per axis; the MPU6050 has three, plus a three-axis gyroscope.
Because gravity pulls on the mass too, a still accelerometer reads about 1 g. That is how it measures tilt (Class 13).
The mass in the drawing oscillates. Real structures are a few hundred micrometres across. A heavier mass and softer springs give more sensitivity but a lower usable frequency range.
Four ways to feel a machine shake.
sensor
strengths
limits
typical use
MEMS accelerometer
cheap, small, digital, also tilt
bandwidth often a few hundred Hz
gestures, falls, slow machinery
wide-band MEMS vibration
kHz bandwidth, low noise
costs more
predictive maintenance
piezo element
very cheap, very high frequencies
analog, needs conditioning
knocks, taps, glass break
microphone near the machine
very high frequencies, cheap
hears the whole room
acoustic fault detection
Contact sensors hear this machine. A microphone hears every machine in the room. That one difference often decides the design.
Ask which one the BrickML from Class 1 combined (vibration plus sound, among others).
Check the bandwidth before you trust the sensor.
The cheap IMU in our kit cannot see this fault at all, however good the model is. No amount of ML fixes a sensor that never recorded the signal.
Two limits stack up: the sensor's own bandwidth (its filter), and the sample rate you actually achieve (Nyquist, Class 8). The lab measures the second one.
The 260 Hz figure is the MPU6050's widest accelerometer low-pass filter setting in its register map; check your datasheet. This is Class 8's exit ticket made physical.
our running example
Should the doorbell hear a knock with its microphone, or feel it?
microphone · INMP441
Already there for the keyword. Hears knocks, but also traffic, rain and the neighbour's TV.
piezo on the door
Costs a few rupees, uses almost no power, and feels only this door. A threshold may be enough: no model at all.
Class 8's rule again: try the cheapest thing first. A sensor choice can remove the need for a model.
End of theory. Now hand out the microphone and IMU and move to the lab block.
lab · teams of four
Part A: hear the room. Part B: feel the table.
25:00
INMP441 pin
ESP32-S3
VDD
3V3
GND
GND
L/R
GND (left channel)
SCK (bit clock)
GPIO 15
WS (word select)
GPIO 16
SD (data)
GPIO 17
MPU6050 pin
ESP32-S3
VCC
3V3
GND
GND
SDA
GPIO 8
SCL
GPIO 9
Wire both now; they use different buses (I2S and I2C), so they do not conflict.
Pin choices: the S3 routes I2S to almost any GPIO; 15, 16, 17 avoid the strapping pins and the pins the N16R8's octal PSRAM uses. 8 and 9 are the Arduino-ESP32 default I2C pins on the S3. Confirm against your board's pin map before class; change the constants in the code if you rewire.
// Part A · INMP441 over I2S · loudness every 100 ms#include<ESP_I2S.h>// Arduino-ESP32 core 3.x
I2SClass i2s;
const int BCLK = 15, WS = 16, DIN = 17;
static int32_t buf[1600]; // 100 ms at 16 kHzvoidsetup() {
Serial.begin(115200);
i2s.setPins(BCLK, WS, -1, DIN);
if (!i2s.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_32BIT,
I2S_SLOT_MODE_MONO)) {
Serial.println("I2S failed"); while (1);
}
}
voidloop() {
size_t n = i2s.readBytes((char*)buf, sizeof(buf)) / 4;
double sum = 0;
for (size_t k = 0; k < n; k++) {
double v = (buf[k] >> 8) / 8388608.0; // 24-bit → ±1
sum += v * v;
}
Serial.println(20 * log10(sqrt(sum / n) + 1e-9)); // dBFS
}
lab · part A
Print loudness in dBFS.
Open the Serial Plotter. Stay silent for ten seconds, then talk, then clap.
Each line is the RMS level of 1,600 samples (100 ms). Expect negative numbers: 0 dBFS is the loudest the ADC can report.
No signal? Swap WS and SCK, check L/R is grounded, or try the other slot.
Uses the ESP_I2S library in Arduino-ESP32 core 3.x; on core 2.x the driver/i2s.h API differs, so test on the lab machines first. The INMP441 sends 24-bit samples left-aligned in 32-bit words, hence the shift by 8. If the readings are stuck near the floor, the data may be on the other channel: pass a slot mask, or tie L/R high and use the right slot.
// Part B · MPU6050 tap test · how fast can we really sample?#include<Adafruit_MPU6050.h>
Adafruit_MPU6050 mpu;
unsigned long t0; int count = 0;
voidsetup() {
Serial.begin(115200);
Wire.begin(8, 9); Wire.setClock(400000); // fast I2C
mpu.begin();
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setFilterBandwidth(MPU6050_BAND_260_HZ); // widest filter
t0 = millis();
}
voidloop() {
sensors_event_t a, g, t;
mpu.getEvent(&a, &g, &t);
Serial.println(a.acceleration.z); // m/s², gravity ≈ 9.8
count++;
if (millis() - t0 >= 5000) { // every 5 s
Serial.printf("# rate: %.0f samples/s\n", count / 5.0);
count = 0; t0 = millis();
}
}
lab · part B
Tap the table. Then measure your real sample rate.
Tap near the board and watch the spike decay. Then rest the board on a phone set to vibrate.
Every 5 s the sketch prints the samples per second you actually achieved. Half of that is the highest frequency you can see.
Uses the Adafruit MPU6050 library. The achieved rate is limited by I2C speed, the library and Serial printing, not just the sensor; that is the lesson. Try removing the println and printing only the rate to see how much printing costs.
lab · fill these six boxes as a team
Your measurements, not the datasheet's.
A · quiet room
noise floor, dBFS
A · talking
typical level, dBFS
A · clap
peak, dBFS; how many dB above the floor?
B · achieved rate
samples per second
B · highest visible frequency
rate ÷ 2, in Hz
B · verdict
could this setup catch a 300 Hz bearing fault? why?
Leave this up while teams work. Two teams read their numbers aloud at the end. The interesting disagreement is usually box 4: different teams get different rates from the same code.
exit ticket · on paper, before you leave
You must detect a failing water pump whose faults show up to 2 kHz. Which sensor family, what minimum sample rate, and why not the MPU6050 from today's lab?
Next class: visual and scene sensors. We will use the laptop webcam in Colab.
Answer: a wide-band vibration sensor (or a piezo with conditioning); sample above 4 kHz; the MPU6050's widest filter is 260 Hz and the rate they measured was far below 4 kHz.