Help W/Controlling servo from USB host shield W/PS3 controller


I'm moderately new to Arduino and trying to make a pan and tilt mount with two Stepper motors. I have successfully used a stepper motor with a joystick with proportional speed as well as with a servo. (All from the Super Starter kit UNO R3 Project). I am now trying to control a stepper and Servo from a ps3 controller. I have successfully got the USB shield to recognize and read the PS3 controller and can see the joystick reading's on the serial monitor. However I cannot get the controller to control the Servo or Stepper. I have attached my Code for the servo, since it seems easier to figure out first, for any recommendations and critiques to make it work.

I have been stuck on this for a while and have tried multiple configurations of my code.

#include <PS3BT.h>
#include <usbhub.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>

USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside

BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
PS3BT PS3(&Btd); // This will just create the instance
//PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

bool printTemperature, printAngle;

//SErvo start 
#include <Servo.h>
Servo Xservo;
int servopin=11;
int Xval;
//servo end

void setup() {
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  Serial.print(F("\r\nPS3 Bluetooth Library Started"));

void loop() {

  Xval = PS3.getAnalogHat(RightHatX);
  Xval= map(Xval,0,255,0,180);

  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
    Serial.println(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 180));

I don't understand the point of that if statement. You just gt a value from it didn't you? But anyway why don't you just Serial.println(Xval)? That's what you're writing to the servo. Do you see the values you expect?

If it's writing correct values to the servo then most servo problems turn out to be power problems. How is your servo powered?


Hello Steve,

I did try the code with out the if Statement and its still not moving. I am powering the servo with the 5v output on the arduino via the shield. I also have it grounded directly to the arduino via the shield. I do know the servo is getting sufficient power because untill the ps3 controller is synced it acts spastic and is moving non stop. but once the controller is connected the servo doesn't react at all to anything.

I do see the values on the Serial monitor I expect, the servo is just not moving in accordance with them at all

What servo is it? What shield?

My guess is whatever the shield is it can't provide enough power for the servo. Try separate power source, 4 x AA batteries (preferably NiMH rechargeables like Eneloops) should work.


It is a Micro Servo 9g... SG90. I'll give the batteries a try and get back. Thanks