Things used in this project

Hardware components:
A000066 iso both
Arduino UNO & Genuino UNO
×1
11812 02
SparkFun XBee Explorer USB
×1
12847 00
SparkFun XBee Shield
×1
Xbee Pro S1
×1
Corona DS238 MG Digital Servos
×1
Software apps and online services:
Ide web
Arduino IDE
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)
3drag
3D Printer (generic)

Code

Arduino Servo Control from XBee serial receiveArduino
Flashed to Arduino Uno
#include <Servo.h>
Servo yawservo;  // create servo object to control a servo
Servo pitchservo;  // create servo object to control a servo

String inputString = "";         // a string to hold incoming data
boolean yawComplete = false;  // whether the string is complete
boolean pitchComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600); // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  yawservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pitchservo.attach(10);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  serialEvent(); //call the function // print the string when a newline arrives:
  if (pitchComplete) {
    pitchservo.write(inputString.toInt());                  // sets the servo position according to the scaled value 
    delay(1); 
    inputString = "";
    pitchComplete = false;
  }

    if (yawComplete) {
    yawservo.write(inputString.toInt());                  // sets the servo position according to the scaled value 
    delay(1); 
    inputString = "";
    yawComplete = false;
  }
}

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == 'x')
    {
      pitchComplete = true;
      break;
    }
        if (inChar == 'y')
    {
      yawComplete = true;
      break;
    }
    inputString += inChar;
  }
}

Credits

Cfc565606d4b9adde09db6885e3738e8
twhi2525
1 project • 10 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog