Mechanics and Construction > Mechanics and Construction

Xbee servo issue


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?

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.


[0] Message Index

Go to full version