Arduino Based Smartphone Controlled Mouse

Published Sep 18, 2022
 48 hours to build
 Beginner

This is a virtual joystick to control a PC cursor. Here I have created a smartphone application that contains 2 virtual joysticks to move the cursor as well as scroll the screen and also does left and right click just like a regular trackpad.

display image

Components Used

Arduino UNO
Arduino UNO
1
Bluetooth Module HC-05
Bluetooth is a wireless communication protocol used to communicate over short distances. It is used for low power, low cost wireless data transmission applications over 2.4 – 2.485 GHz (unlicensed) frequency band.
1
Male to Female Jumper Wire
Jumper Wires Mach pin jumper wires
1
Male to Male Jumper Wire
Jumper Wires Mach pin jumper wires
1
Female to Female Jumper Wire
Jumper Wires Mach pin jumper wires
1
USB Type A to B Cable
USB Cables / IEEE 1394 Cables USB A-B 28/26 BLACK 1.3 M
1
Description

ABOUT THIS PROJECT

This project is similar to my previous work where I have used a joystick to control a PC cursor. The key difference is that I have created a smartphone application that contains 2 virtual joysticks to move the cursor as well as scroll the screen and also does left and right click just like a regular trackpad.

 

Working

The project involves a smartphone application that sends the joystick's x and y axis data, scroll status, left and right click status using bluetooth to the Arduino Uno connected to the HC-05 bluetooth module. These data upon reception to the Arduino is manipulated to make changes in the current cursor's position to obtain a new position. The resulting data along with scroll and button status is then printed as the output that is recognized to be read by the Python sketch. The Python sketch is made to execute mouse actions using the mouse module.

Working Working

About the Application

The smartphone application is created using the MIT-App Inventor. Creating the app is simple as you just need to add the desired blocks to build your required application. I have referred to the Tabletop robotics tutorial on making them. The main screen of the application is as follows-

Smartphone AppSmartphone App

Before sending the main information to the HC-05 module, the application first sends a one-byte number (255) to denote the start of information. The sequence of data transfer is as follows-

1. Send '255' to denote start

2. Send 1 byte joystick x-axis value

3. Send 1 byte joystick y-axis value

4. Send status of left click, right click button and scroll status (1 byte).

The data from the application is sent every 20 milliseconds to the Arduino UNO.

Arduino's Side

The data bytes from the Application is received by the Arduino with the help of HC-05 Bluetooth module. The Arduino contains the current coordinates of the cursor where the x coordinates range from 0 to 1279 and the y coordinates range from 0 to 799. I have obtained these extreme coordinates form the python function mouse.get_position() that returns the coordinates when the cursor is moved (not used in the main sketch).

Based on the data received upon moving the joystick, the current cursor's position (x and y coordinates) is then added/subtracted with the data received by the application to move the cursor to the new desired coordinate. The final data is then printed on the Serial monitor in sequence given below.

Data sent to pythonData sent to python

The following data sequence is finally read by the python program to execute it. For this, we will need to download additional modules namely mouse and pyserial in the steps given below.

Python Programming

The user must have python 3 installed on their laptop/computer. It can be downloaded from the here.

(For Windows)

After installation, Copy the path of the python file location.

The following steps are to be performed on the command prompt. Open command prompt and enter the following-

1. cd <paste the path of the python file>

2. py –m pip install –-upgrade pip

3. py –m pip install mouse

4. py -m pip install pyserial

The mouse module is used to perform mouse actions and pyserial module is used to send/receive data from the arduino. I had already installed the necessary modules, so I got this

PREVIOUSNEXT

  • 1
  • 2

 

Execution

Install the Bluetooth Mouse Control app on your smartphone device.

Upload the Arduino sketch to your Arduino UNO and follow the circuit as given in the schematic.

Make sure the HC-05 Bluetooth module is already paired with your smartphone device, only then you can select it from the list of paired devices.

Python side-

1. Copy paste the python code in a notepad file. Change the COM port to your Arduino UNO's COM port and save it as '.py'.

Fig 1.1:Specify the Arduino's COM portFig 1.1:Specify the Arduino's COM port

fig 1.2:Check from Device Managerfig 1.2:Check from Device Manager

PREVIOUSNEXT

  • 1
  • 2

2. Open the python IDLE and open the notepad file form it.

fig 2.1: Open python IDLEfig 2.1: Open python IDLE

fig 2.2:Open the notepad filefig 2.2: Open the notepad file

Fig 2.3Fig 2.3

PREVIOUSNEXT

  • 1
  • 2
  • 3

3. Run the Sketch.

Fig 3: Run the sketchFig 3: Run the sketch

You will then be directed back to screen in fig 2.2.

Open the smartphone application and connect to the bluetooth module and you will notice the cursor movement upon changing the direction of the joystick.
Video Link:

Codes

Downloads

Arduino_Mouse Download
Comments
Ad