Connecting a mouse to an Arduino is simple. With just a few wires, we can easily integrate it into our Arduino projects. With the method that I describe in this post, the mouse can act as a sensor for determining positions or movements of vehicles, robots, for example.
How It WorksFirst, it is important to mention that this only works with mice that support the PS/2 protocol. Modern mice, for example the wireless ones only support USB and don't "understand" PS/2 any more. PS/2 is a serial protocol, similar to the UART protocol. But unlike UART, PS/2 is a synchronous protocol, which means that data and clock use different wires.
With this, it is easy to use the Arduino's builtin serial interface to receive the PS/2 data from the mouse. Please watch the video if you want to know more details.
The Circuit
Here are two pictures that show how to wire a mouse with PS/2 connector and a PS/2 compatible USB mouse to the Arduino Nano or UNO.
The data goes into the Arduino's Rx pin, clock goes into pin 4. With the 10k resistor between Data and +5V, it is still possible to use the interface for uploading programs while the mouse is connected. After development is done, the resistor can be removed.
Arduino LibraryWith a small Arduino library, it is easy to integrate the mouse into your projects. It comes with an example sketch that allows to control some LEDs with a mouse.
Comments