PIR and Nano setup

So I put this all together with this code... and it worked great but now all of the sudden...
The lights go out....then come right back on.... constantly.....

What should I look for to fix this??

I literally have NO idea what happened... it was working great!!! I even used a different nano and wrote the code to that one... same result.... [even with NO pir sensors hooked up...still off and on behavior continues]

Thanks all!!

#include "FastLED.h"
#define LED_DATA_PIN 9
#define NUM_LEDS 250
CRGB leds[NUM_LEDS];

int onTime = 30*1000; // 30 seconds

int motion_sensor_right = 11;
int motion_sensor_front = 12;
int fadeTimeDiff = 40;

void setup() {
  FastLED.addLeds<WS2811, LED_DATA_PIN, BRG>(leds, NUM_LEDS);
  
  pinMode(motion_sensor_right, INPUT);
  pinMode(motion_sensor_front, INPUT);
}

void loop() {
  if (digitalRead(motion_sensor_right) == 1 || digitalRead(motion_sensor_front) == 1) {
    fadeIn();
    delay(onTime);
    fadeOut();
  }
}

void fadeIn() {
  for (int led = 0; led < NUM_LEDS; led++) {
    leds[led] = CRGB::White;
  }
  for (int b = 0; b < 20; b += 2) {   // b = brightness level
    FastLED.setBrightness(b);
    FastLED.show();
    delay(fadeTimeDiff);
  }
}

void fadeOut() {
  for (int led = 0; led < NUM_LEDS; led++) {
    leds[led] = CRGB::White;
  }
  for (int b = 20; b > 0; b -= 2) {  // b = brightness level
    FastLED.setBrightness(b);
    FastLED.show();
    delay(fadeTimeDiff);
  }
  for (int led = 0; led < NUM_LEDS; led++) {
    leds[led] = CRGB::Black;
  }
  FastLED.show();
}

Put the light where it does not hit the sensor and see if that solves your problem. The odds are high something moved from before when it was working.

1 Like

Without the pir sensors you will need pull down resistors on the input pins otherwise you may get spurious triggering.

2 Likes

Great idea... but that didn't solve anything :slight_smile:
I put the sensors in a drawer where there is NO light....same result...off then right back on.

Post an an annotated schematic showing how you have wired it. Include all connections, power, ground and power sources. Also note any wires more then 10" in length. Note: Frizzies are not schematics!

I hooked them back up and put them in a dark drawer where they couldn't possibly get triggered but still have the same behavior...off then back on .... like it's stuck in a loop....

Same system but with 3 pir sensors....I've modified it to use only 2.... like I said it worked fine then suddenly it started behaving off and on

Create a simple program without fastled which simply switches on the nano's built in led when a PIR is triggered. This will test the behaviour of the PIRs.
Variable onTime should be uint32_t, not int.

1 Like

Don't know if it's related to your fault, but you're starving the Nano (assuming classic Nano v3).
V-in needs 6 to 6.5volt minimum for the regulator on the Nano to make a stable 5volt supply.
If you have a stable external 5volt (LED supply), then connect that directly to the 5volt pin.
The LED strip should also connect to D9 through a (~330 ohm) resistor, and the cap on the LED strip is missing. Plenty of examples for adding those two parts can be found on Google. Failing to add those parts could damage the LED strip.
Leo..

3 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.