DIY Kickback Mouse in the Game (PUBG Gameplay)

3,476

37

4

Introduction: DIY Kickback Mouse in the Game (PUBG Gameplay)

About: I'm content creator about DIY project. You can follow me on instructables and YouTube Channel ( ilge )

Most of us know what a vortex games, especially online games, are. When we press the "Play" button once, hours turn into minutes, especially in FPS games, the excitement is always the ceiling. When I saw the video shared by the YouTube channel of "Teenenggr" recently, I saw how the gaming experience can reach a level with a few lines of code and a few engines. In this content, you will find the details of the project that I made with reference to this video and which I aim to increase the gaming experience several times.

The project in the Teenenggr channel consists of solenoid motors, Arduino and relays on the hardware side. The main protagonist of not only this video of the channel, but also of other videos is solenoid motors. You can find the link of the related video and channel below.

Teenenggr YouTube channel: www.youtube.com/c/Teenenggr

The lead actor of our project is the solenoid motor. Solenoid motors are motors used for pushing and pulling operations and have a very simple structure. Thanks to the magnetic field created by the current passing over the coil inside, the motor moves in one direction and returns to its original position after the energy is cut off. I used these engines to feel the recoil effect on the gun while shooting in the game. Absolutely cut out to capture the "kickback" feeling.

Supplies

Step 1: Circuit

In its most basic form, the project consists of sending the mouse click on the computer to Arduino and driving the motor with the help of a relay, depending on the incoming data. I used a fairly simple Python code to capture mouse clicks. What the code does is, in its most basic form, to inform Arduino when a click is detected / not detected via the serial port. You can find the details about the code part and the code files under the headings below.

Step 2: Coding (Python on PC)

The job of the code I use for this project is to send mouse clicks to Arduino over the serial port. Friends who want to develop on Python code will need to install two libraries. The first of these is the "pyserial" library used to provide serial port communication in the code; the other is the "pywin32" library used to detect mouse clicks. If you want to run the code directly with .exe without messing with the installations, you can skip to the last paragraph under this title.

You can easily install the library with PiP (Preferred Installer Program). In short, PiP is an auxiliary package manager that enables us to install third party libraries on our computer. If you complete the installation by selecting the "Add Python to PATH" box from the boxes that appear while installing Python, you can run the PiP commands from the command prompt (cmd). You can find a more detailed article on PiP and PiP setup below.

For Python installation: https://www.python.org/

After installing PiP, all you have to do is open the command prompt, "pip install" and type the PyPI package you want to install.

Commands required for our code:

pip install pyserial
pip install pywin32

After typing the above commands in the command prompt (cmd) and completing the package setup, you can run the code and play with the code. You can find the Python code below.

import pywintypes
import win32api
import time
import serial

state_left = win32api.GetKeyState(0x01)  # Left button down
state_right = win32api.GetKeyState(0x02)  # Right button down

port = input("Bağlı COM portu girin: ")
ser = serial.Serial(port, 9600, timeout=.1)

while True:
    a = win32api.GetKeyState(0x01)
    #b = win32api.GetKeyState(0x02)

    if a != state_left:  # Button state changed
        state_left = a
        while a < 0:
            print('Left Button Pressed')
            a = win32api.GetKeyState(0x01)
            ser.write(bytes("1", 'utf-8'))
            time.sleep(0.1)
    else:
        ser.write(bytes("2", 'utf-8'))
        time.sleep(0.01)

Step 3: Coding Arduino

The work done on the Arduino side is to trigger the relay and control the LEDs according to the click information coming through the serial port. If "1" comes from the serial port, the relay is triggered and the motor runs. I used a variable named "counter" to drive the LEDs depending on the incoming clicks. The counter value increases with every click; it also decreases when there is no click. 7 LEDs on the circuit are lit according to the value of the “counter”. In this way, I have achieved an effect similar to the LED animation that occurs depending on the sound intensity in the vumeters, according to the fire intensity in the game.

You can find the Arduino code below.

#define RELAY 10
#define DELAY 50 // motor çalışma süresi

const int LEDs[7] = {3,4,5,6,7,8,9};
unsigned int counter = 0;


void setup() {
  Serial.begin(9600);

  for(int i=0; i<7; i++){
    pinMode(LEDs[i], OUTPUT);
  }

  pinMode(RELAY,OUTPUT);

}

void loop() {
  digitalWrite(RELAY,LOW);
  LEDs_On(counter);

}

void serialEvent(){
  char inChar = (char)Serial.read(); //Porttan gelen veriyi oku
  if (inChar == '1')                 //Mouse'a tıklandıysa
  {
    digitalWrite(RELAY, HIGH);
    delay(DELAY);                   //Motor çalışma süresi
    counter++;
  }
  else if (inChar == '2')           //Mouse'a tıklanmıyorsa
  {
    if (counter >0) counter--;
  }
}

void LEDs_On(int c)
{
  if (c>6)                          //Tüm LED'led   *******
  {
    for(int i=0;i<7;i++)
      digitalWrite(LEDs[i],HIGH);
  }
  else if (c>4)                     //5 LED         -*****-
  {
    digitalWrite(LEDs[0], LOW);
    digitalWrite(LEDs[6], LOW);
    for(int i=0;i<5;i++)
      digitalWrite(LEDs[i+1], HIGH);
  }
  else if (c>2)                     //3 LED          --***--
  {
    for(int i=0;i<7;i++) 
      digitalWrite(LEDs[i],LOW);

    digitalWrite(LEDs[2],HIGH);
    digitalWrite(LEDs[3],HIGH);
    digitalWrite(LEDs[4],HIGH);
  }
  else if (c>0)                      //1 LED          ---*---
  {
    for(int i=0; i<7; i++)         
      digitalWrite(LEDs[i],LOW);

    digitalWrite(LEDs[3], HIGH);
  }
  else
  {
    for(int i=0; i<7; i++)          // LED'ler Kapalı -------
      digitalWrite(LEDs[i],LOW);
  }
}

Step 4: 3D Model for Solenoid Mount and Final

I designed a chassis and printed it from a 3D printer to hold the motors together and achieve an aesthetic structure. You can find the design file at the github link below.

Click for the Github link with the codes used in the project and the design file : https://github.com/eglix/Projeler/tree/master/Mous...

After connecting two motors on both sides of the chassis and connecting the motors with the circuit, I completed the project. You can watch the test part of the project on the video. I am waiting for your ideas on how this project can be improved. You can share your comments below the video or in the comments section below. Goodbye until I see you on the next project 🙂

You Can watch how to make and test video: https://youtu.be/Jw-RmpuH7JU

Be the First to Share

    Recommendations

    • Metal Contest

      Metal Contest
    • Maps Challenge

      Maps Challenge
    • Backyard Contest

      Backyard Contest

    4 Comments

    0
    kalkisimege
    kalkisimege

    10 months ago

    Abi güzel proje olmuş zaten YouTube da izlemiştim eline sağlık

    0
    Maker Chef
    Maker Chef

    10 months ago

    Perfect... It can be the only solution for noob fps players like me :)

    0
    motosutra
    motosutra

    11 months ago

    Bro, its amazing I really like it I'll make one for sure...

    0
    ilge ipek
    ilge ipek

    Reply 11 months ago

    Thanks, I'm really glad you liked my project :)