How to control 2 PIR using arduino uno ??

Please help me, i already have the source code for control 1 PIR, but i stil don't know how to edit that source for controlling 2 PIR by using arduino uno ??

Well we can't see your source code to comment on unless you post it....

/* * This is the code PIR sensor tester */

int ledPin = 13; // choose the pin for the LED int inputPin = 2; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status

void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600); }

void loop(){ val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED ON if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); // We only want to print on the output change, not state pirState = HIGH; } } else { digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH){ // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } } }

Right, ok… seems straightforward enough.

(Btw, next time highlight your pasted code and hit the # button on the line above the smilies to format your code nicely.)

What you need to do is firstly double-up this code:

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

…to look something like this, with 2 PIRs say A and B, note the new names and pin numbers for the new B part

int ledPinA = 13;                // choose the pin for the LED A
int inputPinA = 2;               // choose the input pin (for PIR sensor A)
int pirStateA = LOW;             // we start, assuming no motion detected by A
int valA = 0;                    // variable for reading the pin status for A

 int ledPinB = 12;                // choose the pin for the LED B
int inputPinB = 3;               // choose the input pin (for PIR sensor B)
int pirStateB = LOW;             // we start, assuming no motion detected by B
int valB = 0;                    // variable for reading the pin status for B

Then duplicate the code which is inside void loop(), making the necessary changes to add the A’s and B’s and you’ll have two PIR / LED pairs. (Change the messages sent too, to like “motion detected by pirA” so you can see that each is working.

OOPS... you'll also need to duplicate these lines in setup to give them the right A and B names:

  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

nice (:
Thanks bro, it works…

Btw, will it be same if i try to control 5 PIR ??

Btw, will it be same if i try to control 5 PIR ??

Yeah, it should be ok up to the point where you run out of pins... (Although just on a point of wordy correctness, you're not controlling the PIRs. The PIRs are sensors, you read or sense them. The LED, or in real life say a relay powering an alarm or a machine gun, is an actuator: that's what you control.)

Also don't forget that only pin 13 has the built in LED- for other pins you'll need to add an external LED and a series resistor, unless of course it's enough to have all the PIRs activating the one LED on 13 in which case you needn't dupe the LED stuff with the A, B, Cs etc,