ESP32 TurtleBot Controlled With PS4 Controller
by AffanIman01 in Circuits > Remote Control
26 Views, 0 Favorites, 0 Comments
ESP32 TurtleBot Controlled With PS4 Controller
This project is literally foundation for robotic car as from this it can develop to more advanced function with PS4 Controller and other function modularity part like shooting, robotic arm and other. You can make it more advanced into micro-ROS. All resources are available in my drive. This is my first post here and i will be sharing more project sooner on robotic and drone.
Supplies
Material used :
- 3D-Printed Chassis (3 Part to need printed)
- 7mm length M3 PCB Standoff
- M3 Screw and Bolt
- TT Motor with 40cm Wires and Wheel Kit (x2)
- W420 Steel Ball Universal Wheel (Castor)
- ESP32 Microcontroller
- 2Amp 7V-30V L298N Motor Driver
- ESP32 Expansion Board
- 3x 18650 Battery with battery case/Powerbank
Print 3D Turtlebot Chassis
The step would be easy peazy as count 1,2,3. Firstly, bro need to print the chassis first. Total 3d part to be print up is only 3 parts.
Assembly the Turtlebot Chassis With Other Part
Second, assembly mechanical part with is caster ball, tt motor, pcb standoff and motor driver like the picture.
Circuit Assembly
Thirdly, follow wiring circuit as schematic diagram.
Setup SixAxisPairTool to Pair PS4 Controller With ESP32
Download this pair with the esp32 https://sixaxispairtool.en.lo4d.com/windows
Copy and Run the Code
#include <PS4Controller.h>
// Motor control pins for movement
#define MOTOR1_IN1 16 // Motor 1 forward
#define MOTOR1_IN2 17 // Motor 1 backward
#define MOTOR2_IN3 18 // Motor 2 forward
#define MOTOR2_IN4 19 // Motor 2 backward
#define DEADZONE 10 // Deadzone for joystick sensitivity
void setup() {
Serial.begin(115200);
PS4.begin();
Serial.println("Ready.");
pinMode(MOTOR1_IN1, OUTPUT);
pinMode(MOTOR1_IN2, OUTPUT);
pinMode(MOTOR2_IN3, OUTPUT);
pinMode(MOTOR2_IN4, OUTPUT);
stopMotors();
}
void loop() {
if (PS4.isConnected()) {
handleMovement();
delay(10); // Delay for loop stability and responsiveness
}
}
void handleMovement() {
int lx = PS4.LStickX();
int ly = PS4.LStickY();
lx = (abs(lx) > DEADZONE) ? lx : 0;
ly = (abs(ly) > DEADZONE) ? ly : 0;
if (ly > 0) {
moveForward(ly);
} else if (ly < 0) {
moveBackward(abs(ly));
} else if (lx > 0) {
turnRight(lx);
} else if (lx < 0) {
turnLeft(abs(lx));
} else {
stopMotors();
}
}
void stopMotors() {
digitalWrite(MOTOR1_IN1, LOW);
digitalWrite(MOTOR1_IN2, LOW);
digitalWrite(MOTOR2_IN3, LOW);
digitalWrite(MOTOR2_IN4, LOW);
}
void moveForward(int speed) {
digitalWrite(MOTOR1_IN1, HIGH);
digitalWrite(MOTOR1_IN2, LOW);
digitalWrite(MOTOR2_IN3, HIGH);
digitalWrite(MOTOR2_IN4, LOW);
}
void moveBackward(int speed) {
digitalWrite(MOTOR1_IN1, LOW);
digitalWrite(MOTOR1_IN2, HIGH);
digitalWrite(MOTOR2_IN3, LOW);
digitalWrite(MOTOR2_IN4, HIGH);
}
void turnLeft(int speed) {
digitalWrite(MOTOR1_IN1, HIGH);
digitalWrite(MOTOR1_IN2, LOW);
digitalWrite(MOTOR2_IN3, LOW);
digitalWrite(MOTOR2_IN4, HIGH);
}
void turnRight(int speed) {
digitalWrite(MOTOR1_IN1, LOW);
digitalWrite(MOTOR1_IN2, HIGH);
digitalWrite(MOTOR2_IN3, HIGH);
digitalWrite(MOTOR2_IN4, LOW);
}