Wiring for PIR Controlled Digital RGB LED Strip

Attached is my wiring, would this work?

Thanks in advance

Attached is my wiring, would this work?

No. The Arduino can not supply near enough current to light 60 LEDs from one pin. It can turn a transistor on or off, which can, in turn, power the LEDs from another source of current.

I should of clarified, I have a wall wort plugged into the LED Strip (5V) on one end and a USB cable powering the Arduino. The strips light up and the functions created for the light show work just fine. It’s the sensor that I am having trouble with.

I am using this code to control what happens when the sensor is tripped, however, the “else” argument is the only one that runs.

#include <Adafruit_NeoPixel.h>

// 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)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(120, 6, NEO_GRB + NEO_KHZ800);

int motionPin = 2;   // motion detector input pin 
int senseMotion = 0;       // variable to hold current state of motion detector


void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

pinMode(motionPin, INPUT);
pinMode(6, OUTPUT);
    
    
}

void loop() {



senseMotion = digitalRead(motionPin);

      if (senseMotion == HIGH) {    // burgler found!
  colorChase(strip.Color(127,   0, 127), 10); // Violet
  strip.show(); // Initialize all pixels to 'off'
  delay(1000);

    } else {                      // no burgler, yet...
  scanner(127,0,127, 15); // Violet
  strip.show(); // Initialize all pixels to 'off'

    }

  
  //Monocramatic Effect Sequence
  //colorChase(strip.Color(127,   0, 127), 10); // Violet
  //colorWipe(strip.Color(127, 0, 127), 10); // Violet
  //myCrap(strip.Color(127,0,127),10); //Violet
  //scanner(127,0,127, 15); // Violet

  //myCrap2(strip.Color(0,0,0),10); // Off
  //wave(strip.Color(127,0,127), 2, 40); // Violet 
  //rainbow(20);
  //rainbowCycle(20);
   
  
  
}




// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}


void myCrap(uint32_t c, uint8_t wait) {
  for(uint16_t k=0; k<strip.numPixels(); k++) {
    
      strip.setPixelColor(2*k, c); 
      strip.show();
      delay(wait);    
    
  }
  
  
}



void myCrap2(uint32_t c, uint8_t wait) {
  for(uint16_t k=0; k<strip.numPixels(); k++) {
    
      strip.setPixelColor((2*k+1), c); 
      strip.show();
      delay(wait);    
    
  }
  
  
}



void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


// Chase one dot down the full strip.
   void colorChase(uint32_t c, uint8_t wait) {
   int i;

  // Start by turning all pixels off:
    for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

  // Then display one pixel at a time:
    for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c); // Set new pixel 'on'
    strip.show();              // Refresh LED states
    strip.setPixelColor(i, 0); // Erase pixel, but don't refresh!
    delay(wait);
  }

  strip.show(); // Refresh to turn off last pixel
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}


// "Larson scanner" = Cylon/KITT bouncing light effect
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
  int i, j, pos, dir;

  pos = 0;
  dir = 1;

  for(i=0; i<((strip.numPixels()-1) * 8); i++) {
    // Draw 5 pixels centered on pos.  setPixelColor() will clip
    // any pixels off the ends of the strip, no worries there.
    // we'll make the colors dimmer at the edges for a nice pulse
    // look
    strip.setPixelColor(pos - 2, strip.Color(r/4, g/4, b/4));
    strip.setPixelColor(pos - 1, strip.Color(r/2, g/2, b/2));
    strip.setPixelColor(pos, strip.Color(r, g, b));
    strip.setPixelColor(pos + 1, strip.Color(r/2, g/2, b/2));
    strip.setPixelColor(pos + 2, strip.Color(r/4, g/4, b/4));

    strip.show();
    delay(wait);
    // If we wanted to be sneaky we could erase just the tail end
    // pixel, but it's much easier just to erase the whole thing
    // and draw a new one next time.
    for(j=-2; j<= 2; j++) 
        strip.setPixelColor(pos+j, strip.Color(0,0,0));
    // Bounce off ends of strip
    pos += dir;
    if(pos < 0) {
      pos = 1;
      dir = -dir;
    } else if(pos >= strip.numPixels()) {
      pos = strip.numPixels() - 2;
      dir = -dir;
    }
  }
}

But, when I use the sample PIR Sensor code, the LED on the Arduino lights on when motion is detected. I assumed all I would have to do is change the pin number and the function to call. However, this does not work.

Below is the sample code for the light sensor:

/*  
    Motion sensor for Arduino, example code
    Tutorial:  http://www.hacktronics.com/Tutorials/arduino-motion-sensor.html
    Copyright: Mark McComb, hacktronics LLC
    License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
*/

const byte ledPin =  13;    // LED pin
const byte motionPin = 2;   // motion detector input pin 
byte senseMotion = 0;       // variable to hold current state of motion detector

void setup() {
  // set the digital pin directions
  pinMode(ledPin, OUTPUT);      
  pinMode(motionPin, INPUT);
}

void loop()
{
    // Now watch for burglers
    senseMotion = digitalRead(motionPin);
      if (senseMotion == HIGH) {    // burgler found!
      digitalWrite(ledPin, HIGH);
    } else {                      // no burgler, yet...
      digitalWrite(ledPin, LOW);
    }
}

I am using this code to control what happens when the sensor is tripped, however, the "else" argument is the only one that runs.

That hardly seems likely, since that code has no if or else statements in it.

My apologies, I re-posted the code above. I was testing multiple codes and copied the wrong one.

If the sensor works in one code, but not the other, I'd suspect some kind of interference from the LED strip library.

So are you saying that the code look "technically sound"?

it seems as if the "senseMotion == HIGH" argument is not being tripped.

 if (senseMotion == HIGH) {    // burgler found!
  colorChase(strip.Color(127,   0, 127), 10); // Violet
  strip.show(); // Initialize all pixels to 'off'
  delay(1000);

    }

If there is an interference from the LED library why would the else statement run perfectly?

else {                      // no burgler, yet...
  scanner(127,0,127, 15); // Violet
  strip.show(); // Initialize all pixels to 'off'

    }

Wouldn't this use the same library?

If the library uses the pin that the PIR sensor is connected to, for some purpose, that will interfere with your ability to read the (correct state of the) pin. If you don't ever read a HIGH, because the PIR sensor is un(der)powered or interfered with, then the if statement will never evaluate to true.

Try reversing the logic. Make the LED strip do something unless the PIR pin is HIGH. Does that work?

Try reversing the logic. Make the LED strip do something unless the PIR pin is HIGH

I set the LOW value to the PIR to do nothing, and included only the scanner() function when the sensor saw a HIGH.

This was the modification from the above:

void loop() {



senseMotion = digitalRead(motionPin);

      if (senseMotion == HIGH) {    // burgler found!
          scanner(127,0,127, 15); //colorChase(strip.Color(127,   0, 127), 10); // Violet
  strip.show(); // Initialize all pixels to 'off'
  delay(500);

    } else {                      // no burgler, yet...
          strip.Color(0,0,0);//scanner(127,0,127, 15); // Violet
  strip.show(); // Initialize all pixels to 'off'

    }

  
  //Monocramatic Effect Sequence
  //colorChase(strip.Color(127,   0, 127), 10); // Violet
  //colorWipe(strip.Color(127, 0, 127), 10); // Violet
  //myCrap(strip.Color(127,0,127),10); //Violet
  //scanner(127,0,127, 15); // Violet

  //myCrap2(strip.Color(0,0,0),10); // Off
  //wave(strip.Color(127,0,127), 2, 40); // Violet 
  //rainbow(20);
  //rainbowCycle(20);
   
  
  
}

I then noticed the lights would light up when I moved, and a few cycles later stop when I stopped moving.

Issue solved; it works, thank you!