For a university project, I want to activate a WS2812 LED strip with 164 pixels via a PIR motion sensor (HC-SR501). I have tried it with examples, but I can't make it work. Right now, I'm trying to just make the LED strip show one pixel for 5 seconds when the motion sensor gets activated. However, now it just switches from illuminating the whole strip to illuminating only the one pixel every 5 seconds and the motion sensor doesn't seem to do anything. Where is my mistake?
#include <Adafruit_NeoPixel.h>
#define PIN 10
#define NUMPIXELS 164
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int led=10; // Pin number for LED
int pir=5; // Pin number for PIR sensor
int state=LOW; // Initial state is LOW
void setup()
{
pinMode(led, OUTPUT); //LED strip is the output
pinMode(pir, INPUT); // PIR motion snensor is the input
}
void loop()
{
state=digitalRead(pir);
if (state == HIGH)
{
digitalWrite(led, HIGH);
pixels.begin();
pixels.setPixelColor(4, pixels.Color(0,150,0)); // for trying out, just show one pixel first
pixels.show();
delay(5000);
}
else
{
digitalWrite(led, LOW);
}
}
#include <Adafruit_NeoPixel.h>
#define PIN 10
#define NUMPIXELS 164
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int pir=5; // Pin number for PIR sensor
int state=LOW; // Initial state is LOW
void setup()
{
pinMode(pir, INPUT); // PIR motion sensor is the input
pixels.begin();
}
void loop()
{
state=digitalRead(pir);
if (state == HIGH)
{
pixels.setPixelColor(4, pixels.Color(0,150,0)); // for trying out, just show one pixel first
pixels.show();
delay(5000);
}
else
{
pixels.setPixelColor(4, pixels.Color(0,0,0)); // for trying out, just show one pixel first
pixels.show();
}
}