Posts about... All (17) Android (2) Hooking Up Parts (10) Game Controllers (3) Robots (2)

Bluetooth Robot Driven With PS3 Controller [Code+Video]

In order to drive the robot with a PS3 controller, you can combine the ability to read a PS3 controller’s buttons and invoke key strokes with the ability to send commands to the robot via Bluetooth with the help of the Serial Monitor in the Arduino software.


The diagram above gives an overview of the process. Think of the left and right sides as two separate, simple processes. The left side reads a button press from the PS3 controller and converts that to a key stroke on the computer. The right side rotates the wheels of robot in a different direction based on what character it receives over bluetooth.

Processing Code

Arduino Code

The Arduino Side

  1. Upload the Arduino code to your board. (Tip: Before connecting the board to your computer with the USB cable, ensure the BlueSMiRF bluetooth module is unplugged from the RX-0 and TX-1 digital pins on the Arduino. Also disconnect any external power souce, such as a 9V battery.)
  2. Unplug the USB cable from the board. Plug in your BlueSMiRF to the RX-0 and TX-1. (Remember, RX on the BlueSMiRF should be wired to TX-1 on the Arduino and TX on the BlueSMiRF should be wired to RX-0 on the Arduino.) Connect the board to a 9V battery via the Vin pin on the Arduino.
  3. The BlueSMiRF should be flashing red. Change the Serial Port (under Tools in the menu) to the BlueSMiRF (mine displays as “FireFly”).
  4. Open the Serial Monitor in the Arduino software. This will connect to the BlueSMiRF as a serial port, allowing us to send commands to the robot wirelessly over bluetooth. If connected, the flashing red light should change to a steady green light and the Serial Monitor will open.
  5. Send commands to the Arduino by typing a letter in the input field and hitting Send. The commands I programmed are listed below.
    • U = “up” on; start rotating both wheels forward
    • u = “up” off; stop rotating both wheels forward
    • D = “down” on; start rotating both wheels backward
    • d = “down” off; stop rotating both wheels backward
    • L = “left” on; start rotating left wheel backward and right wheel forward
    • l = “left” off; stop rotating left wheel backward and right wheel forward
    • R = “right” on; start rotating left wheel forward and right wheel backward
    • r = “right” off; stop rotating left wheel forward and right wheel backward

    NOTE: Each uppercase command should be followed by its lowercase counterpart. In the end, when we press a button the PS3 controller, it will type an uppercase letter. When we release the button, it will type the same letter but lowercase.

With this functionality in place, all that’s left is to map the PS3 controller buttons to key strokes so that pressing a button on the PS3 controller will type in the Serial Monitor for us.

The Processing Side

  1. Connect your PS3 controller to your computer via bluetooth.
  2. Download the proCONTROLL library to easily enable you to read the PS3 controller buttons.
  3. Save the Processing code and run the program.
  4. Open a notepad application. Press any of the directional buttons the PS3 controller to ensure it working properly. For example when holding UP, it should type “U” and the enter key. Releasing UP should type “u” and the enter key. The enter key is what sends the character once in the Serial Monitor, saving us from having to click the Send button.
  5. Turn on your Arduino. Ensure the BlueSMiRF is chosen as the Serial Port and open the Serial Monitor. Place your cursor in the input field of the Serial Monitor and start using your PS3 controller to drive your robot!

Video