Bluetooth robotic dancer

This basic pan & tilt robot is controlled via an Android smartphone, using a virtual joystick

The code on the Arduino side is rather straighforward
Tip: the SoftwareSerial and the servo libraries don't collaborate happily, I learnt it the hard way :~

More info re Joystick Bluetooth Commander application here

Enjoy

I posted a BlinkM (RGB LED) project based on Joystick Bluetooth Commander, in the LEDs and Multiplexing Section

Interesting. Perhaps you could outfit the robot and make it look a little bit better. Thin layer of plastic? Not sure, I'm still new to this. Also, you could do something along the lines of it being able to function multiple limbs at once: I.E: One arm up, at the same time, another arm going down, while spinning in a circle. You might be able to do something with this in the toy industry.

Thanks for the comments

The robot was quickly assembled using available parts, including an old parallax sonic sensor for the head :wink:
The all project is just a proof of concept for the Joystick Bluetooth Commander application

Joystick Bluetooth Commander Version 2.5 here

Hi Rosamunda

Here is the Arduino side code:

// Andro_Pan&Tilt      V2.6
// Arduino test sketch for Joystick BT commander
// Controls two servo motors

// V2.6 can receive both Byte (Joystick BT commander V2.5)& Integer data (V3.0)
// V2.0: removed SoftwareSerial

//  Arduino pin #0  to  TX Bluetooth module

#include <Servo.h>

#define    DEBUG          false

#define    ledPin         13              // LED pin
#define    pinServo_X     9
#define    pinServo_Y     10
#define    STX            0x02
#define    ETX            0x03
#define    MIN_Y          45             // vertical move limitation
#define    MAX_Y          180            // horizontal move limitation
#define    ZERO_Y         60

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                         // create servo object
Servo myservoY; 

void setup()  {
  Serial.begin(57600);
  myservoX.attach(pinServo_X);  
  myservoY.attach(pinServo_Y);  
  pinMode(ledPin, OUTPUT);
  if(DEBUG)  Serial.println("AndroZinZin V2.5");
}

void loop() {
   if(Serial.available())  {            // received from smartphone
    delay(5);
    cmd[0] =  Serial.read();  
//    if(DEBUG)  Serial.println(cmd[0]);   // ** DEBUG **
    if(cmd[0] == STX)  {  
      i=1;      
      while(Serial.available() && ((cmd[i]=Serial.read()) != ETX)) {
        if(i>5)  break;
//        if(DEBUG)    {Serial.print(i); Serial.print(": "); Serial.println(cmd[i]);}  // ** DEBUG **
        i++;
      }
    }
    if(i==2)    setLED(cmd[1]);
    if(i==3)    setPosition_Byte(cmd[1], cmd[2]);  
    if(i==5)    setPosition_Int(cmd[1]*128+cmd[2], cmd[3]*128+cmd[4]);  
  }
  delay(5);
}

void setLED(int LEDstatus)  {
  switch (LEDstatus) {
    case '1':
      Serial.println("Button_1: ON");
      // your code...      
      break;
    case '2':
      Serial.println("Button_1: OFF");
      // your code...      
      break;
    case '3':
      Serial.println("Button_2: ON");
      // your code...      
      break;
    case '4':
      Serial.println("Button_2: OFF");
      // your code...      
      break;
    case '5':
      Serial.println("Button_3: ON");
      // your code...      
      break;
    case '6':
      Serial.println("Button_3: OFF");
      // your code...      
      break;
    case '7':
      Serial.println("Button_4: ON");
      // your code...      
      break;
    case '8':
      Serial.println("Button_4: OFF");
      // your code...      
      break;
  }
}

void setPosition_Byte(byte posX, byte posY)    {    // Joystick BT commander V2.5
  posX = map(posX, 10, 110, 180, 0);
  posY = map(posY, 10, 110, 0, 180);
  posY+=ZERO_Y;
  posY = constrain(posY, MIN_Y, MAX_Y);
  if(DEBUG)  { Serial.print("(Byte) ");  Serial.print(posX);  Serial.print(", ");  Serial.println(posY); } // ** DEBUG **
  myservoX.write(posX);
  myservoY.write(posY);
}

void setPosition_Int(int posX, int posY)    {        // Joystick BT commander V3.0
  posX = map(posX, 10, 210, 180, 0);
  posY = map(posY, 10, 210, 0, 180);
  posY+=ZERO_Y;
  posY = constrain(posY, MIN_Y, MAX_Y);
  if(DEBUG)  { Serial.print("(Int) ");  Serial.print(posX);  Serial.print(", ");  Serial.println(posY); } // ** DEBUG **
  myservoX.write(posX);
  myservoY.write(posY);
}

Let me know the outcome in the Project main thread

Enjoy

This is the revised sketch, compatible with Joystick Bluetooth Commander V3.X
(modified communication protocol)

// Andro_Pan&Tilt      V3.1
// Arduino demo sketch for Joystick BT commander V3.X
// Controls two servo motors

// V3.0: Android BT Commander V3.X compatible, no button data management
// V2.5 can receive both Byte & Integer data
// V2.0: removed SoftwareSerial

// Android BT Commander settings:
// Options/Options for advanced users/Data Range        >>>  -180 to +180
// Options/Options for advanced users/Refresh interval  >>>  25ms

//  Arduino pin #0 to TX BlueTooth module
// BT TX to be disconnected from D0 during sketch upload

#include <Servo.h> 

boolean    DEBUG =         true;

#define    pinServo_X     9
#define    pinServo_Y     10
#define    STX            0x02
#define    ETX            0x03
#define    MIN_Y          45             // vertical move limitation
#define    MAX_Y          180
#define    ZERO_Y         60             // vertical offset

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                         // create servo object
Servo myservoY; 

void setup()  {
  Serial.begin(57600);
  myservoX.attach(pinServo_X);  
  myservoY.attach(pinServo_Y);  
  if(DEBUG)  Serial.println("Stepper demo for Android BT Commander V3.X");
}

void loop() {
  if(Serial.available())  {                   // data received from smartphone
    delay(5);
    cmd[0] =  Serial.read();  
    if(cmd[0] == STX)  {  
      i=1;      
      while(Serial.available())  {
        cmd[i] = Serial.read();
        if(cmd[i] == ETX)  {
          if(i==2 && cmd[1]>48)                break;    // Button data
          if(i==5 && cmd[1]<3 && cmd[3]<3)     break;    // Joystick data
        }
        if(i>5)   break;
        i++;
      }
      if     (i==2)   Serial.println("Button data not implemented");             // 3 Bytes
      else if(i==5)   setServoPosition(cmd);                                     // 5 Bytes
      else            Serial.println("Communication error");
    }
  }
  delay(5);
}

void setServoPosition(byte data[5])    {
  int joyX = (data[1]<<7) + data[2];
  int joyY = (data[3]<<7) + data[4];
  joyX = joyX - 200;                         // Offset to avoid
  joyY = joyY - 200;                         // transmitting negative numbers
  
  joyX = map(joyX, -180, 180, 180, 0);      // (-180/+180 JBC range)
  joyY = map(joyY, -180, 180, 0, 180);

  joyY+=ZERO_Y;
  joyY = constrain(joyY, MIN_Y, MAX_Y);
  myservoX.write(joyX);
  myservoY.write(joyY);
  if(DEBUG)  {Serial.print(joyX); Serial.print(", "); Serial.println(joyY);}
}

Please post technical questions in the main thread

Code has been updated to be compatible with Joystick BT Commander V5.x

More info here and here

if i add ur software to my robot it will be nice

if i add ur software to my robot it will be nice
Self Balancing Robot with LCD - YouTube

Hi caymanguy,
Nice bot , thanks for sharing :slight_smile:

I also use this App for controlling my own balancing robot, (now with MPU-6050 gyro/acc combo)


You may see the Bluetooth card, vertically plugged on the breadboard

Joystick BT Commander V5.2 now available

More info here

I would love to talk to you about your app for my project.

jmcward:
I would love to talk to you about your app for my project.

If you follow the second link in his signature there's a thread describing how to use the app.

IMO, Joystick BT Commander is a great app. I've used in a couple robots myself.

If you have questions about the app, you should probably ask them in the app thread so other people can find the information provided.

kas:
This basic pan & tilt robot is controlled via an Android smartphone, using a virtual joystick

Arduino robot controlled via Android smartphone - YouTube

The code on the Arduino side is rather straighforward
Tip: the SoftwareSerial and the servo libraries don't collaborate happily, I learnt it the hard way :~

More info re Joystick Bluetooth Commander application here

Enjoy

hey kas, i tried this but i can't seem to make it work. I am using HC-05 module, 2 sg5010 servos and arduino uno. I tried uploading your code and I used the app you posted on google play, but nothing seems to be working.

kas:
This basic pan & tilt robot is controlled via an Android smartphone, using a virtual joystick

Arduino robot controlled via Android smartphone - YouTube

The code on the Arduino side is rather straighforward
Tip: the SoftwareSerial and the servo libraries don't collaborate happily, I learnt it the hard way :~

More info re Joystick Bluetooth Commander application here

Enjoy

so we cant use both at the same time?

geeameal:
so we cant use both at the same time?

YMMV according to processor load, try it for yourself
As suggested by DuaneDegn, please keep the technical discussion on the main thread