I have been working on an LED project that runs continuously, but I only want it to run when the Parallax PIR senses movement
I thought I could control it using "Do While LED (pin 13) but I haven't been successful
any help?
/*
Simulation of a dragstrip light tree.
*/
int stage1a = 2;
int stage2a = 3;
int stage1b = 4;
int stage2b = 5;
int tree1 = 6;
int tree2 = 7;
int tree3 = 8;
int treetop = 9;
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(stage1a, OUTPUT);
pinMode(stage2a, OUTPUT);
pinMode(stage1b, OUTPUT);
pinMode(stage2b, OUTPUT);
pinMode(tree1, OUTPUT);
pinMode(tree2, OUTPUT);
pinMode(tree3, OUTPUT);
pinMode(treetop, OUTPUT);
pinMode(led, OUTPUT);
randomSeed(analogRead(0));
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, 0); // delay 15 seconds between runs
digitalWrite(stage1a, HIGH);
delay(random(300,2000)); // throw in a random delay for the next staging
digitalWrite(stage1b, HIGH);
delay(random(1500,3000)); // throw in a random delay for the next staging
digitalWrite(stage2b, HIGH);
delay(random(300,1500)); // throw in a random delay for the next staging
digitalWrite(stage2a, HIGH);
delay(500);
digitalWrite(tree1, HIGH);
delay(500);
digitalWrite(tree2, HIGH);
delay(500);
digitalWrite(tree3, HIGH);
delay(500);
digitalWrite(treetop, HIGH);
/* after the race starts, wait 10 seconds, then turn off all the lights.
delay(10000); */
digitalWrite(stage1a, LOW);
digitalWrite(stage1b, LOW);
digitalWrite(stage2b, LOW);
digitalWrite(stage2a, LOW);
digitalWrite(tree1, LOW);
digitalWrite(tree2, LOW);
digitalWrite(tree3, LOW);
digitalWrite(treetop, LOW);
digitalWrite(led, 1);
delay(200);
}
If I understand correctly, you need to attach a PIR sensor module and have the code run when there is a motion detected? If yes, define one of the digital pin as input pin and connect the output of the PIR sensor to that digital pin. when there is a moment, the output of the PIR sensor goes high. Use if statement like this
if (digitalread(sensorPin) == HIGH)
{
//put your code here
}
else
{
//do nothing or anything that you want to execute
}