Author Topic: Xbee servo issue  (Read 1179 times)

0 Members and 1 Guest are viewing this topic.

Offline EithmanTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Xbee servo issue
« on: December 08, 2012, 02:34:01 PM »
I am trying to make a remote control car with a couple of XBees, full rotation Servos and Arduinos.  Heres the code.

#include <Servo.h>
Servo Left; // servo on the left hand side
int one = 1;

void setup() {

void loop() {
  if (Serial.available() > 0) {
    int data = - '0';
      if ( data == 1)

The servo is set up to pin 8. When the if statement reads that a 1 has been sent over serial and assigned to the int 'data', the servo should start spinning. But it spins regardless. Even if no data is being sent. If I keep the same code and only change it so that when the if statement is true, it turns on an led, it works fine. But for some reason, when it is supposed to turn the servo, it always reads true and turns the servo. Any ideas?

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,345
  • Helpful? 82
Re: Xbee servo issue
« Reply #1 on: December 08, 2012, 09:02:37 PM »
Try adding Left.write(0) to the setup function.
Also, try different values, both for setup and for "getting 1," as the zero calibration may be slightly off.
Finally, try printing something to the serial port after the function, to see if and how often you actually get there.


Get Your Ad Here