Hi Im new with arduino and Im creating new project with arduino uno
Project name is stairs light with two pir sensor..
Im using 2 pir sensor one of is upstairs (pirPin2) other one is downstairs (pirPin)
if pirPin detect a movement lights goes on to upstairs and pirPin2 detect a movement lights goes off from down to upstairs.
I know this is very basic, maybe silly but my question is how can I reverse this loop? I cant add second loop or something like this
so Ineed help for this I want to do this if pirPin2 detect any movement lights goes on to downstairs and pirPin detect any movement lights goes to down from up.
My codes are below you can see my codes
I hope its clear if you could help me I will be happy
=========================================================
int calibrationTime = 10;
//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 pirPin = 7; //the digital pin connected to the PIR sensor's output
int ledPin1 = 8;
int ledPin2 = 9;
int ledPin3 = 13;
int ledPin4 = 12;
int ledPin5 = 11;
int pirPin2 = 6;
/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(pirPin2, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
digitalWrite(pirPin2, LOW);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
////////////////////////////
//LOOP
void loop(){
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin1, HIGH);
delay(200);
digitalWrite(ledPin2, HIGH);
delay(200);
digitalWrite(ledPin3, HIGH);
delay(200);
digitalWrite(ledPin4, HIGH);
delay(200);
digitalWrite(ledPin5, HIGH); }
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 pirPin2 ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
if(digitalRead(pirPin2) == HIGH){
digitalWrite(ledPin1, LOW);
delay(500); //the led visualizes the sensors output pin state
digitalWrite(ledPin2, LOW);
delay(500);
digitalWrite(ledPin3, LOW);
delay(500);
digitalWrite(ledPin4, LOW);
delay(500);
digitalWrite(ledPin5, LOW);}
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);
}
}