PIR to turn on WS2812FX

OK, I have managed to get my PIR to light the onboard LED for 30 seconds when motion is detected then turn off. I thought it would be easy just to change the pin number and add the code of the WS2812FX, which I can get to work on its own. However, currently the LED strip just stays lit, even when the sensor reads “Motion Stopped”, which turns off the LED. I am using an ESP32.
Do I need to use a trigger command for the WS2812FX?
I want to get this to work to light the stairwell for my dog at night since his eyesight is going.

  Rui Santos
  Complete project details at https://randomnerdtutorials.com  
  Added WS2812FX library to try an light strip instead of
  onboard LED **/

#include <WS2812FX.h>

#define LED_COUNT 150
#define LED_PIN 26
#define timeSeconds 30
//#define LED 2

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// Set GPIOs for LED and PIR Motion Sensor
const int led = 26;
const int motionSensor = 27;

// Timer: Auxiliary variables
unsigned long now = millis();
unsigned long lastTrigger = 0;
boolean startTimer = false;

// Checks if motion was detected, sets LED HIGH and starts a timer
void IRAM_ATTR detectsMovement() {
  Serial.println("MOTION DETECTED!!!");
  digitalWrite(LED_PIN, HIGH);
  startTimer = true;
  lastTrigger = millis();

void setup() {
  // Serial port for debugging purposes

 // PIR Motion Sensor mode INPUT_PULLUP
  pinMode(motionSensor, INPUT_PULLUP);
  // Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
  attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);

  // Set LED to LOW
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

  // divide the string of LEDs into two independent segments
//uint32_t colors[] = {WHITE, WHITE};
//ws2812fx.setSegment(0, 0,           (LED_COUNT/2)-1, FX_MODE_STATIC, colors, 1000, false);
//ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1,     FX_MODE_STATIC, (const uint32_t[]) {WHITE, WHITE}, 1000, false);

void loop() {
  // Current time
  now = millis();
  // Turn off the LED after the number of seconds defined in the timeSeconds variable
  if(startTimer && (now - lastTrigger > (timeSeconds*1000))) {
    Serial.println("Motion stopped...");
    digitalWrite(LED_PIN, LOW);
    startTimer = false;


Looks like you’re going to have to issue a command to the LED strip. Try setBrightness perhaps.

Oh, maybe, so down in the loop section, under where it says “Motion Stopped” add a SetBrightness 0 or something along those lines?
I’ll try that when I get home. Thank you!

Oh, maybe, so down in the loop section, under where it says “Motion Stopped” add a SetBrightness 0 or something along those lines?

That's it.

Unfortunately, that didn’t work and actually still left random LEDs on, which may be due to the fact I am just using a breadboard right now.
I will try tomorrow but I don’t think it is possible at this point.
Thanks for your recommendation.

You will definitely have to do something there.

Probably it's two-fold.

  1. only call ws2812fx.service() when you actually have motion detected. You now call this all the time, regardless of the motion sensor's output.
  2. switch off the LEDs when motion ends (once upon state change is enough).