How to Make a Basic Computer Mouse Using the Joystick Module and Arduino Uno

This instructable will show you how to make a joystick controlled mouse using Arduino Uno and the joystick module.


You will need-

  • One Arduino Uno
  • 5 jumper wires
  • One Joystick
  • Arduino IDE
  • Python

Step 2: Make the Circuit

Make this circuit shown using your Arduino and Joystick.

Step 3: Uploading the Arduino Sketch

//The program that you can copy onto the Arduino IDE is-

void setup() 

int prev_state=0;   
void loop() {
  int z=0,xpos=0,ypos=0;
  int x=analogRead(A0);
  int y=analogRead(A1);
  int sensitivity=10;   
  int curr_state=digitalRead(9);
  if(curr_state==1 && prev_state==0)  

Step 4: Changing the Com Port in the Python Program

Paste this program in a Notepad –

import mouse, sys
import time 
import serial


while 1:
  if '1' in z:       "left")  

Change the com3 part of the program to the specific port which is applicable to you. Save this file as in Notepad.

Step 5: Open the Python File

Open the python file in the Python software you just saved i.e.

Step 6: Upload the Program

Click on the Run tab and click on Run Module to run the program on the Arduino Board

Step 7: Your Program Is Ready to Go!

Once you finish all this steps you can use the joystick to move around the mouse pointer and if you click hard then it also has a clicking function.

Step 8: Understand How the Joystick Works and Understanding X and Y Axis

If you want to learn more about x and y axis’s you can visit –

How the Joystick works –

A joystick plainly consists of two potentiometers aligned in the x and y direction which I have given an explanation link for. The Arduino Uno reads Analog (we fixed the x and y pins in analog pin 0 and 1) values from the Joystick in the range of 0 to 1023. Thus, when the joystick is in its default position e.i. the center, the Analog value also becomes close to 510 – 511 (between 0 and 1023).

Source: How to Make a Basic Computer Mouse Using the Joystick Module and Arduino Uno

About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Scroll to Top