Youssef Sabaa
Published

PS3 Controller Control Servo Wireless

This project will show you how to connect PS3 controller to your Arduino wirelessly to control a 180 degrees servo.

IntermediateFull instructions provided37,359
PS3 Controller Control Servo Wireless

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
PS3 Controller
×1
Servos (Tower Pro MG996R)
×1
USB Shield
×1

Story

Read more

Code

ps3_cont._robot.ino

C/C++
#include <SPI.h>
#include <PS3BT.h>                                                    //Include the necessary libraries.
#include <Servo.h>
USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);

Servo servo1;                                                         //Create instances of type Servo. servo1 is the steering servo and servo2 is the ESC.
Servo servo2;

void setup() {
   Serial.begin(115200);
  
   if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nPS3 Bluetooth Library Started"));

  servo1.attach(9);                                                  //Steering servo on digital pin 5
}
void loop()
{
  Usb.Task();

  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
  
    servo1.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 180));
    servo2.write(map(PS3.getAnalogHat(LeftHatY), 0, 255, 180, 0));
    Serial.println(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 180));
  }
  if (PS3.getButtonClick(UP)) {
    digitalWrite(Led, HIGH);

    Serial.print(F("\r\nUp"));

     if (PS3.PS3Connected) {
      PS3.setLedOff();
      PS3.setLedOn(LED1);

    }
  }
}

Credits

Youssef Sabaa

Youssef Sabaa

5 projects • 53 followers

Comments