Esp32 Ble Gamepad

About the project

A DIY handheld Gamepad using ESP32 and Communicates over BLE

Project info

Difficulty: Moderate

Platforms: AndroidWindows

Estimated time: 1 hour

License: MIT license (MIT)

Items used in this project

Hardware components

MT3608 boost converter MT3608 boost converter Capacitors / Tantalum Electrolytic x 1
TP4056 battery charging circuit with protection TP4056 battery charging circuit with protection x 1
3 way toggle switch 3 way toggle switch x 1
18560 battery and Battery holder 18560 battery and Battery holder x 2
Push button Push button x 8
Angle Push Button Angle Push Button x 2
Joystick Joystick x 2
ws2812b ws2812b x 6
esp32 esp32 x 1

View all

Software apps and online services

Arduino IDE Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic) Soldering iron (generic) x 1

Story

1 / 4

Description

This is a DIY handheld gamepad, made using ESP32 microcontroller. You might have seen such game controllers before. But most of them use Arduino. Or more specifically Arduino pro micro or Leonardo board. Because these boards support HID, or human interface devices over USB. but esp32 doesn't have such feature. So how do we do it? Well, esp32 does have BLE, or Bluetooth low energy, which we can use to communicate wirelessly, over Bluetooth.

DETAILS

So we have ESP32 module, as the central controller, then we have the USB type-C port, and a 3.3v regulator to convert 5v to 3.3v. Then we have the programming circuit, using ch340c usb to serial converter with auto programming mode and auto reset circuitry using duel transistors. We also have a battery charging circuit, along with overcharge, and over discharge protection. Which then boost up to 5v, using the boost converter ic. Next we have the joysticks, D-Pad buttons, trigger buttons, Neopixel LEDs, i2c port. And finally a 3way switch, to toggle between USB power and battery power.

The gamepad has

  • 2 analog joysticks
  • 2 trigger buttons
  • 2 D-Pads
  • 6 addressable RGB LEDs
  • and a i2c port

It can run using 2 18650 Li ion cells, which can be changed using the USB type-C port. And it can also be used to program the microcontroller. The design is inspired by the new ps5 controller, to give it a better look. The GPIO4 is connected to the battery using a voltage divider. So that we can measure the battery voltage. the NeoPixel LEDs will indicates if the controller is connected to a device or battery voltage is low.

The code is based on BLE Gamepad library by lemmingDev. In the code I have defined all the GPIO pins for different inputs. Then in the setup there are some initial led animations. And as soon as the board is connected to the device, all LEDs will turn Green. And it will check battery voltage, in a time interval, which is defined earlier. Then we get the button states, and set the gamepad buttons accordingly. Then we take the analog inputs, and map it to suitable values. And finally set the axis according to the values we received. After uploading the code open Bluetooth menu on your Smartphone or PC and you will see a new device pops up. click on that to connect it and you are ready to play.

Schematics, diagrams and documents

Schematic

Code

Source Code

Credits

Photo of ElectroPoint

ElectroPoint

Electronics Engineer, Maker, YouTuber

   

Leave your feedback...