Neopixel LED with PIR Sensor

Hi,
I am trying to turn neopixel turn on, when PIR Sensor detect Motion and stay turned on for 1min after no motion is detected. I am newbee to Arduino and stuff. going throught codes avaiable I have come to the code shown below. the problem is PIR is detecting motion but LED is not turning on.

Pir is connected to PIN 7 and Neopixel to Pin 8


#include <Adafruit_NeoPixel.h>


#define PIN 6
#define NUMPIXELS 14

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50

const int MOTION_SENSOR_PIN = 7;   
int state = LOW;
int value = 0;

void setup() {
  Serial.begin(9600);                
  pinMode(MOTION_SENSOR_PIN, INPUT); 
        
}

void loop(){

if (value == HIGH) {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(0,222,0));
pixels.show();
delay(DELAYVAL);
}
}
else {
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
}
}
}


You are testing whether the value variable has a value of HIGH but it is only ever set to zero (LOW) and never changes

Is something meant to change the value variable ?

I found this code online. but when even when I am using this code, pir is not detecting anything

#include <Adafruit_NeoPixel.h>

// How many NeoPixels are attached to the Arduino?

#define PIN 6
#define NUMPIXELS 10

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50

const int sensor = 2;
int estado = LOW;
int valor = 0;

void setup() {
pinMode (sensor, INPUT);
Serial.begin (9600);
strip.begin();
randomSeed(analogRead(0));
}

void loop() {

valor = digitalRead (sensor);
int r = random(255);
int g = random(255);
int b = random(255);

if (valor == HIGH) {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(r,g,b));
pixels.show();
delay(DELAYVAL);
}
}
else {
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
}
}
}

Is there anything, such as a pulldown resistor, keeping pin 2 LOW when the PIR is not activated or is it floating at an unknow value, perhaps HIGH, perhaps LOW ?

What do you see if you print the value of the valor variable ?

Does the PIR have its own timer that keeps its output on for a period after it is triggered ?

Just looking at the 'PIR' via SerialMonitor (left the neopixel stuff in there anyway) --

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUMPIXELS 14

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50

const byte MOTION_SENSOR_PIN = 7;   
byte state = LOW;
byte result = 0;

void setup() 
{
  Serial.begin(19200);  
  delay(1000);
  Serial.println("ok ok");              
  //pinMode(MOTION_SENSOR_PIN, INPUT); 
        
}

void loop()
{  
  result = digitalRead(MOTION_SENSOR_PIN);
  if(result)
  {
    Serial.println("HI");
  }
  else
  {
    Serial.println("LO");
  }
  delay(50);

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.