This project turns an ESP32 into a wireless air mouse that tracks hand motion and sends cursor commands over Bluetooth. Built around the MPU-6050 6-axis motion sensor and two push buttons, it detects rotation to move the pointer and button presses to click.
This guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions. The included firmware handles sensor calibration, motion processing, and HID-over-Bluetooth communication, so the device pairs with any computer or tablet that accepts Bluetooth mice. After assembly and calibration, wave the device to control your cursor from across the room.
Wiring diagram

Gather all the parts
Assemble it in 3 steps
1. Connect the motion sensor
With USB unplugged, connect VIN to 3V3, GND to GND, SDA to GPIO0 (data), and SCL to GPIO1 (clock). Leave INT disconnected. Use the MPU6050 breakout with onboard I2C pull-ups.
- Use 3.3 V power, not 5 V, so the sensor's pull-ups cannot expose ESP32 pins to 5 V.
2. Add click buttons
Connect the left button between GPIO3 and GND, and the right button between GPIO4 and GND. For four-leg switches, use contacts on opposite switched sides, not two internally joined legs.
3. Mount and calibrate
Secure the sensor flat with its printed Z axis pointing upward and X axis pointing forward along the mouse. Keep it completely still for the first four seconds after power-up. Rotate left/right to move sideways and tilt the nose up/down to move vertically. Reset while still if the cursor drifts.
- Power through the development board's USB connector. This design does not include a battery or charger.
Review all connections
1. Connections between "imu" and "ESP32"
2. Connections between "left" and "ESP32"
3. Connections between "right" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <NimBLEDevice.h>
#include <NimBLEHIDDevice.h>
#include <math.h>
// Relative mouse: buttons, signed X, signed Y.
uint8_t reportMap[]={0x05,0x01,0x09,0x02,0xA1,0x01,0x85,0x01,0x09,0x01,0xA1,0x00,
0x05,0x09,0x19,0x01,0x29,0x02,0x15,0x00,0x25,0x01,0x95,0x02,0x75,0x01,0x81,0x02,
0x95,0x01,0x75,0x06,0x81,0x03,0x05,0x01,0x09,0x30,0x09,0x31,0x15,0x81,0x25,0x7F,
0x75,0x08,0x95,0x02,0x81,0x06,0xC0,0xC0};
NimBLEServer* server;
NimBLECharacteristic* input;
uint8_t address=0x68;
float biasY=0,biasZ=0, remX=0,remY=0;
const float sensitivity=12.0f; // Pointer counts per degree of rotation.
bool writeReg(uint8_t r,uint8_t v){Wire.beginTransmission(address);Wire.write(r);Wire.write(v);return Wire.endTransmission()==0;}
bool readReg(uint8_t r,uint8_t* b,uint8_t n){
Wire.beginTransmission(address);Wire.write(r);if(Wire.endTransmission(false))return false;
if(Wire.requestFrom(address,n)!=n)return false;
for(uint8_t i=0;i<n;i++)b[i]=Wire.read();return true;
}
bool gyro(float &y,float &z){uint8_t b[6];if(!readReg(0x43,b,6))return false;
y=(int16_t)((b[2]<<8)|b[3])/131.0f;z=(int16_t)((b[4]<<8)|b[5])/131.0f;return true;}
struct Button{int pin;bool raw=false,down=false;uint32_t changed=0;
void update(){bool v=digitalRead(pin)==LOW;if(v!=raw){raw=v;changed=millis();}if(millis()-changed>=20)down=raw;}};
Button left{3},right{4};
void fatal(){Serial.println("MPU6050 missing/read failed. Check 3.3V, ground, SDA 0, SCL 1. Reset to retry.");while(true)delay(1000);}
void setup(){
Serial.begin(115200);pinMode(3,INPUT_PULLUP);pinMode(4,INPUT_PULLUP);
Wire.begin(0,1);Wire.setClock(100000);Wire.setTimeOut(30);
uint8_t who=0;if(!readReg(0x75,&who,1)||who!=0x68){address=0x69;if(!readReg(0x75,&who,1)||who!=0x68)fatal();}
if(!writeReg(0x6B,0x80))fatal();delay(100);
if(!writeReg(0x6B,0x01)||!writeReg(0x1B,0)||!writeReg(0x1A,3)||!writeReg(0x19,4))fatal();
Serial.println("Keep mouse completely still: calibrating in one second.");delay(1000);
for(int i=0;i<400;i++){float y,z;if(!gyro(y,z))fatal();biasY+=y;biasZ+=z;delay(5);}biasY/=400;biasZ/=400;
NimBLEDevice::init("C3 Air Mouse");NimBLEDevice::setSecurityAuth(true,false,true);
server=NimBLEDevice::createServer();server->advertiseOnDisconnect(true);
auto hid=new NimBLEHIDDevice(server);input=hid->getInputReport(1);
hid->setManufacturer("DIY");hid->setHidInfo(0,1);hid->setReportMap(reportMap,sizeof(reportMap));
server->start();auto adv=NimBLEDevice::getAdvertising();adv->setName("C3 Air Mouse");adv->setAppearance(HID_MOUSE);adv->addServiceUUID("1812");adv->enableScanResponse(true);adv->start();
Serial.println("Ready. Pair C3 Air Mouse. Reset while still to recalibrate.");
}
void loop(){
static uint32_t last=micros();static uint8_t previous=255;
left.update();right.update();if(micros()-last<10000){delay(1);return;}
uint32_t now=micros();float dt=min((now-last)/1000000.0f,0.03f);last=now;
float y,z;if(!gyro(y,z)){remX=remY=0;return;}
if(!server->getConnectedCount()){remX=remY=0;previous=255;return;}
y-=biasY;z-=biasZ;if(fabsf(y)<0.8f)y=0;if(fabsf(z)<0.8f)z=0;
remX+=-z*sensitivity*dt;remY+=-y*sensitivity*dt;
int dx=constrain((int)remX,-127,127),dy=constrain((int)remY,-127,127);remX-=dx;remY-=dy;
uint8_t buttons=(left.down?1:0)|(right.down?2:0);
if(dx||dy||buttons!=previous){uint8_t data[]={buttons,(uint8_t)(int8_t)dx,(uint8_t)(int8_t)dy};input->setValue(data,3);input->notify();previous=buttons;}
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




