potentiometre-souris.ino

Arduino Micro · File : potentiometre-souris.ino · Language : Arduino · Use case : Un potentiomètre qui déplace le curseur de la souris comme un mini trackball

The potentiometer offset from its rest position becomes pointer speed: the board turns trackball. Calibration happens at boot — center the potentiometer before powering up.

Hardware required

An Arduino Micro (ATmega32U4, 16 MHz, 5 V) in a breadboard-friendly format with a micro-USB connector and native USB (keyboard/mouse). 1 10 kΩ potentiometer.

Wiring

Ends to 5 V/GND, wiper to A0.

How it works

A ±30 dead zone prevents drift; speed is capped at ±10 px per 20 ms step. In the Arduino IDE, select « Arduino Micro » and the port, then Upload. On Windows a .inf driver may be needed for the COM port. Since the 32U4 is the USB itself, a bad sketch can lock out reflashing (double reset).

Going further

A second potentiometer on A1 adds the Y axis for a 2-axis pointer.

potentiometre-souris.ino

// Potentiometre sur A0 : ecart au centre = vitesse du curseur.
#include <Mouse.h>

const int POT = A0;
int centre = 0;

void setup() {
  Serial.begin(9600);
  Mouse.begin();
  centre = analogRead(POT); // position au demarrage = repos
  Serial.print(F("Centre: "));
  Serial.println(centre);
}

void loop() {
  int v = analogRead(POT);
  int ecart = v - centre;
  if (abs(ecart) > 30) {
    Mouse.move(constrain(ecart / 20, -10, 10), 0);
  }
  delay(20);
}

← Back to the board