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();
}```
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.
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.
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.
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:
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.
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.