This article is from the homepage of Curious Ya Bin.
There are many posts abroad about using a PS4 controller as an Arduino remote control (because the original works are mostly abroad). I searched for information in domestic communities and forums, and there is almost none on this topic, with the most being about PS2 controllers and some about PS3 controllers, but the information is not comprehensive. Recently, I managed to control Arduino with a PS4 controller via Bluetooth, so I wrote a tutorial to share. If you are both a PS4 gamer and a maker, you can learn how to use a PS4 controller as an Arduino controller and make use of the controller.
Implementing a PS4 controller as an Arduino controller is actually quite simple. The USB Host Shield library provides two methods: one is to control it using a USB data cable, which is very simple once the hardware is set up and the library example is burned, but using a wired connection is not suitable for a remote controller, so I won’t discuss this method.
The second method is to use a Bluetooth adapter for wireless control, which is more suitable for controlling small cars and robots. The key here is pairing the Bluetooth adapter. Using a PS4 controller for projects is more impressive compared to using PS2 or mobile Bluetooth remote controls. Without further ado, let’s prepare as follows!
Required Hardware:
-
PS4 Controller
-
USB Bluetooth 4.0 Adapter
-
USB Host Shield Board
-
Arduino UNO
Required Software and Libraries:
-
Arduino IDE: https://www.arduino.cc/en/Main/Software
-
USB Host Shield 2.0: https://github.com/felis/USB_Host_Shield_2.0
My PS4 controller is the new slim version, which has a light bar on the touchpad. I previously bought a Bluetooth 2.0 adapter but couldn’t pair it no matter what, but when I switched to a Bluetooth 4.0 adapter, it paired successfully right away. I used a Bluetooth 4.0 adapter called Orico; I’ve heard that the Ugreen Bluetooth 4.0 adapter works well too, so I recommend buying these two brands. I used a full-size USB Host Shield; there is also a mini version I haven’t used before. For the Arduino board, either UNO or MEGA works, and I used the classic UNO here.
After installing the Arduino IDE, download the USB Host Shield library file, right-click to extract it to the current folder, rename the USB_Host_Shield_2.0-master folder to USB_Host_Shield_2.0 (it’s okay if you don’t rename it, it just looks better), and then copy the entire folder to the libraries folder of the Arduino IDE, which is usually located at
My Computer --> My Documents --> Arduino --> libraries
. There is also a method to install library files online: in the IDE menu, click Project –> Load Library –> Manage Libraries, then wait for the network to load the library list, and enter usb in the search box to find USB_Host_Shield2.0 and install it. However, this method sometimes has loading failures.
After successful installation, reopen the software, File --> Examples --> USB_Host_Shield_2.0
. Here you can find the library we just added.
Next, we will upload the BTPS4 example under Bluetooth, and we will look at the pairing code below.
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
PS4BT PS4(&Btd, PAIR);
// After that you can simply create the instance like so and then press the PS button on the device
//PS4BT PS4(&Btd);
The default example code requires removing the comment from the line PS4BT PS4(&Btd, PAIR);
during the first pairing, and adding the comment to //PS4BT PS4(&Btd);
to indicate entering pairing mode. After burning the code and powering on, simultaneously press the PS and SHARE buttons on the PS4 controller to enter pairing mode. The LED light on the controller will blink quickly, and once paired with the Bluetooth adapter, the LED will stay on. You can comment out the original pairing code //PS4BT PS4(&Btd, PAIR);
and enable PS4BT PS4(&Btd);
to re-burn the code, so you won’t have to enter pairing mode again when powering on, just like below.
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
//PS4BT PS4(&Btd, PAIR);
// After that you can simply create the instance like so and then press the PS button on the device
PS4BT PS4(&Btd);
Below is a casually recorded video.
Author: Curious Ya Bin
For links to the article text, program code, and other resources, please click 【Read More】 to view
Submission: [email protected]
Leave a Comment
Your email address will not be published. Required fields are marked *