Introduction: Bluetooth Remote Control - XBox Gamepad

Initially this project was to create a remote control for a Spider Bot robot created via: https://www.instructables.com/DIY-Spider-RobotQuad-robot-Quadruped/ with additional guide provided here on basic remote control https://www.instructables.com/DIY-Spider-Robot-PART-II-Remote-control/.

The goal was to be able to control the robot without the phone or computer around.

I decided to create a Bluetooth to Bluetooth controller that looks like XBox pad. With Arduino controller, BT module, couple other components and a 3d printed enclosure I managed to create some fine looking controller. Let me share how it was done.

Supplies

Since this project is initially for the Spider Bot so this is quite obvious that you need one first :) Consult the guides from RegisHsu to build your own. General concept is applicable to any other projects too.

Following electronics parts are required:

  • arduino board
  • BT module(s)
  • 18650 battery module
  • LI-ION charger module
  • step-up module
  • 1xLED
  • 8x push-buttons
  • few resistors
  • cables
  • soldering iron

To print a case a 3d printer (or a friend with a 3d printer) is needed. More on this below.

More on selected board and module types below.

Step 1: Shopping List - Needed Parts

I used following modules:

  1. Arduino NANO 3.0 ATMEGA328 CH340 board specifically because of space constraints in the printed case (more on this below). You can use any Arduino board you like.
  2. HC-05 Bluetooth module - this one was used already in the spider bot so for compatibility I used the same. Also this module allows to set Master/Slave mode which is critical for this setup as those two need to connect automatically. More on connection below. Note that two resistors are recommended to connect this BT module. See the circuit drawing below.
  3. 18650 battery and TP4056 usb charging module - as a power source I used 18650 LI-ION battery. TP4056 takes care of the charging and also acts as a safety so that battery is not discharged too much. You can use any other module you like that does the trick.
  4. As Arduino needs 5V and battery offers only 3.7V you need a step-up module. I used MT3608 based module to boost the voltage to 5V. Any other will do the trick too.

Additionally a switch and a LED was put in to make things work nicely.


Step 2: BT Modules Config and Communication Concept

Why HC-05 module?

Originally in the instructions from HERE RegisHsu uses HC-06 BT module. I decided to use HC-05 as you can setup a pair as they allow Master/Slave configuration. This is needed to ensure automatic connection between remote and the spider bot.

Communication concept

The whole concept is super simple. Both HC-05 Bluetooth modules are connected to serial pins of Arduino. This way:

  • anything received via BT will be sent to Arduino serial
  • anything sent to serial port of Arduino will be picked up and sent via BT module

Since we want to pair those modules to connect automatically following concept is in place:

  • Remote will act as master
  • Master will connect to slave once powered up
  • On button push master will send a string with command to serial
  • Slave will read the serial and react once command is detected


Configuration of modules

Please follow this instructions to setup your modules: https://www.instructables.com/How-to-Configure-HC-05-Bluetooth-Module-As-Master-/

Note: I stayed with 9600 baud rate. If you change it please change accordingly in Arduino code.

More info

Also, if you want to understand more about this communication method you can read more here:

https://howtomechatronics.com/tutorials/arduino/how-to-configure-pair-two-hc-05-bluetooth-module-master-slave-commands/

Step 3: Arduino Code

Arduino code is super simple. Whenever a button is pressed a message is sent to serial. Once it's sent to serial the BT module picks it up and sends to connected device - in this case a second BT connected to the spider bot.

I've attached both remote and spider bot code as files. Spider bot code - created by RegisHsu with some minor adjustments by me.

Here's the code:

// BT remote code
// make sure you ensure proper serial speed
// no libraries needed

const int buttonForward = 2; // D1 was 12
const int buttonBack = 3; // D2 was 4
const int buttonLeft = 4; // D3 was 5
const int buttonRight = 5; // D4 was 14

const int buttonStand = 6; // D2 was 4
const int buttonWave1 = 8; // D3 was 5
const int buttonWave2 = 9; // D4 was 14
const int buttonDance = 7; // D8 was 15

int buttonStateForward = 0;
int buttonStateBack = 0;
int buttonStateLeft = 0;
int buttonStateRight = 0;

int buttonStateStand = 0;
int buttonStateWave1 = 0;
int buttonStateWave2 = 0;
int buttonStateDance = 0;


bool sitornot = false;


void setup() {
  Serial.begin(9600);
  Serial.println("Boot OK. Connecting BT...");
  delay(2000);


  pinMode(buttonForward, INPUT);
  pinMode(buttonBack, INPUT);
  pinMode(buttonLeft, INPUT);
  pinMode(buttonRight, INPUT);


  pinMode(buttonStand, INPUT);
  pinMode(buttonWave1, INPUT);
  pinMode(buttonWave2, INPUT);
  pinMode(buttonDance, INPUT);
  
}


void loop() {

  buttonStateForward = digitalRead(buttonForward);
  buttonStateBack = digitalRead(buttonBack);
  buttonStateLeft = digitalRead(buttonLeft);
  buttonStateRight = digitalRead(buttonRight);


  buttonStateStand = digitalRead(buttonStand);
  buttonStateWave1 = digitalRead(buttonWave1);
  buttonStateWave2 = digitalRead(buttonWave2);
  buttonStateDance = digitalRead(buttonDance);


  if (buttonStateForward == HIGH){
    Serial.println("w 1 2");
    delay(1000);
  }
  if (buttonStateBack == HIGH){
    Serial.println("w 2 2");
    delay(1000);
  }
  if (buttonStateLeft == HIGH){
    Serial.println("w 3 2");
    delay(1000);
  }
  if (buttonStateRight == HIGH){
    Serial.println("w 4 2");
    delay(1000);
  }


  if (buttonStateStand == HIGH){
    if (sitornot) {
      Serial.println("w 0 1");
      sitornot = true;
    } else {
      Serial.println("w 0 0");
      sitornot = false;
    }
    delay(1000);
  }
  if (buttonStateWave1 == HIGH){
    Serial.println("w 5 2");
    delay(1000);
  }
  if (buttonStateWave2 == HIGH){
    Serial.println("w 6 2");
    delay(1000);
  }
  if (buttonStateDance == HIGH){
    Serial.println("w 7 10");
    delay(1000);
  }


}

Step 4: Connect All Together

Connecting all together is relatively easy. Make sure not to short the 18650 module as it might get hot :)

As I've put all of that in the enclosure I tried to make it as fit as possible.

Step 5: Lets Make It Look Like XBOX Pad

Fusion 360 came in handy in the design process. I printed all from PETG material. There are two main parts of the body plus 16 parts for the buttons in total. No supports required for this print.

You can download the model and STL files on Printables: https://www.printables.com/model/563238-gamepad-controller-for-your-diy-projects

Step 6: Final Assembly

As you can see on the photos the strategy is just "let it fit in". I used a bit of glue to keep the battery, step-up and the charging module.

Step 7: Have Fun