int ledPin1 = 13; // choose the pin for the LED
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int inputPin = 9; // choose the input pin (for PIR sensor)
int inputPin2 = 8;
int buzzerPin = 7;
int switchPin = 6; //pin for door sensor1
int switchPin2 = 5; // pin for door sensor2
int pirState1 = LOW;
int pirState2 = LOW;
int val = 0;
int val2 = 0;
int magnetState = LOW;
int magnetState2 = LOW;
int magnetValState = 0;
int magnetValState2 = 0;
void setup() {
pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(ledPin2, OUTPUT); // declare LED as output
pinMode(ledPin3, OUTPUT);
pinMode(inputPin, INPUT); // declare sensor 1 as input
pinMode(inputPin2, INPUT); // declare sensor 2 as input
pinMode(buzzerPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(switchPin2, INPUT);
digitalWrite(switchPin, HIGH);
digitalWrite(switchPin2, HIGH);
Servo1.attach(servoPin);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED ON
magnetValState = digitalRead(switchPin);
if (digitalRead(switchPin) == HIGH) {
digitalWrite(ledPin2, HIGH);
delay(1500);
digitalWrite(ledPin2, LOW);
delay(1500);
digitalWrite(buzzerPin, HIGH);
Serial.println("Door brake!");
}
if (pirState1 == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState1 = HIGH;
}
}
// check sensor 2 after delay
val2 = digitalRead(inputPin2);
if (val2 == HIGH) {
digitalWrite(ledPin3, HIGH);
magnetValState2 = digitalRead(switchPin2);
if (digitalRead(switchPin2) == HIGH) {
digitalWrite(ledPin4, HIGH);
delay(50);
digitalWrite(ledPin4, LOW);
delay(50);
digitalWrite(buzzerPin, HIGH);
Serial.println("Door brake!");
}
if(pirState2 == LOW) {
// we have just turned on
Serial.println("Motion from sensor 2 detected!");
// We only want to print on the output change, not state
pirState2 = HIGH;
}
} else {
digitalWrite(ledPin1, LOW); // turn LED OFF
delay (50);
digitalWrite(ledPin2, LOW); // may be already
//playTone(0, 0);
delay(50);
digitalWrite(ledPin3, LOW); // turn LED OFF
delay (50);
digitalWrite(ledPin4, LOW); // turn LED OFF
delay (50);
if (pirState1 == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState1 = LOW;
}
if (pirState2 == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState2 = LOW;
}
}
}
how can i combine two pir sensor with door sensor??
can anyone help me…