Controlling the boats motors from Android

So, I finally managed to get the basics done and put them together. First were the ESC for the motors. I had ordered two Turnigy 30A ESC for brushed motors from HobbyKing and it took “only” six weeks for them to be delivered. I guess it was my fault, ordering right before the chinese new year, when nobody seems to work for the next two weeks. At least neither my order was processed nor my questions were answered by the support. Anyway, they arrived eventually and I connected them to the motors, the battery pack and the Arduino.

Using PWM I was able to control the motors, and much better than with the original remote control. The original remote seemed to have a binary thrust, full speed and no speed. Steering only killed one of the two screws. With the Arduino and one ESC per motor I am able to finely control how fast the motor spins.

Next was the HC-05 Bluetooth module (also known as BTM400_6B) I had lying around for a while. Until now I was unable to configure it via AT commands, mainly due to missing cables and adapters. I sort of fixed that by using the Arduino as a serial bridge, I’ll explain that in more detail in a separate post. Bottom line: I configured the name, pin and baud rate on the Bluetooth module, put it into bridge mode, connected the serial pins with the serial pins on the arduino and it worked on the first try. There are several tutorials on the Internet on how to do that. I’m using Amarino to send data over a serial line via Bluetooth and it is really easy to use.

Finally, I adapted the remote control application I started earlier to send the desired speed and steering via Bluetooth to the Arduino, and guess what, it works! By tilting my mobile phone I can wirelessly control the speed of the motors on the boat.

Here is a basic Arduino code to react to signals from Amarino and set the motors accordingly. It is just a proof of concept and will be improved in the future.

#include <MeetAndroid.h>
 
MeetAndroid meetAndroid;
 
int motorL = 5;
int motorR = 6;
int minValue = 70;
int maxValue = 230;
 
int speed = 0;
float steering = 0;
 
void setup() {
Serial.begin(115200);
meetAndroid.registerFunction(setSpeed, 'A');  
meetAndroid.registerFunction(setSteering, 'B');  
}
 
void loop() {
meetAndroid.receive();
}
 
void setSpeed(byte flag, byte numOfValues) {
speed = meetAndroid.getInt();
setMotors();
}
 
void setSteering(byte flag, byte numOfValues) {
steering = meetAndroid.getFloat();
setMotors();
}
 
void setMotors() {
int lSpeed = minValue + speed;
int rSpeed = minValue + speed;
if (steering < 0) {
rSpeed -= (steering * 5);
}
if (steering > 0) {
lSpeed += (steering * 5);
}
if (lSpeed > maxValue) {
lSpeed = maxValue;
}
if (rSpeed > maxValue) {
rSpeed = maxValue;
}
analogWrite(motorL, lSpeed);
analogWrite(motorR, rSpeed);
}

Basically, the Android app sends integer values between 0 and 100 as desired speed. Tilting the phone as steering results in float values ranging from -10 when tilted completely to the left to +10 when tilted completely to the right, with 0 when it’s centered. These values are sent directly to the Arduino and added or subtracted from the speed value, then they are used to set the motors. Currently they are arbitrary chosen numbers, I need to see what needs improvement when I’m actually driving it on water.

Here a video of the setup in action:

Since it currently seems to be impossible to embed a YouTube video without it loading tracking scripts the video can only be viewed directly on YouTube.

By now I modified the Android-Application so I have a slider to control the thrust and only tilt the phone to steer it. It is much easier to handle that way. Of course the Bleutooth links is no final solution. The Bluetooth module I currently use only has a range of 10 meters. I thought about getting one with 100 meters range, but I guess that won’t do me any good as long as the other endpoint doesn’t support that range as well. Currently I’m planning to get two MRF24J40MA radio transceiver modules, they are incredibly cheap and seem to be easy to use as a serial bridge.

Last, but not least, a schematic of my current setup.

The batteries just represent the boats battery pack.

Published by

Gerald

Diplom-Informatiker (DH) in Darmstadt. Ich blogge über Entwicklung, Internet, mobile Geräte und Virtualisierung. Meine Beiträge gibt es auch bei Google+ und Facebook.

6 thoughts on “Controlling the boats motors from Android”

  1. hello,
    i’m very impressed. i want to control my two brushed motors with the brushed esc using arduino v.1( usb). can u plz tell me the program to dump to get it work.
    i need it for my project.

    thanking you.

    1. I’m not quite sure what you are missing, everything relevant is already in this post. Basically you connect the BEC contacts of the ESC to a PWM output of the Arduino, as shown in the schematic. Then you can control the ESC with analogWrite() as if it were a servo.

      Regards,
      Gerald

  2. i want to work on an rc boat as ma final year project using bluetooth to control both the motors and the rudder i will really need some help from you.i want to use atmega88 and wt12 bluetooth module,

    1. I’m flattered that you think I can be of help, but I really have only experimented a little with these things. I never used an ATMega processor directly (like, not being part of an Arduino) and until now I never even heard of this specific bluetooth module.
      Feel free to ask specific questions, maybe someone who knows more than me reads it and is able to answer it, but you will be far better off posting your stuff on a specialized discussion platform (the Arduino forum, the Adafruit support forum, electrinics stackexchange comes to mind).

  3. Hi,
    I am using HC-05 for my final year project.I am unable to configure the module using AT commands.I followed the steps mentioned in the datasheet to configure the module,also tried using TTL to RS232 convertor to configure it but dint get any response at the hyperterminal.Please help.

  4. can this system be used for making a cheap rc plane. if not can you tell me how can do it without using expensive rc plane transmitter and receiver .please help.

Leave a Reply

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