Projects / Head-controlled mouse

Head-controlled mouse

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ARDUINOMPU6050tilt 37°

    Test the IMU

    Print the gyro values.

  2. ARDUINO

    Calibrate at rest

    Measure the bias while still.

  3. ARDUINO

    Map movement

    Turn and nod move the pointer.

  4. ARDUINO

    Add the dead zone

    Ignore small movements.

  5. ARDUINO

    Add the dwell click

    Click after one second still.

  6. ARDUINO

    Add the on/off button

    Switch the pointer.

  7. ARDUINOMPU6050tilt 38°

    Mount on a cap

    Fix the IMU and strain-relieve the cable.

In short

How do you build a head-controlled mouse?

An IMU on a headband moves the mouse pointer as you turn your head, with a dwell click. You need Arduino Leonardo, MPU6050 IMU, USB A to micro-USB cable (data) and Tactile push button 6 mm. It takes 7 steps and about 180 minutes.

Level
Intermediate
Time
About 180 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
MPU6050 VCC and GNDLeonardo 5V and GNDPower (most MPU6050 boards have a regulator)
MPU6050 SDALeonardo SDA (pin 2)I2C data
MPU6050 SCLLeonardo SCL (pin 3)I2C clock
ButtonLeonardo D7 and GNDPointer on or off
USB cableComputerPower and mouse connection

Code

A gyroscope measures how fast the head turns, and the sketch turns that rate into pointer movement. Turn left or right to move across and nod to move up and down. A dead zone stops small tremors from moving the pointer, and the bias measured at start-up cancels the sensor's resting offset: keep your head still for the first second after plugging in. A dwell click presses the left button once if the pointer stays still for a second, and does not click again until you move. The button turns the pointer on and off, so you can use the real mouse when needed. This is a prototype for experiments and not a medical device or a certified assistive technology. If you or someone you know relies on such a device, speak to an occupational therapist about proven options, and test this one for comfort and neck strain. Mount the IMU on a headband or cap so it cannot slide, and route the cable so it cannot pull. Arduino IDE, board "Arduino Leonardo".

Runs on a virtual Arduino Leonardo 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).

// Head mouse with dwell click. Library: Adafruit MPU6050, Mouse (built in). Board: Arduino Leonardo.
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Mouse.h>

Adafruit_MPU6050 mpu;
const int BTN = 7;
bool active = false;
unsigned long lastBtn = 0, stillSince = 0;
bool clicked = false;
float biasX = 0, biasZ = 0;

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  mpu.begin();
  delay(1000);
  for (int i = 0; i < 100; i++) {                 // measure the resting gyro bias while the head is still
    sensors_event_t a, g, t; mpu.getEvent(&a, &g, &t); biasX += g.gyro.x; biasZ += g.gyro.z; delay(10);
  }
  biasX /= 100; biasZ /= 100;
  Mouse.begin();
}

void loop() {
  if (!digitalRead(BTN) && millis() - lastBtn > 500) { active = !active; lastBtn = millis(); }   // pointer on or off
  sensors_event_t a, g, t; mpu.getEvent(&a, &g, &t);
  float gx = g.gyro.x - biasX, gz = g.gyro.z - biasZ;     // rad per second: nod and turn
  int dx = 0, dy = 0;
  const float DEAD = 0.08;                                 // dead zone for comfort
  if (fabs(gz) > DEAD) dx = (int)(-gz * 18);               // turning left or right moves the pointer left or right
  if (fabs(gx) > DEAD) dy = (int)(-gx * 18);               // nodding up or down moves the pointer up or down
  if (active) {
    if (dx || dy) { Mouse.move(dx, dy, 0); stillSince = millis(); clicked = false; }
    else if (!clicked && millis() - stillSince > 1000) { Mouse.click(MOUSE_LEFT); clicked = true; }   // dwell click after 1 s still
  }
  delay(10);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Turn the head leftPointer moves left
Nod downPointer moves down
Hold still for a secondOne click
Press the buttonPointer stops responding

If it does not work

Pointer drifts

Recalibrate the bias with the head still.

Moves too fast

Reduce the multiplier 18.

Clicks by accident

Lengthen the dwell time.

Moves in the wrong direction

Change the signs or the axes.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the head-controlled mouse?

Arduino Leonardo, MPU6050 IMU, USB A to micro-USB cable (data) and Tactile push button 6 mm.

How long does the head-controlled mouse take to build?

About 180 minutes for a intermediate maker, in 7 steps.

How do I know the head-controlled mouse works?

Turn the head left: Pointer moves left. Nod down: Pointer moves down. Hold still for a second: One click.

Pointer drifts: what should I check?

Recalibrate the bias with the head still.

Moves too fast: what should I check?

Reduce the multiplier 18.

Clicks by accident: what should I check?

Lengthen the dwell time.

Moves in the wrong direction: what should I check?

Change the signs or the axes.