ESP 32 WITH PS5 CONTROLLER CAR

by bichagalpradyun in Circuits > Arduino

3113 Views, 6 Favorites, 0 Comments

ESP 32 WITH PS5 CONTROLLER CAR

Screenshot 2023-06-16 at 7.21.29 PM.png
Screenshot 2023-06-20 at 7.33.40 PM.png
Screenshot 2023-06-20 at 7.35.46 PM.png

The ESP32 car is a small robotic vehicle powered by the ESP32 microcontroller. It is designed to be controlled remotely using a PS5 controller, providing a seamless and intuitive interface for driving the car.

The ESP32 microcontroller is a versatile and powerful device known for its built-in Wi-Fi and Bluetooth capabilities. It allows the car to establish a wireless connection with the PS5 controller, enabling real-time control and responsiveness.

To set up the system, the ESP32 car needs to be equipped with a motor driver module that can control the movement of the car's motors, such as DC motors or servo motors. The ESP32 communicates with the motor driver, translating the commands received from the PS5 controller into appropriate signals for controlling the motors' speed and direction.

The PS5 controller is a popular and ergonomic gamepad designed for the PlayStation 5 gaming console. It offers various buttons, triggers, and joysticks, allowing for precise control inputs. By connecting the PS5 controller to the ESP32 car via Bluetooth, the user can wirelessly steer the car, accelerate or decelerate, and even perform other functions depending on the available controller features.

The ESP32 car's software is responsible for receiving input from the PS5 controller, interpreting the signals, and converting them into motor commands. It may include a mapping system that assigns specific controller inputs to corresponding car movements, such as forward, backward, left, and right.

Overall, the ESP32 car controlled by a PS5 controller offers an engaging and interactive experience. It combines the power of the ESP32 microcontroller, the versatility of the PS5 controller, and the convenience of wireless communication to create a fun and user-friendly remote-controlled car.

Supplies

Screenshot 2023-06-22 at 7.21.50 PM.png
Screenshot 2023-06-22 at 7.22.52 PM.png
Screenshot 2023-06-22 at 7.23.24 PM.png
FA4QT5ELJ4APZ32.png
Screenshot 2023-06-22 at 7.20.44 PM.png

Esp 32

ps5 controller

Car Chasis

Car motor x4

car wheels x4

jumper wires

18650 battery holder 3 cell

18650 battery x3

l293D Motor

screws

Tools needed:

  1. Screwdriver
  2. Drill (if necessary)
  3. Hot glue gun or adhesive (optional)
  4. Wire cutters/strippers

Assembling the Chassis

Screenshot 2023-06-23 at 3.48.11 PM.png
Screenshot 2023-06-22 at 7.20.44 PM.png
Assemble a 4WD Robot Smart Car Chassis Kit

assembly of chassis video

https://www.youtube.com/watch?v=dJszq4B5T5M

Step 1: Prepare the Chassis

  1. Lay the chassis on a flat surface with the top side facing up.
  2. Locate the four mounting holes on the chassis. These will be used to attach the motors later.

Step 2: Attach the Motors

  1. Take one motor and align its mounting holes with the corresponding holes on the chassis.
  2. Insert screws through the mounting holes of the motor and tighten them securely using a screwdriver.
  3. Repeat this process for the remaining three motors, ensuring that they are evenly spaced on the chassis.

Step 3: Mount the Wheels

  1. Take one wheel and slide it onto the shaft of a motor.
  2. Use a clamp to secure the wheel onto the motor shaft by tightening the screw on the clamp.
  3. Repeat this process for the remaining three wheels and motors.

Step 4: Connect the Motor Driver

  1. Identify the L293D motor driver board. It will have multiple pins and screw terminals.
  2. Connect the four motors to the motor driver board using jumper wires. Ensure that each motor is connected to the correct terminal, usually labeled "Motor 1," "Motor 2," "Motor 3," and "Motor 4."
  3. Connect the motor driver board to your microcontroller or Arduino board according to the manufacturer's instructions.

Step 5: Install the Battery Box and Switch

  1. Locate the battery box and switch.
  2. Attach the battery box to the chassis using screws or adhesive tape, ensuring that it is securely mounted.
  3. Connect the positive and negative terminals of the battery box to the corresponding terminals on the motor driver board.
  4. Mount the switch on the chassis using screws or adhesive tape.
  5. Connect the wires from the switch to the power input of the motor driver board, ensuring the correct polarity.

Step 6: Optional - Install a Speed Controller

  1. If you have a speed controller, connect it to the motor driver board according to the manufacturer's instructions.
  2. The speed controller will typically have inputs for controlling the speed of each motor. Connect the appropriate wires to the motor driver board.

Step 7: Final Checks

  1. Ensure that all connections are secure and free from any loose wires or components.
  2. Double-check that the motor wiring is correct and matches the motor driver board connections.
  3. Confirm that the wheels are properly mounted and can rotate freely.

Congratulations! You have successfully assembled the 4-Wheel Drive Smart Robot Bot. Now you can power it on and program it to perform various tasks or movements using your esp 32.

PINOUT OF ESP32

ESP32-Pinout.png

L293d Pinout

Screenshot 2023-06-30 at 8.49.21 AM.png

Ps5 Controller

Screenshot_2023-06-20_at_7.33.40_PM-removebg-preview (1).png
Screenshot 2023-06-30 at 8.52.19 PM.png
ps5-controller-mappings-v0-6jxav4y0w5981.png

The PlayStation 5 (PS5) controller, known as the DualSense, comes with several innovative features that enhance gaming experiences and offer a heightened sense of immersion. Here are some of its key features and how they work:

  1. Adaptive Triggers: The DualSense controller features adaptive triggers that can dynamically adjust the resistance felt when pressing the L2 and R2 triggers. Game developers can utilize this feature to provide tactile feedback that corresponds to in-game actions. For example, pulling back a bowstring might require more force than firing a pistol, adding a realistic feel to gameplay.
  2. Haptic Feedback: The DualSense incorporates advanced haptic feedback technology, replacing the traditional rumble function found in previous controllers. The haptic motors inside the controller can produce a wide range of vibrations and sensations, allowing players to feel subtle details like the texture of surfaces or the impact of different actions within the game.
  3. Built-in Speaker: The DualSense controller includes a built-in speaker that can emit sound effects, dialogue, or music directly from the controller itself. This feature adds an extra layer of immersion by providing audio feedback in tandem with the visuals on the screen.
  4. Motion Sensors: The controller is equipped with a gyroscope and an accelerometer, similar to those found in smartphones. These motion sensors can detect movements and tilt, enabling players to interact with games through gestures and motion controls.
  5. Create Button: The DualSense introduces a new button called the "Create" button, which replaces the "Share" button from the previous PlayStation controller. This button allows players to capture screenshots, record gameplay clips, and share their gaming moments with others.
  6. Touchpad: The touchpad on the front of the DualSense controller provides a touch-sensitive surface that game developers can utilize for various input methods. It can be used for precise cursor control, gesture recognition, or other interactive elements within games.
  7. Integrated Microphone: The DualSense features an integrated microphone array, allowing players to communicate with others during online multiplayer sessions without the need for a separate headset. However, for more reliable and high-quality voice chat, a dedicated headset is still recommended.
  8. USB-C Connectivity: The controller can be charged using a USB-C cable, providing faster charging times compared to the previous micro-USB standard. Additionally, the USB-C port can be used for wired gameplay, offering a low-latency connection for competitive gaming or when wireless connectivity is not available.

These features collectively enhance gameplay experiences by providing more immersive sensations, intuitive controls, and seamless communication options. The DualSense controller's innovative design and functionality aim to deliver a next-generation gaming experience on the PlayStation 5 console.

How to Interact With Ps5 Controller With Esp32

Screenshot 2023-06-30 at 8.18.05 PM.png

The ESP32 can act as a Bluetooth Low Energy peripheral device, allowing it to establish a connection with the PS5 controller and receive input data from it. By utilizing ESP32's BLE capabilities, you can create a wireless interface between the controller and the microcontroller for interaction and data processing.

Find Mac Adress of Your Dual Sensense Controller

Screenshot 2023-06-30 at 9.10.04 PM.png
Screenshot 2023-07-01 at 8.44.52 AM.png
PS5 Controller: How to Put Into Pairing Mode

First put the ps5 controller into pairing mode by

Press and hold the PS button and SHARE button on the wireless controller at the same time. The light bar on the back of the wireless controller will start flashing once pairing mode is active.


To find the BLE (Bluetooth Low Energy) MAC address of a device in the Android phone settings, follow these steps:

  1. Open the "Settings" app on your Android phone. You can usually find it in the app drawer or by swiping down from the top of the screen and tapping the gear-shaped icon.
  2. Scroll down and look for the "Connected devices" or "Bluetooth" option. Tap on it to access the Bluetooth settings.
  3. In the Bluetooth settings, you should see a list of paired or connected devices. Look for the specific device for which you want to find the BLE MAC address.
  4. Once you locate the device, tap on the settings icon (usually represented by a gear or an "i" symbol) next to it. This will open the device details or settings page.
  5. On the device details/settings page, scroll down or navigate to find the MAC address. It may be labeled as "MAC address," "Bluetooth address," or something similar.
  6. The displayed address should be the BLE MAC address of the device. It typically consists of a series of alphanumeric characters separated by colons or dashes.

Note: The steps may vary slightly depending on the Android phone model and version of the operating system. However, the general process should be similar across most Android devices.

note down the bluetooth mac adress we need it while coding

DIAGRAM

PS4 Controlled Tank.png

INSTALL LIBRARY

https://github.com/rodneybakiskan/ps5-esp32

INSTALL THIS LIBRARY WITH THE HELP OF THIS LINK

UPLOAD THE CODE

#include <ps5Controller.h>


void setup() {

 Serial.begin(921600);

 pinMode(16,OUTPUT);

 pinMode(17,OUTPUT);

 pinMode(18,OUTPUT);

 pinMode(19,OUTPUT);

 pinMode(22,OUTPUT);

 pinMode(23,OUTPUT);

 ps5.begin("1a:2b:3c:01:01:01"); //replace with MAC address of your controller

 Serial.println("Ready.");

 digitalWrite(22,HIGH);

 digitalWrite(23,HIGH);

}


void loop() {

// while (ps5.isConnected() == false) { // commented out as ps5 controller seems to connect quicker when microcontroller is doing nothing

//  Serial.println("PS5 controller not found");

//  delay(300);

// }


 while (ps5.isConnected() == true) {

  if (ps5.Right()) Serial.println("Right Button");

  if (ps5.Down()) Serial.println("Down Button");

  if (ps5.Up()) Serial.println("Up Button");

  if (ps5.Left()) Serial.println("Left Button");


  if (ps5.Square()) Serial.println("Square Button");

  if (ps5.Cross()) Serial.println("Cross Button");

  if (ps5.Circle()) Serial.println("Circle Button");

  if (ps5.Triangle()) Serial.println("Triangle Button");


  if (ps5.UpRight()) Serial.println("Up Right");

  if (ps5.DownRight()) Serial.println("Down Right");

  if (ps5.UpLeft()) Serial.println("Up Left");

  if (ps5.DownLeft()) Serial.println("Down Left");


  if (ps5.L1()) Serial.println("L1 Button");

  if (ps5.R1()) Serial.println("R1 Button");


  if (ps5.Share()) Serial.println("Share Button");

  if (ps5.Options()) Serial.println("Options Button");

  if (ps5.L3()) Serial.println("L3 Button");

  if (ps5.R3()) Serial.println("R3 Button");


  if (ps5.PSButton()) Serial.println("PS Button");

  if (ps5.Touchpad()) Serial.println("Touch Pad Button");


  if (ps5.L2()) {

   Serial.printf("L2 button at %d\n", ps5.L2Value());

  }

  if (ps5.R2()) {

   Serial.printf("R2 button at %d\n", ps5.R2Value());

  }


  if (ps5.LStickX()) {

   Serial.printf("Left Stick x at %d\n", ps5.LStickX());

    

  }

  if (ps5.LStickY()) {

   Serial.printf("Left Stick y at %d\n", ps5.LStickY());

   if(ps5.LStickY()>100){

    digitalWrite(16,HIGH);

    digitalWrite(17,LOW);

   }

   else{

    digitalWrite(17,LOW);

    digitalWrite(16,LOW);

   }

   }

   if(ps5.LStickY()<20){

    digitalWrite(17,HIGH);

    digitalWrite(16,LOW);

   }

   else{

    digitalWrite(16,LOW);

    digitalWrite(17,LOW);

   }

  }

  if (ps5.RStickX()) {

   Serial.printf("Right Stick x at %d\n", ps5.RStickX());

  }

  if (ps5.RStickY()) {

   Serial.printf("Right Stick y at %d\n", ps5.RStickY());

    if(ps5.RStickY()>100){

    digitalWrite(18,HIGH);

    digitalWrite(19,LOW);

   }

   else{

    digitalWrite(19,LOW);

    digitalWrite(18,LOW);

   }

   if(ps5.RStickY()<20){

    digitalWrite(19,HIGH);

    digitalWrite(18,LOW);

   }

   else{

    digitalWrite(19,LOW);

    digitalWrite(18,LOW);

   }

  }


  Serial.println();

  // This delay is to make the output more human readable

  // Remove it when you're not trying to see the output

  //delay(300);

 }

Explaination the Code

The code you provided seems to be an example of how to control various outputs based on the input from a PS5 controller using an ESP32 board. Here's a breakdown of how the code works:

  1. In the setup() function:
  • The serial communication is initiated with a baud rate of 921600.
  • Several pins (16, 17, 18, 19, 22, and 23) are set as OUTPUT pins.
  • The PS5 controller is initialized using the begin() function, with the MAC address of the controller provided as an argument.
  • The digital pins 22 and 23 are set to HIGH, which might indicate some specific setup for your particular project.
  1. In the loop() function:
  • The code checks if the PS5 controller is connected using the isConnected() function.
  • If the controller is connected, it checks for various button presses and joystick movements using functions like Right(), Down(), L1(), etc.
  • If a button or joystick movement is detected, a corresponding message is printed using Serial.println().

In the code, there are also sections that control the motor outputs based on the joystick movements:

  • The code checks the values of the left joystick's y-axis (ps5.LStickY()) and right joystick's y-axis (ps5.RStickY()).
  • If the joystick value is above 100, it sets the corresponding motor control pins (16 and 17 for the left motor, 18 and 19 for the right motor) to control the motor in one direction.
  • If the joystick value is below 20, it sets the motor control pins to control the motor in the opposite direction.
  • Otherwise, it sets the motor control pins to stop the motor.

It's important to note that the code assumes you have connected the motor control pins to the appropriate pins on the ESP32 board. Also, make sure to have the necessary libraries and dependencies installed to use the PS5 controller and motor control functions properly.

Trouble Shooting Tip

if the ps5 does not connect restart the ps5 controller it will connect try couple of times tif it still does not connect check the mac adress or restart the esp32

Congratulations We Finished the Project Now You Can Play With It

FSW0I0PLJIL48T8.png
F3IPMPYLJ4APZ41.png
F8BDSQALJIL49KS.png
F6UZN7CLJH5OGXW.png
F68J1W8LJIL4DR5.png
F33GMT4LJIL4A1T.png
FY67EHILJIL4DSN.png
FOC9Z9KLJ75L9H4.png
F90SARQLJIL490O.png

Thanks To

WorldofTech for pairing mode video

for any queries you can dm me on https://www.linkedin.com/in/pradyun-bichagal-0a6a10221