Hi, I have 2 Pir sensors and I want them to both have input but make 2 different outputs (2 separate counters) on 1 lcd can someone please help?
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pirPin = 10;
int pirPin1 = 9;
int pirState = LOW; // we start, assuming no motion detected
int pirState1 = LOW;
int val = 0; // variable for reading the pin status
int val1 = 0;
int counter = 0;
int counter1 = 0;
int currentState = 0;
int previousState = 0;
int currentState1 = 0;
int previousState1=0;
void setup() {
pinMode(pirPin1, INPUT);
pinMode(pirPin, INPUT); // declare sensor as input
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("RedTeam-BlueTeam");
lcd.setCursor(8,1);
lcd.print("-");
}
void loop(){
val = digitalRead(pirPin); // read PIR sensor input value
if (val == HIGH) { // check if the input is HIGH
if (pirState == LOW) {
// we have just turned on
currentState = 1;
// We only want to print on the output change, not state
pirState = HIGH;
delay(1000);
}
} else {
if (pirState == HIGH){
// we have just turned off
currentState = 0;
// We only want to print on the output change, not state
pirState = LOW;
}
//second pir sensor stuff
val1 = digitalRead(pirPin1); // read PIR sensor input value
if (val1 == HIGH) { // check if the input is HIGH
if (pirState1 == LOW) {
// we have just turned on
currentState1 = 1;
// We only want to print on the output change, not state
pirState1 = HIGH;
delay(1000);
}
} else {
}
if (pirState == HIGH){
// we have just turned off
currentState = 0;
// We only want to print on the output change, not state
pirState = LOW;
} else {
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
lcd.setCursor(5,1);
lcd.print(counter);
delay(5000);
if(currentState1 != previousState1){
if(currentState1 == 1){
counter1 = counter1 + 1;
lcd.setCursor(7,1);
lcd.print(counter1);
delay(5000);
}else {
}
}
}
}
}
}
}