Build a Vibration Threshold Monitor
The Story
Machine-monitoring language can overpromise. This project stays educational: it measures acceleration magnitude and shows how a simple threshold behaves. This Golden version keeps the promise narrow: the parts list, code constants, GPIO table, expected output, safety notes, and troubleshooting all describe the same low-voltage educational build.
Explain Like I'm 12
The MPU6050 feels movement in three directions. The ESP32 combines those numbers into one movement size and turns on the alert when it is above the threshold. The ESP32 is the decision maker: it reads one signal, compares it with simple rules, then changes an output you can see or hear.
Learning Support
- Recommended ageAges 13+
- Adult supervisionAdult supervision required around moving objects; test with safe bench vibration only.
- Classroom useUseful for measuring acceleration magnitude and discussing thresholds versus certification.
- Parent promptAsk why one threshold cannot prove a machine is failing.
- Screen-free activityDraw a normal reading band and an alert reading band before running the code.
- Next challengeAdd averaging or hysteresis after recording real baseline readings.
- Skills practiced
- I2C sensor wiring
- Acceleration magnitude
- Threshold calibration
- False-trigger analysis
- Learning outcomes
- Read MPU6050 acceleration over I2C.
- Calculate magnitude from x, y, and z acceleration.
- Drive local alert outputs.
- Explain false triggers and calibration limits.
- Mini experiments
- Record still readings on the bench.
- Tap the board gently and watch the spike.
- Change THRESHOLD_M_S2 and compare alert behavior.
Safety Standards
- Unplug USB before changing jumper wires. Recheck 3.3 V, 5 V, and GND before reconnecting power.
- Do not power motors, pumps, LED strips, or servos from the ESP32 3.3 V pin. Use a suitable external supply and common ground.
- Breadboards are for low-current prototypes. Move high-current or unattended builds to proper terminals, enclosure, strain relief, and fusing.
What You Will Build
A bench vibration threshold monitor using an MPU6050 on I2C and local LED/buzzer outputs.
Learning Objectives
- Read MPU6050 acceleration over I2C.
- Calculate magnitude from x, y, and z acceleration.
- Drive local alert outputs.
- Explain false triggers and calibration limits.
Components List
- ESP32 DevKit boardUSB-programmable ESP32 board used as the controller.
- MPU6050 IMU module3.3 V I2C accelerometer/gyroscope module.
- Red and green LEDs with resistorsAlert and normal indicators on GPIO25 and GPIO26.
- Active buzzer moduleLocal alert on GPIO27; use a driver if current is high.
Bill of Materials
| Part | Qty | Estimated Cost | Notes |
|---|---|---|---|
| ESP32 DevKit board | 1 | Varies | USB-programmable ESP32 board used as the controller. |
| MPU6050 IMU module | 1 | Varies | 3.3 V I2C accelerometer/gyroscope module. |
| Red and green LEDs with resistors | 1 | Varies | Alert and normal indicators on GPIO25 and GPIO26. |
| Active buzzer module | 1 | Varies | Local alert on GPIO27; use a driver if current is high. |
Wiring
MPU6050 uses I2C on GPIO21/GPIO22 at 3.3 V. Alert outputs use GPIO25, GPIO26, and GPIO27.
-
1
Unplug USB before changing MPU6050 or output wiring.
-
2
Connect MPU6050 VCC to 3V3 and GND to GND.
-
3
Connect MPU6050 SDA to GPIO21 and SCL to GPIO22.
-
4
Tie AD0 to GND for address 0x68.
-
5
Connect red LED to GPIO25, green LED to GPIO26, and buzzer signal to GPIO27.
-
6
Reconnect USB and open Serial Plotter.
GPIO Mapping
| Signal | ESP32 Pin | Direction | Notes |
|---|---|---|---|
| MPU6050 SDA | GPIO21 | I/O | I2C data. |
| MPU6050 SCL | GPIO22 | Output | I2C clock. |
| Red/Green/Buzzer | GPIO25 / GPIO26 / GPIO27 | Output | Local alert outputs. |
Circuit Explanation
The ESP32 reads acceleration over I2C, calculates magnitude, and turns on the alert outputs if the value exceeds THRESHOLD_M_S2.
Engineering Explanation
A single magnitude threshold is a lesson, not predictive maintenance. Mounting, noise, gravity, and machine type all affect readings.
Libraries
- Adafruit MPU6050Install with Adafruit Unified Sensor.
- Adafruit Unified SensorDependency used by the MPU6050 library.
Code
Copy into Arduino IDE. Install any libraries noted in the component guides first.
// ESP32 Vibration Monitor - MPU6050 threshold demo
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
const int LED_R = 25;
const int LED_G = 26;
const int BUZZER = 27;
const float THRESHOLD_M_S2 = 15.0;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!mpu.begin()) {
Serial.println("MPU6050 not found - check SDA, SCL, 3V3, and GND.");
while (true) delay(10);
}
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(BUZZER, OUTPUT);
Serial.println("magnitude_m_s2");
}
void loop() {
sensors_event_t accel, gyro, temp;
mpu.getEvent(&accel, &gyro, &temp);
float ax = accel.acceleration.x;
float ay = accel.acceleration.y;
float az = accel.acceleration.z;
float magnitude = sqrt(ax * ax + ay * ay + az * az);
bool alert = magnitude > THRESHOLD_M_S2;
Serial.println(magnitude);
digitalWrite(LED_R, alert ? HIGH : LOW);
digitalWrite(LED_G, alert ? LOW : HIGH);
digitalWrite(BUZZER, alert ? HIGH : LOW);
delay(20);
}
Code Explanation
Wire.begin uses GPIO21 and GPIO22. The loop reads acceleration, computes magnitude, prints it, and drives GPIO25/GPIO26/GPIO27 from the threshold comparison.
Expected Output
Serial Plotter shows magnitude values around the still baseline and spikes when the module is moved. Values above 15.0 turn on red LED and buzzer.
Troubleshooting
- MPU6050 not found Check 3V3, GND, SDA GPIO21, SCL GPIO22, and AD0.
- Alerts never stop Record a still baseline and raise the threshold.
- Readings are noisy Secure the module and add averaging or filtering.
Common Mistakes
- Claiming predictive maintenance from one threshold.
- Powering MPU6050 from 5 V when the module is not 5 V tolerant.
- Using boot pins for alert outputs.
- Mounting the circuit on unsafe machinery.
Testing Checklist
- Confirm the sensor is detected.
- Record still readings.
- Tap gently and observe spikes.
- Change the threshold and repeat.
Engineering Tips
- Use Serial Plotter for calibration.
- Secure the sensor before comparing readings.
- Add hysteresis before driving real outputs.
Upgrade Ideas
- Add averaging or hysteresis.
- Log readings to SD card.
- Publish calibrated readings to MQTT.
Real-World Applications
- Vibration threshold lesson
- Bench machine demo
- Sensor-noise experiment
FAQs
Is this predictive maintenance?
No. It is a threshold-learning prototype.
Why use GPIO21 and GPIO22?
They are the common ESP32 I2C pins.
Why is gravity in the reading?
The accelerometer measures acceleration including gravity, so calibration matters.
Review, Testing, and References
Author: Abdul Mubeen and the ESP32 Engine editorial team. Last updated: 2026-06-27. Reviewed: wiring logic, Arduino code structure, beginner safety, and learning sequence.
Educational level: Intermediate. Estimated completion time: 75-90 min. This project is for learning and prototyping; production or unattended hardware needs additional engineering review.
Project Complete!
You completed ESP32 Vibration Monitor as a trustworthy ESP32 learning build with matching wiring, code, testing, and safety boundaries.
- I2C sensor wiring
- Acceleration magnitude
- Threshold calibration
