DIY Kickback Mouse in the Game (PUBG Gameplay)
by ilge ipek in Circuits > Arduino
5045 Views, 39 Favorites, 0 Comments
DIY Kickback Mouse in the Game (PUBG Gameplay)
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
Arduino Uno CH340 -- BG: https://bit.ly/2F6lN7E (CH340 Chip) or AMZ: https://amzn.to/3h1woxB
5V Relay Module -- BG: https://bit.ly/3igsHWc or AMZ: https://amzn.to/2GBrMSz
12V Solenoid -- BG: https://bit.ly/2F9Jk7C or AMZ: https://amzn.to/3i5Iqay
Barrel Jack: Wire -- BG: https://bit.ly/3i40sdB or AMZ: https://amzn.to/3bvTGL2
5mm Red LED -- BG: https://bit.ly/336XpL8 or AMZ: https://amzn.to/3hZMtVY
Prototyping Board -- BG: https://bit.ly/2ZbLTgw or AMZ: https://amzn.to/3jRGGlX
Header -- BG: https://bit.ly/2ZaVgNv or AMZ: https://amzn.to/2ZepsqZ
12V DC Adaptor -- BG: https://bit.ly/3bzjc1O or AMZ: https://amzn.to/2QZ7ft1
Tools:
Cutting Mat -- BG: https://bit.ly/3bynF54 or AMZ: https://amzn.to/3h3pjwA
Soldering Iron -- BG: https://bit.ly/330sm3D or AMZ: https://amzn.to/35cB9Cy
Solder -- BG: https://bit.ly/2RcZLCZ or AMZ: https://amzn.to/3jRWZ1Y
Solder Paste -- BG: https://bit.ly/3h4YOGY or AMZ: https://amzn.to/2GB0UlC
Tweezer -- BG: https://bit.ly/3i4pQ2x or AMZ: https://amzn.to/2DzP61V
Cutting Plier -- BG: https://bit.ly/331E12i or AMZ: https://amzn.to/2QZSV3n
Heat Shrink Tube -- BG: https://bit.ly/336x4gx or AMZ: https://amzn.to/3lRbncV
3D Printer (Ender 3 Pro) -- BG: https://bit.ly/3jObeVC or AMZ: https://amzn.to/358lsfu
Filament -- BG: https://bit.ly/3h5Rr24 or AMZ: https://amzn.to/2R1JfFM
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.
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)
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); } }
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