Issues with coding (1459 LEDs + 2 PIR)

Hi,
Shortly about the project. I'm making a stairs lightining with LEDs and 2 PIR motion sensors (10 led strips x 5m), so total number is 1459 LEDs. When coming from downstairs PIR detects motion and lights should go up, stay for some time on and fade out, same when going from upstairs. Using Arduino Mega 2560.

Issues:

  1. Lights goes up or down the stairs too slow even by the delay it should go up fast. What's wrong here? Arduino Mega 2560 can't handle it?
  2. Afer PIR motion time delay stops the lights are still on, doesn't fadeout. (when I was trying it at home with 150 led strip, everything was fine).
  3. PIR motion sensor allows me to delay for up too 200s, but I need longer time, as to climb up the stairs takes 5-10min. How should I code that?
  4. When coming lets say from downstairs PIR sensor detects motion and turns on LEDs, but then reaching the top of the stairs second PIR detects motion again so triggers the code like somebody is walking down the stairs. How should I switch off sensMotion when sensMotion2 is triggered?

Code:

#include <FastLED.h>
#define NUM_LEDS 1459
#define DATA_PIN 2
CRGBArray<NUM_LEDS> leds;

int motionPin = 9;                                                                                 
int motionPin2 = 7;                                                                                
int senseMotion = 0;                                                                               
int senseMotion2 = 0;                                                                              
int speed = 30;




void setup() {
  delay(2000);
  FastLED.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS);
  pinMode(motionPin, INPUT);                                                                      
  pinMode(motionPin2, INPUT);
  pinMode(DATA_PIN, OUTPUT);
  FastLED.show(); // Initialize all pixels to 'off'
  FastLED.show();
  Serial.begin(9600); 
  FastLED.setBrightness(100);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(500); } }

void loop() {
  
    senseMotion = digitalRead (motionPin);                                                        
    senseMotion2 = digitalRead (motionPin2);
    
      if (senseMotion == HIGH || senseMotion2 == HIGH) {                                          
          
          if (senseMotion2 == HIGH) 
           for (int i = (NUM_LEDS)-1; i >= 0; i--) {                                                               
            leds [i] = CRGB::Red;
            FastLED.show();                                                                          
            leds[i] = CRGB::SandyBrown;
            delay(20);
            Serial.println("DOwnstairs on")

                                }                        
        
      if (senseMotion == HIGH) {                                                                
         senseMotion2 ==LOW;
         for (int i = 0; i < NUM_LEDS; i++)
         {
          leds[i] = CRGB::Green;
          FastLED.show();
          leds[i] = CRGB::SandyBrown;
          delay(40);
          Serial.println ("Upstairs on");
         }
         
                                 }  
                                                      }
      else {                                                                                    
          digitalWrite (motionPin, LOW);                                                        
          digitalWrite (motionPin2, LOW);
          fadeall();
          leds[1] = CRGB::Black;
          FastLED.show();
          delay(200);
          Serial.println("OFF");
           }


  
}

Your code doesn't compile.

58+ seconds of delay there.
Is that what you wanted?

Have you timed how long a single show takes?

Oops

This delay is how fast the light goes up. On 150 LED strip the light went fast enough, but on 1459 LEDs, it's too slow. I'm walking faster those stairs then the light is climbing down or up. So from begining to end the light should climb in around 1min, but now it takes about 5min or more, and lightning should stay for 10min.

It takes roughly ten times as long to update 1459 LEDs.
That's simple arithmetic.

What I mean, that 150 led strip, or 5m of led strip, when it was connected at home, alone, without other strips connected to light up took 5s, now the same 5m led strip when connected with other led strips (45m), takes 10-15s to light up. So it is arduino not strong enough or am I doing something wrong here?

If it take x milliseconds to perform a "show()" on 150 LEDs, then it it going to to take nearly 10x milliseconds to perform "show()" on 1459 LEDs.
Have you accounted for that?

Oops

I notice you've edited the original post

Don't do that

I understand that, but if I'm changing delay(40) to some other number, the speed is still the same like it was, no change and it looks like arduino is not capable to move the light faster then 1459 led is connected.

Have you timed how long a single show takes?

(I think I've asked this already?)

Around 6min

No way.

You're saying a single call to show() for 1459 LEDs takes 360 seconds?

There's something wrong with how you measured it.

That is the crux of the matter. The question was how long does one of these take:

FastLED.show();

It's quite a long time because even though you changed one or two LEDs, it sends the data for all of them.

I had thought that the multiple serial prints were the problem at such a glacial baud rate but the show takes enough time that it doesn't matter.

That what I'm saying. I'm walking down the stairs faster the show goes. So when i'm at the bottom of the stairs the show is behind me. Spent half day yesterday to check how fast they are going and no reaction when changing delay. But if I'm running this show on a single led strip with 150 leds, everything is fine, can make it run fast and slow with delay

I think you misunderstand.
When I say "show()", I mean the function that updates every single LED just once.

I refuse to believe it takes 6 minutes for one show() to execute.

I understand what are you saying and it takes 6min, don't have a video, but it takes too long, when it should light up in around 1min and by PIR sensor time delay it could take more than 200s + show got to the end. Yesterday I have started it and it still goes, as the PIR sensors are disconnected.

You're in a minority.

You still haven't posted code that compiles.

1 Like
#include <FastLED.h>
#define NUM_LEDS 1459
#define DATA_PIN 2
CRGBArray<NUM_LEDS> leds;

int motionPin = 9;                                                                                 
int motionPin2 = 7;                                                                                
int senseMotion = 0;                                                                               
int senseMotion2 = 0;                                                                              
int speed = 30;




void setup() {
  delay(2000);
  FastLED.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS);
  pinMode(motionPin, INPUT);                                                                      
  pinMode(motionPin2, INPUT);
  pinMode(DATA_PIN, OUTPUT);
  FastLED.show(); // Initialize all pixels to 'off'
  FastLED.show();
  Serial.begin(9600); 
  FastLED.setBrightness(100);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(500); } }

void loop() {
  
    senseMotion = digitalRead (motionPin);                                                        
    senseMotion2 = digitalRead (motionPin2);
    
      if (senseMotion == HIGH || senseMotion2 == HIGH) {                                          
          
          if (senseMotion2 == HIGH) 
           for (int i = (NUM_LEDS)-1; i >= 0; i--) {                                                               
            leds [i] = CRGB::Red;
            FastLED.show();                                                                          
            leds[i] = CRGB::SandyBrown;
            delay(20);
            Serial.println("Downstairs on");

                                
      }                        
        
      if (senseMotion == HIGH) {                                                                
         for (int i = 0; i < NUM_LEDS; i++)
         {
          leds[i] = CRGB::Green;
          FastLED.show();
          leds[i] = CRGB::SandyBrown;
          delay(40);
          Serial.println ("Upstairs on");
         }
         
                                 }  
                                                      }
      else {                                                                                    
          digitalWrite (motionPin, LOW);                                                        
          digitalWrite (motionPin2, LOW);
          fadeall();
          leds[1] = CRGB::Black;
          FastLED.show();
          delay(200);
          Serial.println("OFF");
           }


  
}

It compiles for me. There was minor mistakes it previous code, which I done before posting it here. Here is the original code which runs now.

Do you ever turn the pullup resistors on?
I'm not clear what you hope to achieve here.