
Get full C++ & Python code + lifetime access
The ESP32 BLE Motion & Surface Mouse is an embedded human-interface project that converts an ESP32 microcontroller into a standalone Bluetooth Low Energy (BLE) Human Interface Device (HID) using an MPU6050 6-axis inertial measurement unit and tactile switches.
The system acts as a standard wireless mouse without needing custom receiver dongles, companion software, or mobile applications. When powered, the ESP32 broadcasts a standard BLE HID peripheral profile. Any host device—including Android smartphones, iPhones, Windows PCs, Linux workstations, or MacBooks—can pair directly via system Bluetooth settings.
The firmware reads high-speed angular velocity (gyroscope) or linear acceleration forces from the MPU6050 over an I2C bus running at 400 kHz. These inertial vectors are conditioned through zero-motion hardware calibration offsets, filtered through a software deadzone to eliminate stationary cursor jitter, scaled for target sensitivity, and transmitted as HID mouse delta packets (move(x, y)) alongside debounced hardware click events.
This project introduces:
BleMouse.h)Wire.h)0x6B Power Management)MPU6050.h)INPUT_PULLUP)ESP32 Development Board (30-pin or 38-pin Dev Module) × 1
MPU6050 6-Axis Accelerometer / Gyroscope Module × 1
Tactile Pushbuttons (Momentary, 2-pin or 4-pin) × 2
Half-Size or Full-Size Breadboard × 1
Male-to-Male Jumper Wires × 1 Set
Micro-USB or Type-C Cable × 1
Host Device (Smartphone, Tablet, or PC with Bluetooth) × 1
Design Note: The MPU6050 module communicates over standard I2C. Ensure the pin headers are securely soldered to the breakout board; loose friction-fit connections inside through-holes cause bus communication dropouts. Tactile buttons leverage the ESP32 internal pull-up resistors, eliminating the need for external pull-up or pull-down resistors.
Connect the MPU6050 module to the default hardware I2C peripheral of the ESP32:
VCC → ESP32 3.3V (or 5V if the breakout contains an onboard 3.3V LDO regulator)GND → ESP32 GNDSCL → ESP32 GPIO 22SDA → ESP32 GPIO 21Wire each pushbutton between its dedicated GPIO pin and ground:
GPIO 18GNDGPIO 5GNDInside setup(), the ESP32 initiates the Bluetooth stack:
bleMouse.begin()
The controller advertises itself under the configured identifier:
Aditya's Gyro Mouse
Host operating systems detect the device natively as a standard wireless pointing device. No custom driver installation is required.
The MPU6050 defaults to sleep mode upon receiving power. The firmware configures the I2C interface and issues an explicit wake command:
Wire.begin();
Wire.setClock(400000);
mpu.initialize();
Wire.beginTransmission(0x68);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // Clear SLEEP bit to wake sensor
Wire.endTransmission(true);