best way to send pot over xbee for servo control?

im looking to simply send my pot. data over xbee to control my servo on the other side without interfering with my other controls heres my tx side

#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 12); // RX, TX
int potpin = 0;  // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
const int SW1 = 8; //forward
const int SW2 = 9; //backward
const int SW3 = 3; //left
const int SW4 = 2; //right
void setup()
{
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);
  pinMode(SW4, INPUT_PULLUP);
  //pinMode(Light, INPUT);
  Serial.begin(9600);
mySerial.begin(9600);
}
void loop(void)
{
  byte data = 0;
  if (digitalRead(SW1) == HIGH)
  {
    data += 1;
  }
  if (digitalRead(SW2) == HIGH)
  {
    data += 2;
  }
  if (digitalRead(SW3) == HIGH)
  {
    data += 4;
  }
  if (digitalRead(SW4) == HIGH)
  {
    data += 8;
  }
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 180);  
  if(data > 0)
  {
    delay(50);
  mySerial.write(data);
 Serial.print(data);
  }

}
#include <MotorDriver.h>
#include <Servo.h>
Servo myservo;
byte data = 0;
void setup()
{
  motordriver.init();
  motordriver.setSpeed(250, MOTORB);
  motordriver.setSpeed(250, MOTORA); // steering motor
myservo.attach(4);
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available() > 0)
  {
    data = Serial.read();
  }
  if (data == 1)
  {
    motordriver.goForward();
  }
  else if (data == 2)
  {
    motordriver.goBackward();
  }
  else if (data == 4)
  {
    motordriver.goLeft();
  }
  else if (data == 8)
  {
    motordriver.goRight();
  }
  else if (data == 5)
  {
    motordriver.goForward();
    motordriver.goLeft();
  }
  else if (data == 9)
  {
    motordriver.goForward();
    motordriver.goRight();
  }
  else if (data == 6)
  {
    motordriver.goBackward();
    motordriver.goLeft();
  }
  else if (data == 10)
  {
    motordriver.goBackward();
    motordriver.goRight();
  }
  else
  {
    motordriver.stop();
  }
  delay(50);
  if (data > 0)
  {
    Serial.print("data=");
    Serial.println(data, DEC);
  }
  data -= data;

}

What is your specific question or issue? What does not work with your code?

im just unsure of how to send it and then decifer it on the other end like would i just myserial.write(map);?

I made the below code to do something similar with joysticks and servos. Easiest to develop receiving code first, then develop sending code that works with the receiving code.

tx code

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor

#include <Servo.h> 
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

int newval1, oldval1;  //pot input values
int newval2, oldval2;
int newval3, oldval3;
int newval4, oldval4;
int newval5, oldval5;

void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(2);  
  myservo2.attach(3);
  myservo3.attach(4);
  myservo4.attach(5);
  myservo5.attach(6);
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    Serial.print(newval1); //print the new value for testing 
    Serial.print("a,");
    oldval1=newval1; //set the current old value
  }

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){  
    myservo2.write(newval2);
    Serial.print(newval2);
    Serial.print("b,");
    oldval2=newval2;
  }

  newval3 = analogRead(potpin3);           
  newval3 = map(newval3, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval3 > (oldval3+2)){  
    myservo1.write(newval3);
    Serial.print(newval3);
    Serial.print("c,");
    oldval3=newval3;
  }

  newval4 = analogRead(potpin4);           
  newval4 = map(newval4, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval4 > (oldval4+2)){  
    myservo1.write(newval4);
    Serial.print(newval4);
    Serial.print("d,");
    oldval4=newval4;
  }

  newval5 = analogRead(potpin5);           
  newval5 = map(newval5, 0, 1023, 0, 179); 
  if (newval1 < (oldval5-2) || newval5 > (oldval5+2)){  
    myservo1.write(newval5);
    Serial.print(newval5);
    Serial.print("e,");
    oldval5=newval5;
  } 
  delay(50);  //to slow loop for testing, adjust as needed
}

rx code

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

so servo write on the tx side????

merkzilla: so servo write on the tx side????

Yes, so the servos can be directly connected to the tx arduino for testing and verification that the tx setup is working as desired. Note that below the servo write is also the serial write functions used for transmission to the rx arduino via the serial port. The serial monitor can be used to test and verify the functioning of the rx arduino

oh ok thank you i was trying to send the values without messing up my movement of the car 1,2,4,8 with the servo values

so everything checks out on my tx side (i think lol) but on my rx side things arnt going to well…the servo moves sometimes but so slightly and eratic i dont think its from data received. i think my movement data is getting mixed in the bunch somewhere
tx

#include <SoftwareSerial.h>
#include <Servo.h> 
Servo myservo;  //declare servos
SoftwareSerial mySerial(11, 12); // RX, TX
int potpin = A0;  // analog pin used to connect the potentiometer
int newval, oldval; // variable to read the value from the analog pin
const int SW1 = 8; //forward
const int SW2 = 9; //backward
const int SW3 = 3; //left
const int SW4 = 2; //right
void setup()
{
  myservo.attach(A1); 
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);
  pinMode(SW4, INPUT_PULLUP);
  //pinMode(Light, INPUT);
  Serial.begin(9600);
mySerial.begin(9600);
}
void loop(void)
{
  int data = 0;
  if (digitalRead(SW1) == HIGH)
  {
    data += 1;
  }
  if (digitalRead(SW2) == HIGH)
  {
    data += 2;
  }
  if (digitalRead(SW3) == HIGH)
  {
    data += 4;
  }
  if (digitalRead(SW4) == HIGH)
  {
    data += 8;
  }
  newval = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  newval = map(newval, 0, 1023, 0, 180); 
   if (newval < (oldval-2) || newval > (oldval+2))
   { //dead band 
    myservo.write(newval); //position the servo
    mySerial.write(newval); //print the new value for testing 
    mySerial.write("a,");
    Serial.print(newval); //print the new value for testing 
    Serial.print("a,");
    oldval=newval; //set the current old value 
   }
  if(data > 0)
  {
    delay(50);
  mySerial.write(data);
 Serial.print(data);
  }

}

rx

#include <MotorDriver.h>
#include <Servo.h>
String readString;
Servo myservo;
int data = 0;
void setup()
{
  motordriver.init();
  motordriver.setSpeed(250, MOTORB);
  motordriver.setSpeed(250, MOTORA); // steering motor
myservo.attach(40);
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available())
  {
   char data = Serial.read();
    //gets one byte from serial buffer
    //camera coontrol
    if (data == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out
        int n = readString.toInt();  //convert readString into a number
        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservo.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservo.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += data; //makes the string readString
    }
  }
  //movement control
  if (data == 1)
  {
    motordriver.goForward();
  }
  else if (data == 2)
  {
    motordriver.goBackward();
  }
  else if (data == 4)
  {
    motordriver.goLeft();
  }
  else if (data == 8)
  {
    motordriver.goRight();
  }
  else if (data == 5)
  {
    motordriver.goForward();
    motordriver.goLeft();
  }
  else if (data == 9)
  {
    motordriver.goForward();
    motordriver.goRight();
  }
  else if (data == 6)
  {
    motordriver.goBackward();
    motordriver.goLeft();
  }
  else if (data == 10)
  {
    motordriver.goBackward();
    motordriver.goRight();
  }
  else
  {
    motordriver.stop();
  }
  delay(50);
    Serial.print("data=");
    Serial.println(data, DEC);
  

}

but on my rx side things arnt going to well....the servo moves sometimes but so slightly and eratic i dont think its from data received.

Probably 90% of servo problems are due to trying to power the servo from the arduino instead of an external power supply, or if the external power supply is used, the grounds are not properly connected. Why do you have a 50ms delay in the receiving code?

i just used the servo code and it still isnt working on the rx side

tx

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor
#include <SoftwareSerial.h>
#include <Servo.h> 
Servo myservo1;  //declare servos
SoftwareSerial mySerial(11, 12); // RX, TX

int potpin1 = A0;  //analog input pin A0

int newval1, oldval1;  //pot input values


void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(A1);  
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    mySerial.write(newval1); //print the new value for testing 
    mySerial.write("a,");
    oldval1=newval1; //set the current old value
  } 
  delay(50);  //to slow loop for testing, adjust as needed
}
//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa ;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(A0);  //the pin for the servoa control
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Very basic servo test code to see if you can get your servo to position.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  } 
}

keep this for tx side with that

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor
#include <SoftwareSerial.h>
#include <Servo.h> 
Servo myservo1;  //declare servos
SoftwareSerial mySerial(11, 12); // RX, TX

int potpin1 = A0;  //analog input pin A0

int newval1, oldval1;  //pot input values


void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(A1);  
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    mySerial.write(newval1); //print the new value for testing 
    mySerial.write("a,");
    oldval1=newval1; //set the current old value
  } 
  delay(50);  //to slow loop for testing, adjust as needed
}

The below may have timer conflicts, so you may need to sort that out if you are going to use SoftwareSerial.

#include <SoftwareSerial.h>
#include <Servo.h>

my main issue is getting it to work on my rx side it works on my tx side fine but for some reason it isnt carrying over

movement data is 1-10 so cant i simply say if there val availible from the potentiameter to add 11 (so not to confused with movement data) to the val and send it then on the rx side say if the data received is > than 10 cammove = data - 10 then myservo.write camMove???

so i have this code working on both sides only issue now is there is a long delay between when i give a cammand and when the rx side fallows through with the cammand
tx

#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial mySerial(11, 12); // RX, TX
int potpin = 0;  // analog pin used to connect the potentiometer
int newval, oldval;   // variable to read the value from the analog pin
const int SW1 = 8; //forward
const int SW2 = 9; //backward
const int SW3 = 3; //left
const int SW4 = 2; //right
void setup()
{
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);
  pinMode(SW4, INPUT_PULLUP);
  //pinMode(Light, INPUT);
  Serial.begin(9600);
mySerial.begin(9600);
}
void loop(void)
{
   newval = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  newval = map(newval, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  if (newval != (oldval))
  { 
    newval + 11;
    mySerial.write(newval); //print the new value for testing 
    Serial.print(newval);
    oldval=newval; //set the current old value
  } 
  
  int data = 0;
  
  if (digitalRead(SW1) == HIGH)
  {
    data += 1;
  }
  if (digitalRead(SW2) == HIGH)
  {
    data += 2;
  }
  if (digitalRead(SW3) == HIGH)
  {
    data += 4;
  }
  if (digitalRead(SW4) == HIGH)
  {
    data += 8;
  }
  if(data > 0)
  {
    delay(50);
  mySerial.write(data);
 Serial.print(data);
  }

}
#include <MotorDriver.h>
#include <Servo.h>
String readString;
Servo myservo;
int data = 0;
void setup()
{
  motordriver.init();
  motordriver.setSpeed(250, MOTORB);
  motordriver.setSpeed(250, MOTORA); // steering motor
myservo.attach(A0);
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available())
  {
   data = Serial.read();
  }
  //movement control
  if (data == 1)
  {
    motordriver.goForward();
  }
  else if (data == 2)
  {
    motordriver.goBackward();
  }
  else if (data == 4)
  {
    motordriver.goLeft();
  }
  else if (data == 8)
  {
    motordriver.goRight();
  }
  else if (data == 5)
  {
    motordriver.goForward();
    motordriver.goLeft();
  }
  else if (data == 9)
  {
    motordriver.goForward();
    motordriver.goRight();
  }
  else if (data == 6)
  {
    motordriver.goBackward();
    motordriver.goLeft();
  }
  else if (data == 10)
  {
    motordriver.goBackward();
    motordriver.goRight();
  }
  else
  {
    motordriver.stop();
  }
  // cam movement
  int cammove = 0;
  if (data > 10)
  {
    cammove = data - 11;
  myservo.write(cammove);
  } 
  delay(50);
    Serial.print(cammove);
    Serial.print("data=");
    Serial.println(data, DEC);
  
  data -= data;
  
}

You might try using the code with the two arduinos connected with tx/rx/gnd wires instead of xbee and see if there is still a delay.

I fixed the delay seems to work good now although when I turn the servo all the way to one side it seems to still mix with my movement commands because the car jumps like it's trying to move.... Should I have Val map on the rx side as well

    newval + 11;

?