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() {
Left.attach(
;
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
int data = Serial.read() - '0';
if ( data == 1)
{
Left.write(180);
}
}
}
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?