Example design with XMotion V3 board and Bluetooth Control

Example design with XMotion V3 board and Bluetooth Control

In this example, we will direct the robot with an APP running on Android (Arduino Car application) using the XMotion V3 control card and Bluetooth Module (HC-06). The new version of the XMotion control board has a direct socket for Bluetooth. In this way, we can make a practical connection with the HC-06 Bluetooth model.

I don’t add anything else to keep the code as simple as possible.

What are we using?

  • Xmotion V3 Controller Board x1 (Link)
  • 12mm Motor Mount Pair x2
  • Mini Plastic Caster Wheel Pair x2
  • HC-06 Bluetooth Module x1
  • Maze Solver Robot Chassis x1
  • 6V 300 rpm 12mm DC Micro Gear Motors x2
  • JS2622 Aluminum Silicone Wheel Pair x2
  • Brass 35mm Standoffs
  • LiPo Battery 3S with JST Cable

All parts can be found at our JSumo Shop too.

Bluetooth controlled parts with robot body

There is very little soldering for our robot project, first we solder the motors to the Left Motor and Right Motor outputs. We solder the female header to the Bluetooth socket on the left and finally solder the JST Male cable set for the battery.

As the body, I used a maze robot body with a simple octagonal design.

Do not install the Bluetooth module in the opposite direction.

About the Bluetooth Robot Control App

We had chosen “Arduino Car” app here:

https://play.google.com/store/apps/details?id=com.electro_tex.bluetoothcar&hl=en_US

That is generic Bluetooth control app. At code only we receive some strings and compare it with the table shown at app. So you can use another bluetooth app but in that case your statement controls also needs to be same as different string that app sends.

The sent character strings are included in the application, and we compare these strings with the if query.

We are uploading the code below to XMotion with Micro USB Cable:

// Definitions of Motor Pins
#define leftPwmPin 10
#define leftDirPin 12
#define rightPwmPin 11
#define rightDirPin 13
// Variable to store commands received via Bluetooth
int Command = 0;
void setup() {
// Motor pinouts
pinMode(leftPwmPin, OUTPUT);
pinMode(leftDirPin, OUTPUT);
pinMode(rightPwmPin, OUTPUT);
pinMode(rightDirPin, OUTPUT);
Serial1.begin(9600); // Caution it is not serial.begin Serial1.begin which uses hardware UART
}
void loop() {
// Check if data is being received via Bluetooth.
if (Serial1.available() > 0) {
Command = Serial1.read();
// Control the motors according to the incoming commands.
if (Command == ‘F’) {
forward();
} else if (Command == ‘R’) {
turnright();
} else if (Command == ‘L’) {
turnleft();
} else if (Command == ‘G’) {
reverse();
} else if (Command == ‘S’) {
StopRobot();
}
}
}
// Forward motion function
void forward() {
digitalWrite(leftDirPin, HIGH);
digitalWrite(rightDirPin, HIGH);
analogWrite(leftPwmPin, 255);
analogWrite(rightPwmPin, 255);
}
// Turn right function
void turnright() {
digitalWrite(leftDirPin, HIGH);
digitalWrite(rightDirPin, LOW);
analogWrite(leftPwmPin, 128); // 128/255 Speed (Half %50 speed)
analogWrite(rightPwmPin, 128); // 128/255 Speed (Half %50 speed)
}
// Turn left function
void turnleft() {
digitalWrite(leftDirPin, LOW);
digitalWrite(rightDirPin, HIGH);
analogWrite(leftPwmPin, 128); // 128/255 Speed (Half %50 speed)
analogWrite(rightPwmPin, 128); // 128/255 Speed (Half %50 speed)
}
//Reverse motion function
void reverse() {
digitalWrite(leftDirPin, LOW);
digitalWrite(rightDirPin, LOW);
analogWrite(leftPwmPin, 255);
analogWrite(rightPwmPin, 255);
}
// stopping function
void StopRobot() {
analogWrite(leftPwmPin, 0);
analogWrite(rightPwmPin, 0);
}

Now, I will sum this code by using XMotion library, it will make shorter code for motor movement functions.

For this I will add #include <xmotion.h> line to beginning of code.

#include <xmotion.h>
// Variable to store commands received via Bluetooth
int Command = 0;
void setup() {
Serial1.begin(9600); // Caution it is not serial.begin Serial1.begin which uses hardware UART
}
void loop() {
// Check if data is being received via Bluetooth.
if (Serial1.available() > 0) {
Command = Serial1.read();
// Control the motors according to the incoming commands.
if (Command == ‘F’) {
xmotion.Forward(100,5); // %100 Speed for short duration 5ms.
} else if (Command == ‘R’) {
xmotion.Right0(50,5); // %50 speed for short time.
} else if (Command == ‘L’) {
xmotion.Left0(50,5); // %50 speed Left Turn
} else if (Command == ‘G’) {
xmotion.Backward(100,5); // Backward full %100 speed
} else if (Command == ‘S’) {
xmotion.StopMotors(5); // Stop Motors for 5 millisecond in loop so it will be infinite.
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>