My university team is working on a Arduino based robot and we are interested in wirelessly controlling it with either Bluetooth or Radio control. Which is easiest to work with and the most efficient?
Hopefully someone more experienced than I can chirp in ;), but what needs to be transmitted? If its for controls, I feel RC has a bit faster response time and is less troublesome to use and set up. Also, and someone correct me if I'm wrong, RC typically has a much greater range.
On the flip side, if you need to transfer data back and forth for debugging... and monitoring... and such things haha, and dont need a far range, bluetooth might be a better option.
I've used both and i'm currently using RF. It really depends on what your sending, if you need to receive anything, range and complexity.
Bluetooth communicates serially so it uses the Arduino's serial port (Tx Rx), and in doing so by using the serial connection you can easily send and receive data.
Downside: Bluetooth is a little sluggish but has better quality also your limited to about 30ft. However if you can manage to find a LE(low energy) bluetooth module, you can go further. (Aprox 50 - 60ft, depending on surroundings).
RF use the virtual wire library, which not going to lie, can be a little confusing at first. It's range is mostly based on the transfer rate. Lower rate means further distances 150 - 170ft (open space), but more likely to lose some data. If you use a high rate, then your range is about 30 - 40ft, and your data is 99% all there. (Surroundings effect data loss too)
Downside: the virtual wire library limits you to about 27 sendable characters at one time. (Buffer size)
Also again it is a little more confusing when just starting out.
What are you sending, and how far do you need to go?
Added: forgot to mention, bluetooth works in pairs and must be "paired" to talk to one another. Usually you only need to pair them when connecting to a computer, most modules auto pair when in range of each other.
RF can have one transmitter to multiple receivers. However two transmitter to one receiver will cause problems.
We will use either Bluetooth or Radio Control to control the motors of a robot and instruct it to spin a certain way and at a certain speed.
WK95:
My university team is working on a Arduino based robot and we are interested in wirelessly controlling it with either Bluetooth or Radio control. Which is easiest to work with and the most efficient?
Ummm, bluetooth a form of radio control, as is wifi, nRF24L01+, and cell phone radios.
It all comes down to range (and the higher the range, typically the more power hungry the radio is), size, ease of programming, cost, whether you need a special license to use the spectrum or it is open for all.
Bluetooth (Bluetooth - Wikipedia) tends to be point to point devices, where you have one master and one slave in a pairing. One advantage of bluetooth is most modern smartphones have bluetooth capability, so you can control the system from a phone. Typically on Arduino, the most common bluetooth devices act as serial ports, where you plug in the device, and do Serial.print to send information and Serial.read to read it. There are ways to control it via AT commands. You can find bluetooth 2.1 systems that communicate with Android phones, either as separate devices, or a shield that fits on the Uno. I bought one HC-05 device for about $10 from ebay. In order to communicate with Apple phones, you need to use something with bluetooth 4.0, which is more expensive and harder to find than 2.1 devices. Since I do not use Apple devices of any sort, that is the extent of my knowledge about bluetooth 4.0.
If you don't need control from a phone, I believe a lot of people use nRF24L01+ radios: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
Wifi is another choice, in that it can be controlled via laptops and such if you have set up the access points. Typically you would need to create a web server that you can connect to from other computers. From what I've read, the wifi shields tend to take up most of the SRAM, and are rather power hungry.
Well then it comes down to range. For short range, I would go with bluetooth. If you want something a little further, then use RF. If you going for long distances and are in a wifi zone, use wifi.
The first robot I made used bluetooth, and I was able to control it from my laptop, android tablet and phone.
You can also do what most first timers do, and go with a wireless PS2 controller. You will get about 20 ft, and you have a bunch of buttons you can have do different things.
So far, we just need to control two motors, one for each wheel.
Can anyone share any links about using Bluetooth to control a Arduino bot?
I have a code you can use.
RF control:
/*
EzTEC truck code
Example string:
full forward: "20,10,0" => x,y,s
full reverse: "0,10,0"
360 left: "10,0,0"
360 right: "10,20,0"
forward + Left: "20,0,0"
forward + right: "20,20,0'
reverse + left: "0,0,0"
reverse + right: "0,20,0"
*/
#include<string.h>
#include <VirtualWire.h>
int DRV1,DRV2,STRR,STRL;
int x = 0; // Forward/reverse
int y = 0; // Left/right
int s = 0; // options: lights, buzzers, additional motors...
char c[30];
int ledpin = 13;
byte LMF = 3;// PWM Left motor forward pin
byte LMR = 5;// PWM Left motor Reverse pin
byte RMF = 11;// PWM Right motor forward pin
byte RMR = 6;// PWM Right motor reverse pin
void setup()
{
pinMode(ledpin, OUTPUT); // pin 13 (on-board LED) as OUTPUT
pinMode(LMF, OUTPUT);
pinMode(RMF, OUTPUT);
pinMode(LMR, OUTPUT);
pinMode(RMR, OUTPUT);
Serial.begin(9600); // start serial communication at 115200bps
vw_setup(2000); // Bits per sec
vw_set_rx_pin(8);
vw_rx_start();
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
//Serial.print("Got: ");
for (i = 0; i < buflen; i++){
digitalWrite(ledpin, HIGH);
c[i] = buf[i];
}
x=atoi(strtok(c,","));
y=atoi(strtok(NULL,","));
s=atoi(strtok(NULL," "));
/* Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
Serial.print(s);
Serial.println();*/
move(x, y, s);
}
}
void move(int x, int y, int s)
{
//Movement varibles
int DRV2 = map(x, 0, 10, 255, 0);
int DRV1 = map(x, 10, 20, 0, 255);
int STRL = map(y, 0, 10, 255, 0);
int STRR = map(y, 10, 20, 0, 255);
if(x > 10)//forwards
{
//Serial.println("Forward with turning");
analogWrite(LMF, constrain(abs(DRV1 - STRL),0,255)); analogWrite(RMF, constrain(abs(DRV1 - STRR),0,255));
digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
}
else if(x < 10)//backwards
{
//Serial.println("Reverse with turning");
digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
analogWrite(LMR, constrain(abs(DRV2 - STRL),0,255)); analogWrite(RMR, constrain(abs(DRV2 - STRR),0,255));
}
else if(x == 10 && y > 10)//Right
{
//Serial.println("360 left");
digitalWrite(LMR, LOW); analogWrite(RMR, STRR);
analogWrite(LMF, STRR); digitalWrite(RMF, LOW);
}
else if(x == 10 && y < 10)//Left
{
//Serial.println("360 right");
analogWrite(LMR, STRL); digitalWrite(RMR, LOW);
digitalWrite(LMF, LOW); analogWrite(RMF, STRL);
}
else //full stop
{
digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
}
if(s == 1)
{
//additonal option
}
else if(s == 2)
{
//option 2
}
else // s == 0
{
//option 3
}
// clear data
digitalWrite(ledpin, LOW);
x=0;
y=0;
s=0;
}
Bluetooth code: Bluetooth module
/*
simple dual motor test
*/
#include<string.h>
int DRV1,DRV2,STRR,STRL;
int x = 0;
int y = 0;
int s = 0;
String val,X,Y,state = "";
int currentCommand = 0;
int ledpin = 13;
byte LMF = 3;// PWM
byte LMR = 5;// PWM
byte RMF = 9;// PWM
byte RMR = 6;// PWM
void setup()
{
pinMode(ledpin, OUTPUT); // pin 13 (on-board LED) as OUTPUT
pinMode(LMF, OUTPUT);
pinMode(LMR, OUTPUT);
pinMode(RMF, OUTPUT);
pinMode(RMR, OUTPUT);
Serial.begin(9600); // start serial communication at 115200bps
}
void loop() {
if( Serial.available()) // if data is available to read
{
digitalWrite(ledpin, HIGH);
char c= Serial.read();
if (c == ','){
currentCommand++;
}
else {
val += c;
//Serial.println(val);
switch (currentCommand) {
case 0:
X += val;
val = "";
break;
case 1:
Y += val;
val = "";
break;
case 2:
//Serial.println("X: "+X);
//Serial.println("Y: "+Y);
state = val;
currentCommand = 0;
val = "";
//Serial.println("state: "+state);
//Serial.println();
x=X.toInt();
y=Y.toInt();
s=state.toInt();
X=""; Y=""; state="";
move( x, y, s);
break;
}
}
}
}
void move(int x, int y, int s)
{
x = constrain(x, 0, 20);
y = constrain(y, 0, 20);
//Movement varibles
int DRV2 = map(x, 0, 10, 255, 0);
int DRV1 = map(x, 10, 20, 0, 255);
int STRL = map(y, 0, 10, 255, 0);
int STRR = map(y, 10, 20, 0, 255);
if(x > 10)//forwards
{
//Serial.println("Forward with turning");
analogWrite(LMF, abs(DRV1 - STRL)); analogWrite(RMF, abs(DRV1 - STRR));
digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
}
else if(x < 10)//backwards
{
//Serial.println("Reverse with turning");
digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
analogWrite(LMR, abs(DRV2 - STRL)); analogWrite(RMR, abs(DRV2 - STRR));
}
else if(x == 10 && y > 10)//Right
{
//Serial.println("360 left");
digitalWrite(LMR, LOW); analogWrite(RMR, STRR);
analogWrite(LMF, STRR); digitalWrite(RMF, LOW);
}
else if(x == 10 && y < 10)//Left
{
//Serial.println("360 right");
analogWrite(LMR, STRL); digitalWrite(RMR, LOW);
digitalWrite(LMF, LOW); analogWrite(RMF, STRL);
}
else //full stop
{
digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
}
if(s == 1)
{
// option 1
}
else if(s == 2)
{
// option 2
}
else
{
// option 3
}
// clear data
digitalWrite(ledpin, LOW);
x=0; y=0; s=0;
val = ""; X= ""; Y= ""; state = "";
}
Thanks a lot for sharing that code. We'll try to use that.
I updated the Bluetooth code and took out a few unneeded constrain functions and fixed the "clear data" variables.
Would you be able to make a video of your robot when it's done, I would like to see it.
Maybe if its nice enough, we'll make a video.