P2P communication with Xbee series 2

Several things now that I looked at it again.

  1. The pot must be on an analog pin (A0-A5).
  2. A single byte is all we need to communicate an integer between 0 and 180.
  3. The motor code should not do Serial.print, as that sends data back to the potentiometer unit, and it's not expecting any input.

Try these. Move the pot to pin A0 first.

EDIT: int potPin = 5 is ok, assuming pot is connected to A5. I always forget that works. Confusing IMHO, I always use A0-A5 to be clear.

//potentiometer code

//Define Pins
int potPin = A5;    //pot must be on an analog pin

void setup()
{
  //Create Serial Object (9600 Baud)
  Serial.begin(9600);
}

void loop()
{
  delay(100);
  //since we want a number between 0 and 180, that fits
  //nicely into a byte variable (8-bit, unsigned).
  //so the message consists of a single character (byte).
  byte val = map(analogRead(potPin), 0, 1023, 0, 180);
  Serial.write(val);    //send it over the link in binary
}
//servo code

#include <Servo.h>

//Define Pins
int servoPin = 9;

//Create Servo Object
Servo jeremysServo;

void setup()
{
 //Start Serial
 Serial.begin(9600);
  
  //Attaches the Servo to our object
  jeremysServo.attach(servoPin);
  
  delay(500);
}

void loop()
{  

  while( Serial.available() == 0);
  byte pos = Serial.read();

  //Turn the servo
  jeremysServo.write(pos);
    
}