PIR Sensor, Arduino and Xbee

Hey,
Guys
I am just working on a project where I use a PIR sensor to detect motion which alerts me using leds and stuff. I am doing this wirelessly and i have 2 xbee's. But i cannot figure out the code. If someone can send me the code that would be awsome.
BTW i am new to electronics and only 14.
This would help me a bunch thanks :slight_smile: :slight_smile: .

I also have the shields the programming thing which u connect to the computer and use the xctu software. all i need is the code

LAWRENCENEEDSHELP:
all i need is the code

It's not very likely someone will send you the code.

You're much more likely to have success if you write the code yourself and then ask for help when you have trouble.

Break your project into small parts. Learn to do each part by itself and then combine the parts.

Can you light a LED? Can you use the PIR sensor? Have you configured the XBees?

If/when you have questions about specific hardware, make sure and provide a link to the hardware you're using. If/when you have questions about the code, post the code you're asking about using code tags. Read the "How to use this forum" to learn about code tags.

BTW i am new to electronics and only 14.

So much to learn! Welcome to the forum. We aim to help others, not do the job for them. As has been said, take small steps and join them together. The "Learn" tab at the top of the page has lots of information to help.

Start with a simple switch turning on a LED and then turning it off again. Then use the PIR instead of the switch.

Remember to use a resistor (270 ohms or similar) in series with the LED so as not to burn out the output.

Always save any working code and "Save As" to start the next phase of your program. This way you can always return to a working version when you totally confuse yourself with additions.

Weedpharma

int calibrationTime = 30;

// Codes sent to the Receiver:
char TurnOn = 'a';
char TurnOff = 'b';
char warmUp = 'z';

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 5; // the digital pin connected to the PIR sensor's output
int ledPin = 4; // the built-in LED

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

//give the sensor some time to calibrate
for(int i = 0; i < calibrationTime; i++){
Serial.println( warmUp ); // Send the receiver info that we're holding in a Warm-Up loop
delay(1000);
}
delay(50);
}

////////////////////////////
//LOOP
void loop(){

if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state

if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
delay(50);
}
Serial.println( TurnOn );

takeLowTime = true;
}

if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
Serial.println( TurnOff );

if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase

}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
delay(50);
}
}
}

Was there a question?

Please learn to use code tags.

DuaneDegn:
If/when you have questions about the code, post the code you're asking about using code tags. Read the "How to use this forum" to learn about code tags.

As Duane suggested, please edit and place your code within code tags.

And I recognise that code. I've been helping someone else who used the exact same code example, intended for the Parallax PIR detector. If your's isn't the Parallax PIR detector, you probably don't need all that "lockLow" stuff:-

  • The Parallax PIR Sensor is an easy to use digital infrared motion sensor module.
  • (http://www.parallax.com/detail.asp?product_id=555-28027)
  • The sensor's output pin goes to HIGH if motion is present.
  • However, even if motion is present it goes to LOW from time to time,
  • which might give the impression no motion is present.
  • This program deals with this issue by ignoring LOW-phases shorter than a given time,
  • assuming continuous motion is present during these phases.