Triggerbot with Python and Arduino Pro Micro

Welcome to this tutorial on creating a triggerbot using Python and an Arduino Pro Micro. This guide will walk you through the process, from setting up your development environment to configuring the Arduino and Python scripts. By the end, youโ€™ll have a functioning trigger bot that can be used in games with color detection.

Github Source: https://github.com/slyautomation/color-triggerbot

For the video guide watch this!

Requirement

  • Hardware: Arduino Pro Micro (or any Arduino compatible with USB HID), USB cable.
  • Software: PyCharm, Arduino IDE, Python 3.10, Git.

Amazon: Arduino Pro Micro: https://amzn.to/3UY8ri1

Aliexpress: Arduino Pro Micro: https://s.click.aliexpress.com/e/_DdgYkVN

Also works with Arduino Leonardo and/or usb host shield: Amazon:

Arduino USB Host Shield: https://amzn.to/3JKdJHn

Arduino Leonardo R3: https://amzn.to/4b0IUdS

Soldering Iron: https://amzn.to/4ba7R5W

Solder Wire: https://amzn.to/4ba7R5W

Aliexpress:

Arduino USB Host Shield: https://s.click.aliexpress.com/e/_Dl8wK3l

Arduino Leonardo R3: https://s.click.aliexpress.com/e/_DkYWL1V

Step 1: Set Up Your Development Environment

1.1 Install PyCharm

Download and install PyCharm from JetBrains. Need a guide to install pycharm and python? Check out this guide! Install Pycharm and Python: Clone a github project

1.2 Clone the Slip Automation GitHub Repository

Open a terminal and clone the repository:

git clone https://github.com/slyautomation/color-triggerbot.git

Or copy the contents from https://github.com/slyautomation/color-triggerbot

1.3 Open the Project in PyCharm

  • Launch PyCharm.
  • Open the cloned repository folder in PyCharm.

1.4 Set the Python Interpreter

  • Go to File > Settings > Project: <your_project_name> > Python Interpreter.
  • Select Python 3.10. If itโ€™s not listed, click the gear icon and add Python 3.10.

Step 2: Configure Arduino

2.1 Install the Arduino IDE

Download and install the Arduino IDE from Arduino’s website.

2.2 Add Necessary Libraries

  • Download the HID Mouse Reports library from this link.
  • Copy the folder and paste it into the Arduino libraries directory (usually found in Documents/Arduino/libraries).

2.3 Load the Arduino Script

  • Open the Arduino IDE.
  • Open the script from the cloned repository that corresponds to the Arduino Pro Micro.
  • For the Pro Micro, youโ€™ll use adruino_keyboard_press.ino.
  • Select the correct board (Arduino Pro Micro) and port from the Tools menu.
  • Click Verify to compile the script.
  • Click Upload to upload the script to your Arduino.

Step 3: Configure Python Script

3.1 Install Required Python Packages

In PyCharm, open the terminal and run the following commands:

pip install opencv-python
pip install keyboard

3.2 Update Script Settings

Open the Python script in the repository and make the following changes:

  • Port Configuration: Ensure the COM port in the script matches the port your Arduino is connected to. This is typically something like COM12.
  • Color Configuration: Update the color value in the script to the color you want the trigger bot to detect. For example:
color_to_use = 'red'
if color_to_use == 'purple':
    lpoint = [135, 35, 20]
    upoint = [155, 255, 255]

if color_to_use == 'yellow':
    lpoint = [22, 46, 255]
    upoint = [38, 255, 255]

if color_to_use == 'red':
    lpoint = [0, 90, 90]
    upoint = [4, 235, 255]
  
  

Color Configuration:

To change the trigger bot to detect cyan color using HSV (Hue, Saturation, Value) color space, you need to set the lower and upper thresholds for the cyan color. The HSV values for cyan typically range as follows:

  • Hue: around 80 to 100 (depends on the exact shade of cyan)
  • Saturation: 100 to 255 (depends on how vibrant the cyan is)
  • Value: 100 to 255 (depends on the brightness of the cyan)
# Define the lower and upper thresholds for cyan in HSV color space
lpoint = [80, 100, 100]
upoint = [100, 255, 255]

3.3 Run the Python Script

  • Right-click the script in PyCharm.
  • Select Run.

Step 4: Testing and Adjustments

4.1 Open a Game with Color Detection

Launch a game that uses color detection for triggering actions (e.g., shooting when a specific color is detected on the screen).

4.2 Configure In-Game Settings

  • Change the secondary firing option in your game settings to match the key press defined in your Arduino script.
  • Or if using a usb host shield no change is needed as you can still use the aimbot ino to action the clicks, the python code for the triggerbot will only send mouse clicks instead of movement as well.

4.3 Test the Trigger Bot

  • Move the in-game crosshair over the target color.
  • The trigger bot should automatically trigger the firing action.

Step 5: Optional Adjustments

5.1 Adjust Color Detection Parameters

  • If the trigger bot is not responsive, tweak the color detection parameters.
  • Uncomment the display lines in the Python script to visualize the detection process:
    • Line 75, 76, 85 and 86
75 #cv2.drawContours(image, contours, -1, (255, 0, 0), 1)
76 #cv2.circle(image, (pt[0], pt[1]), radius=1, color=(0, 0, 255), thickness=-1)
....
85 #cv2.imshow("images", image)
86 #cv2.waitKey(5)

5.2 Fine-Tune Firing Modes

  • The script supports different firing modes such as pistol and auto. Adjust these modes using function keys (F1, F2, F3) as defined in the script.

5.3 Error Handling

  • If you encounter any errors, ensure all dependencies are correctly installed.
  • Check for any missing libraries and install them via PyCharmโ€™s terminal or the Arduino Library Manager.

Conclusion

Youโ€™ve now set up a functional trigger bot using Python and an Arduino Pro Micro. This setup can be customized and extended for various use cases in gaming and automation. Experiment with different settings and fine-tune the system to your needs. Enjoy your new trigger bot!

Here’s a demo in deathmatch!

Leave a Reply

Your email address will not be published. Required fields are marked *