IntermediateInteractive Control

Gesture Air Mouse

Control your computer cursor and presentations with hand movements.

Time
2–3 h
Estimated cost
~£30
Hardware
ESP32-DevKitC V4 (38-pin)

Example code — not yet validated

Try it in the browser

What you will build

A handheld Bluetooth controller that your computer sees as a normal mouse, with no software to install. Hold the Move button and wave your hand to steer the cursor. Other buttons give left click, next slide and previous slide. The card image shows a wrist-worn version; this guide builds the handheld breadboard version first.

How it works

The MPU6050's gyroscope measures how fast your hand rotates. Rotation left/right (yaw) moves the cursor horizontally; up/down (pitch) moves it vertically. Using rotation speed rather than tilt angle feels like a laser pointer. The ESP32 advertises itself as a Bluetooth LE HID mouse; Windows, macOS, Linux, ChromeOS and Android pair with it like any wireless mouse. Next/previous slide are sent as scroll-wheel steps, which PowerPoint and Google Slides treat as slide changes in presentation mode.

Parts

Part Qty Purpose Required
ESP32-DevKitC V4 (WROOM-32E, has BLE) 1 Controller + Bluetooth Yes
MPU6050 breakout (GY-521) 1 Motion sensing Yes
Tactile buttons 4 Move, click, next, previous Yes
Mini breadboard + small USB power bank 1 Handheld build Yes

The classic ESP32 has Bluetooth LE but no native USB HID, so this build uses Bluetooth only.

Build steps

  1. MPU6050: VCC → 3V3, GND → GND, SDA → GPIO 21, SCL → GPIO 22. Mount it flat on the breadboard.
  2. Buttons to GND from: GPIO 25 (Move), GPIO 27 (Left click), GPIO 32 (Next), GPIO 33 (Previous).
  3. Install Adafruit MPU6050 and ESP32 BLE Mouse (by T-vK) from GitHub/Library Manager. If it fails to compile on core v3.x, use a maintained fork or the NimBLE-based version and record which one on the page.
  4. Upload. Keep the controller still for 2 s while it measures gyro drift.
  5. On your computer, open Bluetooth settings and pair XBOT Air Mouse.
  6. Checkpoint: hold Move and rotate your wrist → cursor moves; release → cursor stops.
  7. Open a slideshow in presentation mode and test Next/Previous.
  8. Tune SENSITIVITY until a comfortable wrist turn crosses the screen.

Try it in the browser

Interactive Preview. A pointer demo on the project page moves a virtual cursor from a virtual IMU (drag or arrow keys) and shows the gyro values. It does not move your real cursor; that only happens with the paired hardware.

Code

Download gesture-air-mouse.ino

// Gesture Air Mouse — XBOTNOW
// Board: ESP32-DevKitC V4 · Core: esp32 v3.x
// Libraries: Adafruit MPU6050, ESP32 BLE Mouse (record exact version/fork used)
#include <BleMouse.h>
#include <Adafruit_MPU6050.h>

const int BTN_MOVE = 25, BTN_CLICK = 27, BTN_NEXT = 32, BTN_PREV = 33;
const float SENSITIVITY = 18.0;   // pixels per (rad/s) per update
const float DEADZONE = 0.04;      // rad/s, removes hand tremor

BleMouse mouse("XBOT Air Mouse", "XBOTNOW", 100);
Adafruit_MPU6050 mpu;
float biasY = 0, biasZ = 0, vx = 0, vy = 0;
bool lastClick = false, lastNext = false, lastPrev = false;

bool pressed(int pin) { return digitalRead(pin) == LOW; }

void setup() {
  Serial.begin(115200);
  for (int p : {BTN_MOVE, BTN_CLICK, BTN_NEXT, BTN_PREV}) pinMode(p, INPUT_PULLUP);
  if (!mpu.begin()) { Serial.println("MPU6050 not found"); while (1) delay(10); }
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  sensors_event_t a, g, t;
  for (int i = 0; i < 200; i++) {                 // 2 s gyro bias calibration
    mpu.getEvent(&a, &g, &t); biasY += g.gyro.y; biasZ += g.gyro.z; delay(10);
  }
  biasY /= 200; biasZ /= 200;
  mouse.begin();
}

void loop() {
  if (!mouse.isConnected()) { delay(100); return; }
  sensors_event_t a, g, t; mpu.getEvent(&a, &g, &t);
  float gz = g.gyro.z - biasZ, gy = g.gyro.y - biasY;
  if (fabs(gz) < DEADZONE) gz = 0;
  if (fabs(gy) < DEADZONE) gy = 0;

  // smooth, then move only while Move is held (clutch)
  vx = 0.7 * vx + 0.3 * (-gz * SENSITIVITY);
  vy = 0.7 * vy + 0.3 * (-gy * SENSITIVITY);
  if (pressed(BTN_MOVE)) mouse.move((int8_t)constrain(vx, -127, 127), (int8_t)constrain(vy, -127, 127));

  bool c = pressed(BTN_CLICK), n = pressed(BTN_NEXT), p = pressed(BTN_PREV);
  if (c && !lastClick) mouse.press(MOUSE_LEFT);
  if (!c && lastClick) mouse.release(MOUSE_LEFT);
  if (n && !lastNext) mouse.move(0, 0, -1);      // scroll down = next slide
  if (p && !lastPrev) mouse.move(0, 0, 1);       // scroll up = previous slide
  lastClick = c; lastNext = n; lastPrev = p;
  delay(10);                                      // ~100 updates/s
}

Troubleshooting

Symptom Likely cause Check
Not visible in Bluetooth list Already paired to another device Remove old pairing; reset the ESP32
Cursor drifts slowly Moved during calibration Keep still for 2 s after reset
Axes swapped or reversed Sensor orientation Swap gz/gy or flip the signs
Next/Prev do nothing App doesn't map scroll to slides Test in PowerPoint or Google Slides presentation mode

Safety and limitations

Keep a normal mouse and keyboard available. This is a maker project, not a certified accessibility device. Bluetooth pairing is open while the device advertises; unpair it from shared computers after use.

Checklist

Next project

Motion-Controlled Flight Simulator: stream the motion to a 3D game in the browser.

Next project: Motion-Controlled Flight Simulator