├── Diagrams └── Robot Arm Car.png ├── GetBluetoothMacAddress └── GetBluetoothMacAddress.ino ├── LICENSE ├── README.md └── Robot_Arm_Car └── Robot_Arm_Car.ino /Diagrams/Robot Arm Car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/un0038998/RobotArmCar/98d3e1aaec26d1fa62869fa5bdd5dd60c1bcfbef/Diagrams/Robot Arm Car.png -------------------------------------------------------------------------------- /GetBluetoothMacAddress/GetBluetoothMacAddress.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() 4 | { 5 | Serial.begin(115200); 6 | Ps3.begin(); 7 | 8 | String address = Ps3.getAddress(); 9 | 10 | Serial.print("The ESP32's Bluetooth MAC address is: "); 11 | Serial.println(address); 12 | } 13 | 14 | void loop() 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ujwal Nandanwar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Robot-Arm-Car 2 | This repository contains code and diagram for Robot Arm Car with PS3 Controller and esp32 3 | -------------------------------------------------------------------------------- /Robot_Arm_Car/Robot_Arm_Car.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SERVO_FORWARD_STEP_ANGLE 1 5 | #define SERVO_BACKWARD_STEP_ANGLE -1 6 | 7 | struct ServoPins 8 | { 9 | Servo servo; 10 | int servoPin; 11 | String servoName; 12 | int initialPosition; 13 | }; 14 | std::vector servoPins = 15 | { 16 | { Servo(), 27 , "Base", 90}, 17 | { Servo(), 26 , "Shoulder", 90}, 18 | { Servo(), 25 , "Elbow", 90}, 19 | { Servo(), 33 , "Gripper", 90}, 20 | }; 21 | 22 | bool gripperSwitch = false; 23 | 24 | //Right motor 25 | int enableRightMotor=22; 26 | int rightMotorPin1=16; 27 | int rightMotorPin2=17; 28 | //Left motor 29 | int enableLeftMotor=23; 30 | int leftMotorPin1=18; 31 | int leftMotorPin2=19; 32 | 33 | #define MAX_MOTOR_SPEED 200 //Its value can range from 0-255. 255 is maximum speed. 34 | 35 | const int PWMFreq = 1000; /* 1 KHz */ 36 | const int PWMResolution = 8; 37 | const int PWMSpeedChannel = 4; 38 | 39 | void writeServoValues(int servoIndex, int servoMoveStepSize, bool servoStepSizeIsActualServoPosition = false) 40 | { 41 | int servoPosition; 42 | if (servoStepSizeIsActualServoPosition) 43 | { 44 | servoPosition = servoMoveStepSize; 45 | } 46 | else 47 | { 48 | servoPosition = servoPins[servoIndex].servo.read(); 49 | servoPosition = servoPosition + servoMoveStepSize; 50 | } 51 | if (servoPosition > 180 || servoPosition < 0) 52 | { 53 | return; 54 | } 55 | 56 | servoPins[servoIndex].servo.write(servoPosition); 57 | } 58 | 59 | 60 | void notify() 61 | { 62 | int rx =(Ps3.data.analog.stick.rx); //Base => Right stick - x axis 63 | int ry =(Ps3.data.analog.stick.ry); //Shoulder => Right stick - y axis 64 | int ly =(Ps3.data.analog.stick.ly); //Elbow => Left stick - y axis 65 | int lx =(Ps3.data.analog.stick.lx); //Gripper => Left stick - x axis 66 | 67 | if (rx > 50) 68 | { 69 | writeServoValues(0, SERVO_BACKWARD_STEP_ANGLE); 70 | } 71 | else if (rx < -50) 72 | { 73 | writeServoValues(0, SERVO_FORWARD_STEP_ANGLE); 74 | } 75 | 76 | if (ry > 50) 77 | { 78 | writeServoValues(1, SERVO_BACKWARD_STEP_ANGLE); 79 | } 80 | else if (ry < -50) 81 | { 82 | writeServoValues(1, SERVO_FORWARD_STEP_ANGLE); 83 | } 84 | 85 | if (ly > 50) 86 | { 87 | writeServoValues(2, SERVO_FORWARD_STEP_ANGLE); 88 | } 89 | else if (ly < -50) 90 | { 91 | writeServoValues(2, SERVO_BACKWARD_STEP_ANGLE); 92 | } 93 | 94 | if (lx > 50) 95 | { 96 | writeServoValues(3, SERVO_BACKWARD_STEP_ANGLE); 97 | } 98 | else if (lx < -50) 99 | { 100 | writeServoValues(3, SERVO_FORWARD_STEP_ANGLE); 101 | } 102 | 103 | if (Ps3.event.button_down.r2) 104 | { 105 | gripperSwitch = !gripperSwitch; //Toggle gripper close / open 106 | gripperSwitch ? writeServoValues(3, 170, true) : writeServoValues(3, 100, true) ; 107 | } 108 | 109 | if (Ps3.data.button.up) //Move car Forward 110 | { 111 | rotateMotor(MAX_MOTOR_SPEED, MAX_MOTOR_SPEED); 112 | } 113 | else if (Ps3.data.button.down) //Move car Backward 114 | { 115 | rotateMotor(-MAX_MOTOR_SPEED, -MAX_MOTOR_SPEED); 116 | } 117 | else if (Ps3.data.button.right) //Move car Right 118 | { 119 | rotateMotor(-MAX_MOTOR_SPEED, MAX_MOTOR_SPEED); 120 | } 121 | else if (Ps3.data.button.left) //Move car Left 122 | { 123 | rotateMotor(MAX_MOTOR_SPEED, -MAX_MOTOR_SPEED); 124 | } 125 | else //Stop the car 126 | { 127 | rotateMotor(0, 0); 128 | } 129 | 130 | delay(10); 131 | 132 | } 133 | 134 | void onConnect() 135 | { 136 | Serial.println("Connected!."); 137 | } 138 | 139 | void onDisConnect() 140 | { 141 | Serial.println("Disconnected!."); 142 | } 143 | 144 | void rotateMotor(int rightMotorSpeed, int leftMotorSpeed) 145 | { 146 | if (rightMotorSpeed < 0) 147 | { 148 | digitalWrite(rightMotorPin1,LOW); 149 | digitalWrite(rightMotorPin2,HIGH); 150 | } 151 | else if (rightMotorSpeed > 0) 152 | { 153 | digitalWrite(rightMotorPin1,HIGH); 154 | digitalWrite(rightMotorPin2,LOW); 155 | } 156 | else 157 | { 158 | digitalWrite(rightMotorPin1,LOW); 159 | digitalWrite(rightMotorPin2,LOW); 160 | } 161 | 162 | if (leftMotorSpeed < 0) 163 | { 164 | digitalWrite(leftMotorPin1,LOW); 165 | digitalWrite(leftMotorPin2,HIGH); 166 | } 167 | else if (leftMotorSpeed > 0) 168 | { 169 | digitalWrite(leftMotorPin1,HIGH); 170 | digitalWrite(leftMotorPin2,LOW); 171 | } 172 | else 173 | { 174 | digitalWrite(leftMotorPin1,LOW); 175 | digitalWrite(leftMotorPin2,LOW); 176 | } 177 | } 178 | 179 | void setUpPinModes() 180 | { 181 | for (int i = 0; i < servoPins.size(); i++) 182 | { 183 | servoPins[i].servo.attach(servoPins[i].servoPin); 184 | servoPins[i].servo.write(servoPins[i].initialPosition); 185 | } 186 | 187 | pinMode(enableRightMotor,OUTPUT); 188 | pinMode(rightMotorPin1,OUTPUT); 189 | pinMode(rightMotorPin2,OUTPUT); 190 | 191 | pinMode(enableLeftMotor,OUTPUT); 192 | pinMode(leftMotorPin1,OUTPUT); 193 | pinMode(leftMotorPin2,OUTPUT); 194 | 195 | //Set up PWM for motor speed 196 | ledcSetup(PWMSpeedChannel, PWMFreq, PWMResolution); 197 | ledcAttachPin(enableRightMotor, PWMSpeedChannel); 198 | ledcAttachPin(enableLeftMotor, PWMSpeedChannel); 199 | ledcWrite(PWMSpeedChannel, MAX_MOTOR_SPEED); 200 | 201 | rotateMotor(0, 0); 202 | } 203 | 204 | 205 | void setup() 206 | { 207 | setUpPinModes(); 208 | Serial.begin(115200); 209 | Ps3.attach(notify); 210 | Ps3.attachOnConnect(onConnect); 211 | Ps3.attachOnDisconnect(onDisConnect); 212 | Ps3.begin(); 213 | Serial.println("Ready."); 214 | } 215 | 216 | void loop() 217 | { 218 | } 219 | --------------------------------------------------------------------------------