my bluetooth controlled mouse arduino project is not working

179 views Asked by At

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 are 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 and I control the mouse with mobile app.

ERROR:- there is no error when I run the python and Arduino script it runs well but when I use a mobile app and connect the app with Arduino it gets connected but it's not working(cursor is not moving) check the below link

app link:- https://drive.google.com/drive/folders/1xJYx8pkkLD5OFUnATf7K_ENvClIXVAxw

this is I am trying to perform https://create.arduino.cc/projecthub/shubhamsantosh99/smartphone-controlled-mouse-728d91 basically, I followed all the step from the above link but I can't move the cursor from mobile app

this is Arduino code:-

    int datareceived[5] {0,0,0,0};          // To store byte from phone
    int in_byte = 0;
    int array_index = 0;
    void setup() {
    Serial.begin (9600); // starts the serial monitor
    }
     int height=0,width=0;
     int lcount=0,rcount=0;
    void loop() {
      int clicks=0;
      int sensitivity=20;       // you can adjust the sensitivity
      int xpos=0,ypos=0;
    if (Serial.available() > 0) {  //recieve byte from phone
      in_byte= Serial.read(); //store in byte into a variable
      if (in_byte == (255)) { // if the variable is 0 stet the array inxed to 0.
        array_index = 0;
      }
      datareceived[array_index] = in_byte;  //store number into array
      array_index = array_index +1;
      
    if(datareceived[1]>=110)
    xpos=map(datareceived[1],110,172,0,sensitivity);       // When moved right
    if(datareceived[1]<=70)
    xpos=map(datareceived[1],60,1,0,-sensitivity);        // When moved left
    if(datareceived[2]>=110)
    ypos=map(datareceived[2],110,255,0,sensitivity);     // When moved down
    if(datareceived[2]<=60)
    ypos=map(datareceived[2],70,1,0,-sensitivity);       // When moved up
    
    
    if(datareceived[3]==1)      // TO recognise a single button press
    {
      lcount+=1;
      if(lcount>3)
      {
        clicks=1;
        lcount=0;
      }
    }
    else if(datareceived[3]==2)
    {
      rcount+=1;
      if(rcount>3)
      {
        clicks=2;
        rcount=0;
      }
    }
    else 
    clicks=datareceived[3];       // to recognise the scroll
    
    
    if(xpos!=0 or ypos!=0 or clicks!=0)       // when either of the joystick is moved or the button is pressed
    {
    height=height+ypos;
    width=width+xpos;
    if(height>=799)
    height=799;
    if(height<=0)
    height=0;
    if(width>=1279)
    width=1279;
    if(width<=0)
    width=0;
    Serial.print(width);
    Serial.print(":");
    Serial.print(height);
    Serial.print(":");
    Serial.println(clicks);
    clicks=0;
    }
    }
    }

this is python code:-

    import mouse, sys
    import time 
    import serial
    
    mouse.FAILSAFE=False
    ArduinoSerial=serial.Serial('com3',9600)  #Specify the correct COM port
    time.sleep(1)                             #delay of 1 second
    
    while 1:
       data=str(ArduinoSerial.readline().decode('ascii'))
       (x,y,z)=data.split(":")  # read the x and y axis data
       (x,y)=(int(x),int(y))   # convert to int
       mouse.move(x,y)         # move the cursor to desired coordinates
       if '1' in z:                       
          mouse.click(button="left")     #clicks mouse button
       elif '2' in z:
          mouse.click(button="right")
       elif '3' in z:
          mouse.wheel(delta=-1)       # Scroll down
       elif '4' in z:
          mouse.wheel(delta=1)       # Scroll up
0

There are 0 answers