Need input please

I've been trying to make this 'project' for a couple days now. The ONLY results I get are is that the lights go out and come right back on. It's in a loop. I have looked at this and I cannot even figure out why....... can anyone see anything I am not seeing? I've tried 9 different PIR sensors and 3 different Nano's, rewired it twice......same results.

This a project I found on Youtube....

Thanks everyone!

#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_left = 10;
int motion_sensor_right = 11;
int motion_sensor_front = 12;
int fadeTimeDiff = 50;

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

void loop() {
  if (digitalRead(motion_sensor_left) == 1 || 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( 150, 60, 15);
  }
  for (int b = 0; b < 255; b += 2) {
    FastLED.setBrightness(b);
    FastLED.show();
    delay(fadeTimeDiff);
  }
}

void fadeOut() {
  for (int led = 0; led < NUM_LEDS; led++) {
    leds[led] = CRGB( 150, 60, 15);
  }
  for (int b = 255; b > 0; b -= 2) {
    FastLED.setBrightness(b);
    FastLED.show();
    delay(fadeTimeDiff);
  }
  for (int led = 0; led < NUM_LEDS; led++) {
    leds[led] = CRGB::Black;
  }
  FastLED.show();
}```

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.

Give links to components, need to see what the output of the sensors is.


For troubleshooting, add some print statements to see what the variables are doing.

analyze this code

  for (int b = 0; b < 255; b += 2) {
    FastLED.setBrightness(b);
    FastLED.show();
    delay(fadeTimeDiff);
  }

At some point, b with be 254, which is less than 255 so it gets incremented by 2 to become 256. You then set the brightness to this value which takes a value from 0-255. 256 is the same as 0 so your leds are OFF.

1 Like

@blh64 Nope. For b=256 the cycle is not execute.

Hi,
You could do this;

 for (int b = 0; b < 255; b =b+1) 
 {
    FastLED.setBrightness(b);
    FastLED.show();
    delay(fadeTimeDiff/2);
  }

It will take just as long.

Tom... :smiley: :+1: :coffee: :australia:

But you don’t want us to look at it? If not why no link?

We only can ever know what you tell us, so it becomes impossible to help because we have to guess what your actual trying to achieve.

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".

Thanks..Tom.. :smiley: :+1: :coffee: :australia:

1 Like

Without more information, my first thought is immediately that I see you use "INPUT" mode for the digital inputs, not "INPUT_PULLUP". If wired incorrectly, this could mean that your input is "floating", i.e. randomly reading 1 and 0 for every read, which means it would trigger all the time, even when the sensor itself is not triggering.

This is a very common problem with beginner projects. To solve this (or to exclude it as a possible problem), we need more information on the project and, most importantly, your wiring.

1 Like

This is not how for loop works

Sorry I should have posted this link.....

Under Bed lights

Instructables

Yes I see that. But being new to this type of thing I forget to give ALL the info at times. Sorry.

I appreciate everyone's input. Just trying to solve this mystery as more of a learning experience.
I SHOULD have listed the project links.....so here it is. This contains all the parts and code. I used exactly the same parts, and followed the wiring diagram to the letter. Even took it all apart and rewired it.

There was another guy with the same problem I was having and it really never got answered. Other then that I haven't see anywhere where anyone actually made this work.

Under Bed lighting

If the lights are constantly fading up, staying on for 30 seconds, fading off and then immediately fading up again, it sound like one or more of your motions sensor are always giving a HIGH signal. Do you have a multimeter so you can check the inputs on the three motion sensor pins?

If not, add Serial.begin(115200); to setup() and use Serial.print() to show information on Serial Monitor. Print things like the the state of the input pins:

void loop() {
  Serial.print("Left: ");
  Serial.print(digitalRead(motion_sensor_left);
  Serial.print(", Right: ");
  Serial.print(digitalRead(motion_sensor_right);
  Serial.print(", Front: ");
  Serial.println(digitalRead(motion_sensor_front);

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

Not arguing as I have NO idea what I'm doing but having 9 new PIR sensors being bad..... 6 are a new batch I just got and 3 are leftovers from projects I never used.

I know I wired this correctly, that part I'm VERY good at being a contractor and able to follow schematics and such. I just can't help but think that there's something in the code that isn't quite right but being really new to all this I can't seem to find it.

The thing that makes me think this is as like I said I've used other nanos and 9 different PIR's.... just makes no sense to me.

You are just missing the closing ')' on those Serial.print() calls

void loop() {
  Serial.print("Left: ");
  Serial.print(digitalRead(motion_sensor_left));
  Serial.print(", Right: ");
  Serial.print(digitalRead(motion_sensor_right));
  Serial.print(", Front: ");
  Serial.println(digitalRead(motion_sensor_front));
1 Like

LOL Thank you. That's why I edited my reply I caught that.

If you use that sensor from the link, it would mean that when there's no movement, there is no active signal. Depending on the way the sensor works exactly, this could leave your pin in a floating state where it reads 0 or 1 randomly. (Google arduino floating pin)

Try connecting a 1k resistor from your input pins to ground. This makes sure the pin is always kept at 0, unless the sensor sends an active signal, making it 1. This is called a pulldown resistor and whether this is needed depends on the exact way the sensor is built.

The data sheet for the HC-SR581 sez it is an active signal, 0 volts or 3.3 volts.

If anything, you would want to pull the output up. 0 LOW 0.0 volts is fine.

But 3.3 volts shoukd read HIGH on an Arduino input, and I doubt you’ve ruined the sensor using INPUT_PULLUP, but it shouldn’t be needed. Use INPUT.

There’s enough going on that I recommend a testing setup without any code, no Arduino, see

for just how many ways to go wrong with this unit.

Are you sure you have the exact sensor? HC-SR501 specified in you link?

a7

1 Like

Ok so I have discovered Thanks to johnwasser and blh64 is this:
If I hook a PIR sensor to [testing with only 1 sensor not all three]

johnwasser you are right....... no matter what I do it's firing 1's all the time. Even if I have NO PIR sensor hooked up......

2 different Nano's......ughhh. I have the Nano plugged into the IDE and one pir sensor and that is what I'm getting so I'm confused.

I am wondering this is a 5v setup.....PIR sensors are 3.3V........hummmmmmmm

Yes I ordered them from Amazon and searched for HC-SR501.

Thank you for the link I will go read more!!! There's just something so strange about all this.