Xbees and PIR project, Need Help.

Hello, I have been using two Arduino Unos and Xbees connected to the Arduinos via shield and have been trying to send data from a PIR sensor from one arduino’s xbee to another in order to use the data to turn a servo. The project’s goal is to trip a PIR sensor and have a servo turn due to it. These are the two codes I am using, the problem seems to be that when I use the codes, the servo never turns or shows any signal of receiving data from the PIR sensor.
Thanks

Code to Arduino with PIR sensor

int pirPin = 7;

void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
}

void loop(){
byte val = map(digitalRead(pirPin), 0, 1023, 0, 180);
Serial.write(val);
delay(2000);
Serial.write(0);
delay(500);
}

Code to Arduino with Servo

#include <Servo.h>
int servoPin = 9;
Servo Trevor;

void setup()
{
Serial.begin(9600);
Trevor.attach(servoPin);
}

void loop()
{
while(Serial.available() > 0)
{
byte data = Serial.read();
int position = data;
Trevor.write(position);
delay(5000);
}
}

Start small and simply hard code a simple message and send it.

Take the PIR out of the equation for the moment.

byte val = map(digitalRead(pirPin), 0, 1023, 0, 180);

Why are you mapping a digitalRead() return value from 0-1023 to 0-180? A digitalRead() returns true or false; 0 or 5V; 0 or 1. That is why it's called a digital read.

This is your problem. PIR sensors have ditial outputs (1 or 0 and NO in between, hence nothing to map really). In order to move a servo based on sensed position, you need a network of PIR sensors.

Oh ok, so I would have to take out that line of code and set it up to where a 1 would make the servo go to 180 while a 0 would make the servo go to 0? I am just trying to make the servo turn to 180 degrees when the PIR sensor is tripped so would it be a good idea to just write some "if" functions to go with it?

Mrbobokins: Oh ok, so I would have to take out that line of code and set it up to where a 1 would make the servo go to 180 while a 0 would make the servo go to 0? I am just trying to make the servo turn to 180 degrees when the PIR sensor is tripped so would it be a good idea to just write some "if" functions to go with it?

Yep!

How’s this?

int pirPin = 7;

void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
}

void loop(){
if (digitalRead(pirPin), HIGH);
{
Serial.write(180);
delay(2000);
}
if (digitalRead(pirPin), LOW);{
Serial.write(0);
delay(2000);
}

I can't seem to make that code work.