#include <FastLED.h>
#define NUM_LEDS 10
#define LED_PIN 26
#define PIR_PIN 13
CRGB leds[NUM_LEDS];
int motion_detected = false;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
setLeds(CRGB::Black);
}
void loop() {
int read_state = digitalRead(PIR_PIN);
if (read_state == HIGH) {
Serial.println("Motion detected");
if (motion_detected == false) {
setLeds(CRGB::Red);
motion_detected = true;
}
} else {
Serial.println("No motion detected");
if (motion_detected == true){
setLeds(CRGB::Black);
motion_detected = false;
}
}
delay(100);
}
void setLeds(CRGB color) {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = color;
}
FastLED.show();
}