PRABEEN RAJ
Published © GPL3+

Joystick PC Mouse

Convert Arduino Uno into PC Mouse

BeginnerFull instructions provided3,157
Joystick PC Mouse

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
You can use any arduino boards for this projects
×1
Analog joystick (Generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
10K potentiometer
×2
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
For mouse left click
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
Pycom Python

Story

Read more

Schematics

Circuit Diagram For Joystick Module

Circuit Diagram For Potentiometer

If you don't have joystick module use this circuit

Code

Arduino Code

C/C++
int d7 =7;
int d8 =8;

void setup() {
 pinMode(d7,INPUT_PULLUP);
 pinMode(d8,INPUT_PULLUP);
 
Serial.begin(9600);
}

void loop() {
  int X = analogRead(A1);
  int Y = analogRead(A0);
  int x = map(X, 1, 1023, 1917, 2);
  int y = map(Y, 1, 1023, 2, 1077);
  

if(digitalRead(d8)==LOW){
Serial.print("c");

}else{
  Serial.print("z");
}
Serial.print(" ");
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.print(" ");
Serial.println("m");
delay(180);
}

Python Code

Python
import serial            #Install Modules
import pyautogui as pg   #Install Modules


pg.FAILSAFE=False


ser = serial.Serial("COM1",'9600')  #Enter Arduino Port Number
while True:
    read = ser.readline().decode('ascii')
    readArray = read.split()
    c = readArray[0]
    x = readArray[1]
    y = readArray[2]
    m = readArray[3]
    print(c, ' ', x,' ',y,' ',m)
    if c=='c':
        pg.click(button='left')

    pg.moveTo(int(x), int(y))

Arduino and Python Code

Credits

PRABEEN RAJ

PRABEEN RAJ

10 projects • 2 followers

Comments