Listing 2 shows how to interface the
XBee receiver to the serial motor controller
used on the Telebot. Note the use of the
SoftwareSerial and Servo object libraries —
both of which come with the Arduino IDE
software. Points of interest in the sketch
include:
• The setup() routine starts three serial
objects (one for the XBee, two for
the motor controller).
case (‘u’):
forward();
This runs both motors forward when
receiving the u (up) signal.
Last Data to Receive
The Telebot provides numerous avenues
for customization and enhancement. Add
a video camera as I’ve done for the
prototype, and you can beam back pictures
as you drive your robot through your house
or office. In conjunction with the camera, I
added a Parallax Backpack module to act as
a video text overlay. A third Arduino atop
the Telebot collects data from a series of
sensors mounted nearby — temperature,
humidity, light, and so on. The data is
captured and added as text over the video
that’s transmitted back to me.
Even if you don’t use picture feedback,
your Telebot will give you hours of
experimentation. Remember that just
because you control the robot with a
joystick, that doesn’t mean the Telebot has
to be completely reliant on you. Add some
sensors to allow it to navigate on its own.
Steer it into a corner, then see how well it
can find its way out! SV
www.servomagazine.com/index.php?/
magazine/article/november2012_McComb
Discuss this article in the SERVO Magazine
forums at http://forum.servomagazine.com
Listing 2 — Telebot_Receive.
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
#define xbeeRx A0 // DOUT to A0
#define xbeeTx A1 // DIN to A1
SoftwareSerial Xbee (xbeeRx, xbeeTx); //After motor serial
void setup() {
servoLeft.attach(10); // Left servo to pin 10
servoRight.attach(9); // Right servo to pin 9
Serial.begin(9600);
Xbee.begin(9600);
delay(200);
pinMode(13, OUTPUT); // Show ready status
digitalWrite(13, HIGH);
}
void loop() {
readXbee();
delay(50);
}
void readXbee() {
if(Xbee.available()) {
char val = Xbee.read();
Serial.println(val);
controlMotor(val);
}
}
void controlMotor(char val) {
switch (val) {
case ('c'):
stopRobot();
break;
case ('u'):
forward();
break;
case ('d'):
reverse();
break;
case ('r'):
turnRight();
break;
case ('l'):
turnLeft();
break;
}
}
// Motion routines for forward, reverse, turns, and stop
void forward() {
servoLeft.write(0);
servoRight.write(180);
}
void reverse() {
servoLeft.write(180);
servoRight.write(0);
}
void turnRight() {
servoLeft.write(180);
servoRight.write(180);
}
void turnLeft() {
servoLeft.write(0);
servoRight.write(0);
}
void stopRobot() {
servoLeft.write(90);
servoRight.write(90);
}
SERVO 11.2012 55