Hello Stefan,
Thanks for your reply, apologies about the issues with my message, I’m quite new to the forum.
Here is the code:
// Motion sensor led's programmed by myself \\
// Version: BETA \\
// Creation date: 26/12/2020 \\
// Info: N/A \\
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 150
#define BRIGHTNESS 0 // MAXIMUM IS 255 -- default is 65
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
bool activated = "";
int ledPin = 13; // LED
int pirPin = 7; // PIR Out pin
int pirStat = 0; // PIR status
void setup() {
//delay(3000); // power-up safety delay -- Uneeded as of now
FastLED.addLeds < LED_TYPE, LED_PIN, COLOR_ORDER > (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(0);
FastLED.show();
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600);
delay(500); // ORIGINAL IS 1000
}
void loop() {
pirStat = digitalRead(pirPin);
if (pirStat == HIGH) { // if motion detected
activated = true;
Serial.println("Motion Detected");
Serial.println(activated);
delay(500);
} else {
if (pirStat == LOW) { // if no motion detected
activated = false;
Serial.println("No motion detected");
Serial.println(activated);
delay(500);
}
}
if (activated == true) {
FastLED.setBrightness(65);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(255, 192, 203); // 50, 255, 20
}
FastLED.show();
} else {
if (activated == false) {
FastLED.setBrightness(0);
FastLED.show();
}
}
}
So, my main goal is as follows:
The Motion Sensor (specific model: HC-SR501) is set to a distance of about 3 metres and a delay of 3 seconds. My goal is to turn on the LED strip, when the value is read as true, this value is set to true when the motion detector detects “HIGH”, the value is set to false when the motion sensor is set to “LOW”. These values are then handled separately, below in the code, it checks if the value is True, then it sets the lights on, and if it is false, it turns the lights on.
My current issue right now is the lights blink, they come on for about 1 second, then turn off for one second again. I don’t know if the motion sensor is reading something wrong but where I get it to print, it says “MOTION DETECTED” followed by the value true, it prints this 2 times then says “NO MOTION DETECTED” followed by the value false, this loop continues leading the lights to blink on and off.
The flashing is the lights going on and off, the goal is to just have it so that if I hover my hand over the sensor, the lights turn on until the sensor outputs as LOW (no motion detected) then the lights turn off.
Apologies for the misunderstanding, completely my fault.
Best regards, Unseen