Hi,
first time using arduino...and I have no programming experience....gd start lol
I want a strip running along my stairs, controlled by arduino and pirs.
when bottom pir only is activated leds light going up the stairs....
when top pir only is activated leds light going down the stairs....
when both pirs activated leds stay white for a time delay
if both pirs low, strip is off.....
I had used this code as reference...but modified:
I think I have a problem with too many "if" functions in my code....I cant get stript to light when only one pir is high....
any advice...
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(40, 6, NEO_RGB + NEO_KHZ800);
int motionPin = 2; // PIR Input pin 2, SENSOR AT BOTTOM OF STAIRS
int motionPin2 = 3; // PIR 2 Input pin 3, SENSOR AT TOP OF STAIRS
int senseMotion = 0; // variable to hold current state of motion detector at btm of stairs
int senseMotion2 = 0; // 2nd variable to hold current state of motion detector at top of stairs
void setup()
{
pinMode(motionPin, INPUT); //PIRs declared as inputs
pinMode(motionPin2, INPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
rainbow (3); //rainbow effect
rainbowCycle (3); //rainbow cycle effect
colorWipe (strip.Color (0, 0, 0), 0);
strip.show(); //turn pixels off
}
void loop()
{
senseMotion = digitalRead (motionPin); //set variables equal to what our sensors are reading (on or off)
senseMotion2 = digitalRead (motionPin2);
if ((senseMotion == HIGH)&(senseMotion2 == LOW)) { // If downstairs motion sensor is triggered only
colorWipe (strip.Color (0, 255, 0), 50); // red color sweep going up stairs (Towards the arrow on the strip)
delay (5000); // Delay time to walk upstairs
//colorChase (strip.Color(255, 0, 0), 50); // Color chase animations, red, green, blue indicating that the light are about to shut down
colorWipe (strip.Color (0, 0, 0), 0); //wipe all pixels
strip.show(); //all pixels off
}
else if ((senseMotion == LOW)&(senseMotion2 == HIGH)) { // If upstairs motion sensor is triggered only
colorWipe2 (strip.Color(0, 255, 0), 50); // green color sweep going down stairs
//strip.show();
delay(5000);
colorWipe2 (strip.Color(0, 0, 0), 0);
strip.show();
}
else if ((senseMotion == HIGH)&(senseMotion2 == HIGH)) { // If Upstairs and downstairs motion sensor is triggered...
colorWipe (strip.Color (255, 255, 255), 50); // white color sweep going up stairs
//strip.show(); //
delay (5000); //
//colorChase (strip.Color(255, 25, 25), 5); // Color chase animations, red, green, blue indicating that the light are about to shut down
colorWipe (strip.Color (0, 0, 0), 0); // This is needed for turn everything off, clear all pixels. More efficient with this here
strip.show();
}
else { // no motion = no lights or animate til off
digitalWrite (motionPin, LOW); //turning motion pins low, doesnt seem to make a difference either.
digitalWrite (motionPin2, LOW);
//colorWipe (strip.Color(0, 0, 0), 30);
strip.show();
}
} }