Please respect the project and follow me.
Step #1Put the USB Shield on the top of the Arduino.
Step #2Upload the code to your Arduino.
#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);
}
}
}
Plug the Bluetooth dongle in the USB shield.
open the serial and wait until the Arduino will read the Bluetooth dongle then unplug it and connect your PS3 control to the USB shield and wait until the Arduino will change the mac address of the PS3 controller then unplug it an plug the Bluetooth dongle again and press the center button in the PS3 controller (HOME BUTTON(power on)) and the PS3 will be connected by seeing the number 1 on the controller is on. and on the serial it will tell you that the PS3 controller is connected and ready to use. then the angle of the servo will be showing in the serial.
Enjoy. Please Respect this project and follow me Youssef Emad. :-)
Comments