Neopixels and PIR Sensor

Hello Everyone!

I am trying to manipulate Neopixel stripes with a PIR Sensor but I cant. Can someone please guide me? I am using the RGWstrandtest sketch but I dont know how to integrate the sensor.

I am still a beginner but I need to have this for a university project.

Thank you so much.

Define manipulate. Post your code here. Describe what the code actually does and how that differs from what you want the code to do. Post a data sheet for the PIR sensor. Post a schematic of your project.

Please read the "how to use this forum-please read" stickies to see how to format and post code and some hints on how to ask an effective question. We can't help, much, without more information. Details are important.

/*
Arduino with PIR motion sensor
For complete project details, visit: Arduino with PIR Motion Sensor | Random Nerd Tutorials
Modified by Rui Santos based on PIR sensor by Limor Fried
*/
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 60

int Adafruit_NeoPixel = 6; // the pin that the Adafruit is attached to
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

void setup() {
pinMode(Adafruit_NeoPixel, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}

void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(Adafruit_NeoPixel, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds

if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(Adafruit_NeoPixel, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds

if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}

This is the Code that i'm using. I was able to turn on the first LED of the NeoPixel Stripe when the PIR sensor detected movement.but I don't know how to turn on the other ones. There are 60 NeoPixels in total.

Here you see only the first led is turned on. Not the whole strip.

You've included the Neopixel library, but you are not using it. A few minutes on the LadyAda site found me this tutorial on how to use it: adafruit-neopixel-uberguide.

There's some config, setup and then you can use setPixelColor on your strip to command individual LEDs.

Disclaimer - never used one of these things although now I'm intrigued enough that I might.

*/
#include <Adafruit_NeoPixel.h>
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60,6); //(number of leds, pin where the adafruit is attached to)

uint16_t n = strip.numPixels(); //when I insert any number here, an error occurs: no matching function for call to"Adafruit_NeoPixel::numbPixels(int)"

strip.setBrightness(64);

Unsurprising. strip.numPixels() is a function that tells you how many pixels that particular strip has. It has no need for any additional parameters to do that job - which is what the compiler is telling you, albeit somewhat obliquely.

ok. Thanks for your help. I don't understand how to make it work. I still have the same problem even if I use the RGBstrandtest sketch from Adafruit.

What about the plain old strand test that comes with the library?

Have you tried the debugging steps here: arduino-library-installation?

now the neopixels work fine and when I check the serial monitor, the motion sensor also works fine.
the problem is that they're not working together. :o
maybe now you can help me looking at my sketch :slight_smile:

thank you so much

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 60
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(60, 6);

//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;
int Adafruit_NeoPixel = 6; // the pin that the Adafruit is attached to
int totalLEDs = 60; // total number of LEDs connected
int sensor = 8; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

void setup() {

pinMode(Adafruit_NeoPixel, OUTPUT); // initalize Adafruit as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial

pixels.begin();
pixels.setPixelColor(0, pixels.Color(100,0,0));
pixels.setPixelColor(1, pixels.Color(100,0,0));
pixels.setPixelColor(2, pixels.Color(100,0,0));
pixels.setPixelColor(3, pixels.Color(100,0,0));
pixels.setPixelColor(4, pixels.Color(100,0,0));
pixels.setPixelColor(5, pixels.Color(100,0,0));
pixels.setPixelColor(6, pixels.Color(100,0,0));
pixels.setPixelColor(7, pixels.Color(100,0,0));
pixels.setPixelColor(8, pixels.Color(100,0,0));
pixels.setPixelColor(9, pixels.Color(100,0,0));
pixels.setPixelColor(10, pixels.Color(100,0,0));
pixels.setPixelColor(11, pixels.Color(100,0,0));
pixels.setPixelColor(12, pixels.Color(100,0,0));
pixels.setPixelColor(13, pixels.Color(100,0,0));
pixels.setPixelColor(14, pixels.Color(100,0,0));
pixels.setPixelColor(15, pixels.Color(100,0,0));
pixels.setPixelColor(16, pixels.Color(100,0,0));
pixels.setPixelColor(17, pixels.Color(100,0,0));
pixels.setPixelColor(18, pixels.Color(100,0,0));
pixels.setPixelColor(19, pixels.Color(100,0,0));
pixels.setPixelColor(20, pixels.Color(100,0,0));
pixels.setPixelColor(21, pixels.Color(100,0,0));
pixels.setPixelColor(22, pixels.Color(100,0,0));
pixels.setPixelColor(23, pixels.Color(100,0,0));
pixels.setPixelColor(24, pixels.Color(100,0,0));
pixels.setPixelColor(25, pixels.Color(100,0,0));
pixels.setPixelColor(26, pixels.Color(100,0,0));
pixels.setPixelColor(27, pixels.Color(100,0,0));
pixels.setPixelColor(28, pixels.Color(100,0,0));
pixels.setPixelColor(29, pixels.Color(100,0,0));
pixels.setPixelColor(30, pixels.Color(100,0,0));
pixels.setPixelColor(31, pixels.Color(100,0,0));
pixels.setPixelColor(32, pixels.Color(100,0,0));
pixels.setPixelColor(33, pixels.Color(100,0,0));
pixels.setPixelColor(34, pixels.Color(100,0,0));
pixels.setPixelColor(35, pixels.Color(100,0,0));
pixels.setPixelColor(36, pixels.Color(100,0,0));
pixels.setPixelColor(37, pixels.Color(100,0,0));
pixels.setPixelColor(38, pixels.Color(100,0,0));
pixels.setPixelColor(39, pixels.Color(100,0,0));
pixels.setPixelColor(40, pixels.Color(100,0,0));
pixels.setPixelColor(41, pixels.Color(100,0,0));
pixels.setPixelColor(42, pixels.Color(100,0,0));
pixels.setPixelColor(43, pixels.Color(100,0,0));
pixels.setPixelColor(44, pixels.Color(100,0,0));
pixels.setPixelColor(45, pixels.Color(100,0,0));
pixels.setPixelColor(46, pixels.Color(100,0,0));
pixels.setPixelColor(47, pixels.Color(100,0,0));
pixels.setPixelColor(48, pixels.Color(100,0,0));
pixels.setPixelColor(49, pixels.Color(100,0,0));
pixels.setPixelColor(50, pixels.Color(100,0,0));
pixels.setPixelColor(51, pixels.Color(100,0,0));
pixels.setPixelColor(52, pixels.Color(100,0,0));
pixels.setPixelColor(53, pixels.Color(100,0,0));
pixels.setPixelColor(54, pixels.Color(100,0,0));
pixels.setPixelColor(55, pixels.Color(100,0,0));
pixels.setPixelColor(56, pixels.Color(100,0,0));
pixels.setPixelColor(57, pixels.Color(100,0,0));
pixels.setPixelColor(58, pixels.Color(100,0,0));
pixels.setPixelColor(59, pixels.Color(100,0,0));
pixels.setPixelColor(60, pixels.Color(100,0,0));
pixels.show();

}

void loop(){

if(digitalRead(sensor) == HIGH){
digitalWrite(Adafruit_NeoPixel, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}

if(digitalRead(sensor) == LOW){
digitalWrite(Adafruit_NeoPixel, LOW); //the led visualizes the sensors output pin state

if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}

Why is all the LED control code in setup() and not inside the i clause in loop() ?

Why not use a for loop when setting the colour of the LEDs ?

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code. Do not post double spaced code.

digitalWrite(Adafruit_NeoPixel, HIGH);

That is not the way to turn on a Neopixel. Do you see that in the examples? No!

Come on with that code to change the colours you deserve to fail anything you are studying.

Also where has my origional post, reply #1 dissapered to?

Grumpy_Mike:
Also where has my origional post, reply #1 dissapered to?

Are you thinking of a reply you made to one of davi22's three crossposts on this topic?

I too replied to one of his many posts but goodness know which one

ok i'll take your tips into consideration. im a design student. I have never in my life dealt with programming and electronics. i'm trying to teach myself this so I can achieve something new in my field so no reason to be questining my abilities. I came to the forum because I needed help. I thought that is what the arduino community does.

I came to the forum because I needed help. I thought that is what the arduino community does.

But posting the same question in at least 3 different sections of the forum has done you no favours. My helpful reply to one of them which included a working example has been lost as have other replies.

davi22:
I came to the forum because I needed help. I thought that is what the arduino community does.

It dose to all decent people, but you were an arrogant so n so, and did not bother to read the rules because you were above that. You cross posted three times and did not use code tags even when you were told. You ignored advice and didn’t even bother to research your project.

Yes we help people but we don’t like being jerked about by them, we expect to be treated with common curtesy, not the contempt you showed.

Well said Mike