Need help with this code, i downloaded it like this and the trouble is that pir pins on arduino are high and should be low(i think) if u measure it with voltmeter, if u look at code it should not be - pin (10,11), so sensor randlomy lights up leds.
THE CODE:
Need help with this code, i downloaded it like this and the trouble is that pir pins on arduino are high and should be low(i think) if u measure it with voltmeter, if u look at code it should not be - pin (10,11), so sensor randlomy lights up leds.
THE CODE:
// "Bling" up your Staircase By Simon Jowett November 2014
// Thanks to the Neopxel Library by Adafruit
#include <Adafruit_NeoPixel.h>
#define PIN 6
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
// Set up Variables
unsigned long timeOut = 60000; // timestamp to remember when the PIR was triggered.
int downUp = 0; // variable to rememer the direction of travel up or down the stairs
int alarmPinTop = 10; // PIR at the top of the stairs
int alarmPinBottom = 11; // PIR at the bottom of the stairs
int alarmValueTop = LOW; // Variable to hold the PIR status
int alarmValueBottom = LOW; // Variable to hold the PIR status
int ledPin = 13; // LED on the arduino board flashes when PIR activated
int LDRSensor = A0; // Light dependant resistor
int LDRValue = 0; // Variable to hold the LDR value
int colourArray[350]; // An array to hold RGB values
int change = 1; // used in 'breathing' the LED's
int breathe = 0; // used in 'breathing' the LED's
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.begin (9600); // only requred for debugging
pinMode(ledPin, OUTPUT); // initilise the onboard pin 13 LED as an indicator
pinMode(alarmPinTop, INPUT); // for PIR at top of stairs initialise the input pin and use the internal restistor
pinMode(alarmPinBottom, INPUT); // for PIR at bottom of stairs initialise the input pin and use the internal restistor
delay (2000); // it takes the sensor 2 seconds to scan the area around it before it can
//detect infrared presence.
for (int i = 0 ; i < 350; i++) { // initilise the colourArray to zero
colourArray = 0;
- }*
}
void loop() { - LDRValue = analogRead(LDRSensor);*
- Serial.println(LDRValue);*
- if (LDRValue > 50) { // only switch on LED's at night when LDR senses low light conditions - you may have to change the number for your circumstances!*
- alarmValueTop = digitalRead(alarmPinTop); // Constantly poll the PIR at the top of the stairs*
- alarmValueBottom = digitalRead(alarmPinBottom); // Constantly poll the PIR at the bottom of the stairs*
- if (alarmValueTop == HIGH && downUp != 2) { // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.*
- timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.*
- downUp = 1;*
- topdown(); // lights up the strip from top down*
- }*
- if (alarmValueBottom == HIGH && downUp != 1) { // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.*
- timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.*
- downUp = 2;*
- bottomup(); // lights up the strip from bottom up*
- }*
- if (timeOut + 5000 < millis() && timeOut + 20000 < millis()) { //Koliko dugo da svijetle kad se upale*
- if (downUp == 1) {*
- colourWipeDown(strip.Color(0, 0, 0), 50); // Off*
- }*
- if (downUp == 2) {*
- colourWipeUp(strip.Color(0, 0, 0), 50); // Off*
- }*
- downUp = 0;*
- // for (int i=0 ;i < 350; i++) { // Depending on your preference you may want to include this loop to clear out the colourArray*
_ // colourArray*=0;_
_ // }_
_ }*_
* }*
}
void topdown() {
* Serial.println ("detected top"); // Helpful debug message*
* colourWipeDown(strip.Color(50, 50, 30), 25); // Warm White*
* for (int i = 0; i < 3; i++) { // Helpful debug indication flashes led on Arduino board twice*
* digitalWrite(ledPin, HIGH);*
* delay(200);*
* digitalWrite(ledPin, LOW);*
* delay(200);*
* }*
}
void bottomup() {
* Serial.println ("detected bottom"); // Helpful debug message*
* colourWipeUp(strip.Color(50, 50, 30), 25); // Warm White*
* for (int i = 0; i < 3; i++) { // Helpful debug indication flashes led on Arduino board twice*
* digitalWrite(ledPin, HIGH);*
* delay(200);*
* digitalWrite(ledPin, LOW);*
* delay(200);*
* }*
}
// Fill the dots one after the other with a color
void colourWipeDown(uint32_t c, uint8_t wait) {
* for (uint16_t i = 0; i < strip.numPixels(); i++) {
_ strip.setPixelColor(i, c);_
_ strip.show();_
_ delay(wait);_
_ }_
_}_
_// Fill the dots one after the other with a color*_
void colourWipeUp(uint32_t c, uint8_t wait) {
* for (uint16_t i = strip.numPixels(); i < -1; i--) {
_ strip.setPixelColor(i, c);_
_ strip.show();_
_ delay(wait);_
_ }_
_}*_