#include <LiquidCrystal_I2C.h>
int ledPin = 2;
int inputPin = 12;
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
int people_num = 0;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(115200);
lcd.init();
lcd.print("Welcome to xxx");
lcd.setCursor(1,1);
lcd.print("Park ! ");
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
lcd.clear();
Serial.println("Motion detected!");
people_num++;
//Serial.println("We have " + String(people_num) + " people arrived");
lcd.print(String(people_num));
lcd.print("\n");
lcd.print("people arrived");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
lcd.clear();
lcd.print("Wait for people");
// We only want to print on the output change, not state
pirState = LOW;
}
}
// lcd.setCursor(0,0);
// lcd.print("haha");
}