Hello!
I'm creating stair lights with the goal of having the lights triggered whether someone is going up or down the stairs, so I need 2 PIR to be able to trigger the LED strip lights. I've been able to get things working with one PIR, but the 2nd won't trigger the lights.
#include <FastLED.h>
#define NUM_LEDS 191
#define DATA_PIN 2
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define BRIGHTNESS 60
#define VOLTS 5
#define MAX_AMPS 500
#define MOTION_SENSOR_1_PIN 12 // Arduino pin connected to the OUTPUT pin of motion sensor
#define MOTION_SENSOR_2_PIN 11
int motion_state = LOW; // current state of motion sensor's pin
int motion_state_2 = LOW;
int prev_motion_state = LOW; // previous state of motion sensor's pin
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<CHIPSET,DATA_PIN,COLOR_ORDER>(leds,NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
pinMode(MOTION_SENSOR_1_PIN, INPUT); // set arduino pin to input mode
pinMode(MOTION_SENSOR_2_PIN, INPUT);
}
void loop() {
prev_motion_state = motion_state; // store old state
motion_state = digitalRead(MOTION_SENSOR_1_PIN); // read new state
motion_state_2 = digitalRead(MOTION_SENSOR_2_PIN);
if (prev_motion_state == LOW && motion_state == HIGH) { // pin state change: LOW -> HIGH
Serial.println("Motion detected!");
// turn on the led strip
for (int i=0; i<NUM_LEDS; i++) {
leds[i] = CRGB::White;
FastLED.show();
delay(10);
}
} else if (prev_motion_state == HIGH && motion_state == LOW) { // pin state change: HIGH -> LOW
Serial.println("Motion stopped!");
FastLED.clear();
FastLED.show();
}
if (prev_motion_state == LOW && motion_state_2 == HIGH) { // pin state change: LOW -> HIGH
Serial.println("Motion detected!");
// turn on the led strip
for (int i=NUM_LEDS; i<0; i--) {
leds[i] = CRGB::White;
FastLED.show();
delay(10);
}
} else if (prev_motion_state == HIGH && motion_state == LOW) { // pin state change: HIGH -> LOW
Serial.println("Motion stopped!");
FastLED.clear();
FastLED.show();
}
}
Any help would be greatly appreciated!

