Build it step by step
0 of 7 doneWire the sensor
I2C to D4 and D5 and power from 3V3.
Build the motor driver
BC547 base through 1 kΩ to D2, collector to the motor negative, motor positive to 3V3, flyback diode across the motor.
Print the angle
Upload the code, open the serial monitor and lean forward to check the angle changes. Swap axes in readAngle if not.
Mount the sensor
Fix it flat on a clip or strip so it sits on your upper back.
Calibrate
Sit upright and press the button. The motor buzzes once to confirm.
Test
Slouch for a minute. After 60 seconds it vibrates three times, then waits two minutes before repeating.
Add the battery
Connect the LiPo to the XIAO pads and charge it over USB.
How do you build a posture reminder clip?
A clip on your back vibrates when you slouch for more than a minute while sitting. You need Seeed XIAO ESP32C3, MPU6500 6-axis IMU, Vibration motor (coin type), BC547 NPN transistor, Resistor 1 kΩ, Signal Diode 1N4148, Li-Po battery 3.7 V 500 mAh, Tactile push button 6 mm and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| MPU6500 VCC and GND | XIAO 3V3 and GND | Sensor supply |
| MPU6500 SDA | XIAO D4 | I2C data |
| MPU6500 SCL | XIAO D5 | I2C clock |
| BC547 base | XIAO D2 through 1 kΩ | Motor switch |
| BC547 emitter | GND | Return |
| BC547 collector | Motor - | Low-side switch |
| Motor + | XIAO 3V3 | Supply |
| 1N4148 across motor | Cathode on motor +, anode on motor - | Flyback protection |
| Calibrate button | XIAO D1 and GND | Set your upright position |
| LiPo battery | XIAO BAT+ and BAT- pads | Charges over USB |
Code
Arduino IDE with the ESP32 board package by Espressif, board "XIAO_ESP32C3". No libraries, the sensor is read over raw I2C. The angle formula depends on how the board is mounted, so print readAngle() on the serial monitor and swap the axes if the angle does not change as you lean.
Runs on a virtual Seeed XIAO ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
const byte MPU = 0x68, MOTOR = D2, BTN = D1;
float upright = 0; // angle recorded when the button is pressed
const float LIMIT = 15.0; // degrees of forward lean that counts as slouching
const unsigned long HOLD_MS = 60000UL; // lean this long before buzzing
unsigned long leanSince = 0, lastBuzz = 0;
int events = 0;
float readAngle() {
Wire.beginTransmission(MPU); Wire.write(0x3B); Wire.endTransmission(false);
Wire.requestFrom(MPU, (uint8_t)6);
int16_t ax = Wire.read() << 8 | Wire.read();
int16_t ay = Wire.read() << 8 | Wire.read();
int16_t az = Wire.read() << 8 | Wire.read();
return atan2((float)az, (float)ay) * 180.0 / PI; // forward lean when worn on the back; swap axes if your mounting differs
}
void buzz() { for (byte i = 0; i < 3; i++) { digitalWrite(MOTOR, HIGH); delay(200); digitalWrite(MOTOR, LOW); delay(150); } }
void setup() {
Serial.begin(115200);
pinMode(MOTOR, OUTPUT); pinMode(BTN, INPUT_PULLUP);
Wire.begin();
Wire.beginTransmission(MPU); Wire.write(0x6B); Wire.write(0); Wire.endTransmission(); // wake the sensor
delay(100);
upright = readAngle();
}
void loop() {
if (digitalRead(BTN) == LOW) { upright = readAngle(); buzz(); delay(500); }
float lean = readAngle() - upright;
if (fabs(lean) > LIMIT) {
if (leanSince == 0) leanSince = millis();
if (millis() - leanSince > HOLD_MS && millis() - lastBuzz > 120000UL) {
buzz(); lastBuzz = millis(); events++;
Serial.print("Slouch events: "); Serial.println(events);
}
} else leanSince = 0;
delay(200);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Sit upright | No vibration |
| Lean 20 degrees forward for one minute | Three pulses |
| Stay slouched | Another reminder only after two minutes |
| Press the button | One buzz and the upright angle resets |
If it does not work
Angle does not change
The axes are wrong for your mounting. Try atan2(ax, az) or atan2(ax, ay).
Motor does not vibrate
Check the BC547 pins and that the motor is on 3V3 and the transistor's collector.
Resets when the motor starts
The coin motor draws a surge. Add a 100 µF capacitor on 3V3.
Battery does not charge
The BAT+ and BAT- pads are swapped. Check polarity.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the posture reminder clip?
Seeed XIAO ESP32C3, MPU6500 6-axis IMU, Vibration motor (coin type), BC547 NPN transistor, Resistor 1 kΩ, Signal Diode 1N4148, Li-Po battery 3.7 V 500 mAh, Tactile push button 6 mm and Jumper wires male to male (40 pcs, 20 cm).
How long does the posture reminder clip take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the posture reminder clip works?
Sit upright: No vibration. Lean 20 degrees forward for one minute: Three pulses. Stay slouched: Another reminder only after two minutes.
Angle does not change: what should I check?
The axes are wrong for your mounting. Try atan2(ax, az) or atan2(ax, ay).
Motor does not vibrate: what should I check?
Check the BC547 pins and that the motor is on 3V3 and the transistor's collector.
Resets when the motor starts: what should I check?
The coin motor draws a surge. Add a 100 µF capacitor on 3V3.
Battery does not charge: what should I check?
The BAT+ and BAT- pads are swapped. Check polarity.
