PS4-controlled robotic battle platform
An ESP32-based remote-controlled combat vehicle combining motorized movement with laser tag functionality. The system is controlled via PS4 gamepad over Bluetooth and features infrared shooting capabilities, LED visual feedback, and motor chaos effects when hit.
TankBattleGithub_compressed.mp4
- PS4 Gamepad Control: Wireless Bluetooth control with two joystick modes (one-stick and two-stick driving)
- Motor Control: Dual motor drive with expo curves, deadzone handling, and pivot turning
- Laser Tag Combat: Infrared transmitter/receiver for shooting and detecting hits
- Visual Laser: Physical laser pointer activated with triggers
- Activity Lighting: 67 RGB LEDs (WS2812/NeoPixel) for team colors, hit indicators, and game status
- Hit Reactions: Motor chaos mode activated when hit, disrupting vehicle control temporarily
- Team System: Multiple team color support with in-game color switching
- One-stick mode: Single joystick controls both movement and turning
- Two-stick mode: Left stick for forward/backward, right stick for turning with pivot-in-place and high-speed turn boost
- Hit detection with cooldown periods
- Fire rate limiting
- Team-based combat with color identification
- Game over state when hit too many times
Use an image search to find the best deal for every component.
| Component | GPIO Pin |
|---|---|
| LED Strip Data | 13 |
| IR Transmit (Fire) | 2 |
| IR Receiver Front | 27 |
| IR Receiver Back | 26 |
| Laser | 15 |
| Right Motor | |
| Right Motor Enable | 22 |
| Right Motor Pin 1 | 16 |
| Right Motor Pin 2 | 17 |
| Left Motor | |
| Left Motor Enable | 23 |
| Left Motor Pin 1 | 18 |
| Left Motor Pin 2 | 19 |
The 3d/ directory contains Fusion 360 (.f3d) design files and STL exports for mounting the ESP32 and components onto the tank chassis. Click the STL links to view interactive 3D previews on GitHub.
| Component | Description | Files |
|---|---|---|
| Barrel | Barrel mount for the IR LED transmitter and laser module | .f3d | .stl |
| Chassis Plate | Main mounting plate for ESP32, motor driver, and electronics | .f3d | .stl |
| Chassis Plate Rails | Rail system for attaching components to the chassis plate | .f3d | .stl |
| Turret | Turret assembly for mounting sensors and barrels with rotation capability | .f3d | .stl |
The .f3d files can be opened and modified in Autodesk Fusion 360. The .stl files are ready for 3D printing.
This project is set up for VS Code with the PlatformIO extension.
Setup:
- Install VS Code
- Install the PlatformIO IDE extension from the VS Code marketplace
- Open this project folder in VS Code
- PlatformIO will automatically detect
platformio.iniand install dependencies
Building and uploading:
- Click the PlatformIO toolbar icon (checkmark) to build
- Click the upload icon (arrow) to flash to ESP32
- Or use the command palette:
PlatformIO: Upload
If you prefer the command line:
Building and uploading:
platformio run --target uploadMonitoring serial output:
platformio device monitorThe project uses the following libraries (auto-installed by PlatformIO):
- NeoPixelBus - Advanced LED control
- PS4_Controller_Host - PS4 gamepad support
- Find your ESP32's MAC address (use included
showMacAddress.cpputility) - Pair your PS4 controller using a PC/smartphone app (search for (SixAxisPairTool)[https://docs.totemmaker.net/assets/files/sixaxis/SixaxisPairToolSetup-0.3.1.exe] must have sha256 hash: b274dfc581adbf50787b6498c2e6878447e2ebe0be78c296795295b91991c2f6)
- Set the controller's master address to your ESP32's MAC address
- Power on the controller - it should connect automatically
- Right Stick (one-stick mode): Forward/backward/left/right - combined movement
- Left Stick (two-stick mode): Forward/backward movement
- Right Stick (two-stick mode): Turning and pivot-in-place
- R1 / RB: Fire infrared shot + activate laser
- L1 / LB: Activate laser without firing
- Square / X: Pink team
- Cross / A: Blue team
- Circle / B: Orange team
- Triangle / Y: Green team
- D-Pad Up: Toggle joystick mode (one-stick ↔ two-stick)
- Share: Reset preferences to defaults
- L2 + R2 (held together): In-game preferences reset
- main_control: Core game logic and FreeRTOS task management
- PS4_gamepad: PS4 controller interface abstraction
- motor_control: Dual motor mixing with expo curves and driving modes
- motors: Low-level motor driver interface
- ir_fire / ir_sensors: Infrared transmission and reception using ESP32 RMT peripheral
- laser: Laser pointer control
- activity_lights: LED patterns for game state feedback
- flasher: LED flashing effects
- colors: Team color definitions
- prefs: Persistent preferences storage (EEPROM)
The firmware uses FreeRTOS tasks for concurrent handling of:
- IR message reception
- LED animations
- Motor control
- Gamepad input processing
Uses ESP32's RMT (Remote Control) peripheral for precise IR timing. Protocol details in src/IR32/ library. The system transmits team-specific codes to differentiate between friendly and enemy fire.
When hit, the MotorChaosMonkey class temporarily interferes with motor control, creating erratic movement to simulate being "stunned" in combat.
Game settings and team colors are persisted to EEPROM and loaded on boot.
Serial debugging at 115200 baud. Build flags in platformio.ini enable ESP_LOG output:
-DCORE_DEBUG_LEVEL=4
-D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
GPL-3.0 - See LICENSE










