2 pir sensor

Hi all first time on here only just getting into arduino so don't no anything . I am trying to run a led lights strip up my stairs running off 2 small pir sensor with problems with the signal to my relay when running the 2 pir so I am now thinking of trying to go the arduino way so if anyone can help me please .I have a arduino uno. 2 pir sensor module hc sr501 and a relay which has 5v in and 240v out and up to 10a .plus 2a led strip lights .can anyone help with wiring diagram and software program please p's one sensor is on the bottom step and one on top step need lights to come on if you are going up or down stairs thank you

How about forming your question with breaks and spacing so we can read it without straining our brains to make sense of this paragraph.

It appears that you may be after help to use two PIRs to control two lots of LEDs on stairs.

The PIR is treated as a switch to LOW when active. Your code needs to look for a change of state (not just looking for a LOW). The LEDs are simply outputs. The LED strings need to be driven by a relay or transistor as the Arduino cannot control the current directly from the output pin.


Do the lights work with only one PIR sensor?

If your system will work without a microcontroller when using one PIR, there is likely a way to get it to work with two PIR sensors and still not use a microcontroller.

Yes the led strip lights works with one pir sensor with out the arduino.

I can get the arduino to run one pir using digital button in the library but I have tried to add another button but not having much luck .

So if someone would be nice and send me the program to run 2 digital buttons for the pir with 1 out put would be much appreciated thank you .

Supply your code so we can see where you have gone wrong.


//set up the pushbutton pins to an input: Pin mode (button 1pin, input); Pin mode (button 2 pin, input );

//set up the led pin to be an output Pin mode (ledpin, output);

Void loop ()

Internet button1state, button2state // variables to hold the pushbutton states

Button1states = digitalread(button1pin); Button2states = digitalread(button2pin);

If ((button1states == low) ll (button2states == low //

((Button1states == low // (button2 states == low))) //

Digitalwrite (led pin, high); // turn the led on

} Else } Digitalwrite (led pin, low); // turn the led off

As you can see I don't know much lol If I used the one in the arduino library ( digital button ) it works on one of the pir and if I set the pin number I can get opposite one to work but not both at the same time the program you can see I found on the Internet but it keeps coming up with errors thank you

wicko: Yes the led strip lights works with one pir sensor with out the arduino.

I still think there's a good chance you could get the lights to work with 2 PIR sensors without using an Arduino.

Can you provide a diagram of how the single PIR and lights are wired?

How far away will the second PIR be from the first.

We'll try to help with the code if your setup needs an Arduino but it seems like it would be a good idea to try it without the Arduino first. You might just need to add a diode and/or a pull-up resistor to your circuit.

I am running 2 pir sensor arduino type 3 pin

and a 5v in relay to 240v at upto 10a

using alarm cable 1a for the sensors and to the relay in .

the leds are in a 10m length and are 240v 2a with a transformer to 12v

running one sensor works very good but when I run 2 pir sensor I have problems

when I test the signal wire I an not getting the 3.5v I need for the relay

But with one pir sensor I am getting 3.5v

But putting 2 signal wire together not getting the 3.5v hope you can understand that I am trying to say thank you

Ps sorry forgot to say pir sensor 1 is about 8m from pir sensor 2

Are the PIR sensors active high or active low?

In other words, when do you get 3.5V from the sensor, when it's triggered or while it's not tiggered?

As I mentioned before, It might be possible to add a diode or a pull-up resistor to the circuit to get it to work with two sensors. I almost positive, it could work with a couple signal relays.

This should also be easy with an Arduino.

I modified the "Button" example to check two inputs instead of one. I don't program the Arduino much but hopefully this will work.

/* PirSensorsWithRelay */
// By Duane Degn
// October 31, 2015

// Based on Arduino example code "Button".

// constants won't change. They're used here to
// set pin numbers and active state:
const int TOP_SENSOR = 2;     // the number of the PIR pin
const int BOTTOM_SENSOR = 3;  // the number of the PIR pin
const int ACTIVE = HIGH;     
const int RELAY_PIN =  13;      // the number of the LED (or relay) pin

// variables will change:
int topSensorState = 0;         // variable for reading the top PIR sensor
int bottomSensorState = 0;      // variable for reading the bottom PIR sensor

void setup() 
  // initialize the relay pin as an output:
  // initialize the PIR sensor pins as inputs:

void loop()
  // read the state of the PIR sensors:
  topSensorState = digitalRead(TOP_SENSOR);
  bottomSensorState = digitalRead(BOTTOM_SENSOR);

  // check if either of the PIR sensors are active.

  if ((topSensorState == ACTIVE) or (bottomSensorState == ACTIVE))
    // turn relay on:
    digitalWrite(RELAY_PIN, HIGH);
    // turn relay off:
    digitalWrite(RELAY_PIN, LOW);

I assumed the PIR sensors are active high, but if they're active low, change this line:

const int ACTIVE = HIGH;


const int ACTIVE = LOW;

The code compiles but I haven't tested it.

I will give it a go thank you very much

The 3.5v is when it is triggered

I will give your program a go and let you know

Thanks for all your help

Hi I have just tried that program you sent me and it works very very good thank you

I am going to hard wire it in tomorrow

I will keep you updated with how I get on with it

Thanks for the program and your help and time much appreciated thank you duanedegn

wicko: Hi I have just tried that program you sent me and it works very very good thank you

Good to hear. Sometimes my programs only work very good. :)

The program is basically the "Button" example with an extra input.

Hi DuanedegnI

i have just hard wired it all in now working very very good

Had some problems

But all fine now

Thank you very much again for your time and help much appreciated

Would of taken me a long time to do it on my own

Sorry about the ( L ) at the end of your name my

phone put it on and didn't see it until I sent it


It's good to hear the code is working.

I use the Propeller microcontroller much more than the Arduino and I realize I let some Spin slip into my C.

The line:

  if ((topSensorState == ACTIVE) or (bottomSensorState == ACTIVE))

Should probably be:

  if ((topSensorState == ACTIVE) || (bottomSensorState == ACTIVE))

I'm surprised the code compiled and I'm even more surprised the code works.

Do any of the other forum members know why "or" will work in place of "||"?

My guess is the compile accepts both versions.

I couldn't find "or" in the listed in the reference page.