/* PARKING LOT PROJECT
Baptiste Pousset
For developpement pruposes the fair of staying in the parking spot is $2/seconds
FYI the sensor takes 6 (clock) seconds to turn off
*/
#include <LiquidCrystal_I2C.h> //LCD library
LiquidCrystal_I2C lcd(0x27,16,2); // LCD size and screen parameters
const int ledred = 22; // LED RED ativation pin
const int ledgreen = 21; // LED GREEN activation pin
//variable of the pins to the motion sensors
int M1 = 34;
int M2 = 35;
int M3 = 32;
int M4 = 33;
int M5 = 25;
int M6 = 26;
int M7 = 27;
int M8 = 14;
int M9 = 12;
int M10 = 13;
// variable for reading the motion sensor status
int val1 = LOW;
int val2 = LOW;
int val3 = LOW;
int val4 = LOW;
int val5 = LOW;
int val6 = LOW;
int val7 = LOW;
int val8 = LOW;
int val9 = LOW;
int val10 = LOW;
// variable to get time of sensor activation
int t1 = 0;
int t2 = 0;
int t3 = 0;
int t4 = 0;
int t5 = 0;
int t6 = 0;
int t7 = 0;
int t8 = 0;
int t9 = 0;
int t10 = 0;
//parking spot status
int v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
//flags of each parking spot. F=0 someone just left and payed, F=1 someone on parking, F=2 no one in parking spot
int f1=0,f2=0,f3=0,f4=0,f5=0,f6=0,f7=0,f8=0,f9=0,f10=0;
int value=0; // Parking price to be payed
int Cap = 0; // Parking ocupancy
int Ava = 10; // Parking left
void setup() {
Wire.begin(4,5); //connection of the LCD
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(ledred, OUTPUT); // declare LED as output
pinMode(ledgreen, OUTPUT); // declare LED as output
pinMode(M1, INPUT); // declare sensor as input
pinMode(M2, INPUT); // declare sensor as input
pinMode(M3, INPUT); // declare sensor as input
pinMode(M4, INPUT); // declare sensor as input
pinMode(M5, INPUT); // declare sensor as input
pinMode(M6, INPUT); // declare sensor as input
pinMode(M7, INPUT); // declare sensor as input
pinMode(M8, INPUT); // declare sensor as input
pinMode(M9, INPUT); // declare sensor as input
pinMode(M10, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop() {
val1 = digitalRead(M1); // read input value
val2 = digitalRead(M2); // read input value
val3 = digitalRead(M3); // read input value
val4 = digitalRead(M4); // read input value
val5 = digitalRead(M5); // read input value
val6 = digitalRead(M6); // read input value
val7 = digitalRead(M7); // read input value
val8 = digitalRead(M8); // read input value
val9 = digitalRead(M9); // read input value
val10 = digitalRead(M10); // read input
// converting to variable HIGH to 1 and LOW to 0 with a condition statement and time ticks
if (val1 == HIGH ){
v1=1;
t1+=1; // should be a start counting
delay(1000);
f1=1; //flag saying that there was someone there recently
}
else if (f1 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f2 == 0 ||f3 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t2+=15;t3+=15;t4+=15;t5+=15;
// }
value = t1*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P1");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P1");
}
delay (15000);
f1=0; // flag put back down
value=0;
}
else {
v1=0; // there is no one in the spot
t1=0; // the tick count has stopped
f1=2; //this means there is no one in the
}
//Sensor 2
if (val2 == HIGH){
v2=1;
t2+=1; // should be a start counting
delay(1000);
f2=1;
}
else if (f2 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f1 == 0 ||f3 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t2+=15;
// }
value = t2*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P2");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P2");
}
delay (15000);
f2=0; // flag put back down
value=0;
}
else {
v2=0; // there is no one in the spot
t2=0; // the tick count has stopped
f2=2; //this means there is no one in the spot
}
//Sensor 3
if (val3 == HIGH){
v3=1;
t3+=1; // should be a start counting
delay(1000);
f3=1;
}
else if (f3 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f1 == 0 ||f2 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t3+=15;
// }
value = t3*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P3");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P3");
}
delay (15000);
f3=0; // flag put back down
value=0;
}
else {
v3=0; // there is no one in the spot
t3=0; // the tick count has stopped
f3=2; //this means there is no one in the spot
}
//Sensor 4
if (val4 == HIGH){
v4=1;
t4+=1; // should be a start counting
delay(1000);
f4=1;
}
else if (f4 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
// if (f1 == 0 ||f2 == 0 || f3 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t4+=15;
// }
value = t4*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P4");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P4");
}
delay (15000);
f4=0; // flag put back down
value=0;
}
else {
v4=0; // there is no one in the spot
t4=0; // the tick count has stopped
f4=2; //this means there is no one in the spot
}
//Sensor 5
if (val5 == HIGH){
v5=1;
t5+=1; // should be a start counting
delay(1000);
f5=1;
}
else if (f5 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f1 == 0 ||f2 == 0 || f3 == 0 || f4 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t5+=15;
// }
value = t5*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P5");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P5");
}
delay (15000);
f5=0; // flag put back down
value=0;
}
else {
v5=0; // there is no one in the spot
t5=0; // the tick count has stopped
f5=2; //this means there is no one in the spot
}
//Sensor 6
if (val6 == HIGH){
v6=1;
t6+=1; // should be a start counting
delay(1000);
f6=1;
}
else if (f6 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f1 == 0 ||f2 == 0 || f3 == 0 || f4 == 0 || f5 == 0 || f7 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t6+=15;
//}
value = t6*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P6");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P6");
}
delay (15000);
f6=0; // flag put back down
value=0;
}
else {
v6=0; // there is no one in the spot
t6=0; // the tick count has stopped
f6=2; //this means there is no one in the spot
}
//Sensor 7
if (val7 == HIGH){
v7=1;
t7+=1; // should be a start counting
delay(1000);
f7=1;
}
else if (f7 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
// if (f1 == 0 ||f2 == 0 || f3 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f8 == 0 || f9 == 0|| f10 == 0){
// t7+=15;
//}
value = t7*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P7");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P7");
}
delay (15000);
f7=0; // flag put back down
value=0;
}
else {
v7=0; // there is no one in the spot
t7=0; // the tick count has stopped
f7=2; //this means there is no one in the spot
}
//Sensor 8
if (val8 == HIGH){
v8=1;
t8+=1; // should be a start counting
delay(1000);
f8=1;
}
else if (f8 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f1 == 0 ||f2 == 0 || f3 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f9 == 0|| f10 == 0){
// t8+=15;
// }
value = t8*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P8");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P8");
}
delay (15000);
f8=0; // flag put back down
value=0;
}
else {
v8=0; // there is no one in the spot
t8=0; // the tick count has stopped
f8=2; //this means there is no one in the spot
}
//Sensor 9
if (val9 == HIGH){
v9=1;
t9+=1; // should be a start counting
delay(1000);
f9=1;
}
else if (f9 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
// if (f1 == 0 ||f2 == 0 || f3 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f10 == 0){
// t9+=15;
//}
value = t9*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P9");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P9");
}
delay (10000); // ten second was put for debuging purposes
//delay (15000); Uncomment for 15 seconds display on the screen
f9=0; // flag put back down
value=0;
}
else {
v9=0; // there is no one in the spot
t9=0; // the tick count has stopped
f9=2; //this means there is no one in the spot
}
//Sensor 10
if (val10 == HIGH){
v10=1;
t10+=1; // should be a start counting
delay(1000);
f10=1;
}
else if (f10 == 1 ){ // when val1==LOW and the flag is up
//if ofther spots are checking out we add the 15s delay of the message to
//if (f1 == 0 ||f2 == 0 || f3 == 0 || f4 == 0 || f5 == 0 || f6 == 0 || f7 == 0 || f8 == 0 || f9 == 0){
// t10+=15;
// }
value = t10*2; // value is three didgits
Serial.print(value);
//prints out the amount due
lcd.setCursor(0, 0);
lcd.print("Your total cost");
lcd.setCursor(0, 1);
lcd.print(" is $ ");
if (value < 10){
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(7, 1);
lcd.print(" .00 P10");
}
else {
lcd.setCursor(6, 1);
lcd.print(value);
lcd.setCursor(8, 1);
lcd.print(".00 P10");
}
delay (15000);
f10=0; // flag put back down
value=0;
}
else {
v10=0; // there is no one in the spot
t10=0; // the tick count has stopped
f10=2; //this means there is no one in the spot
}
// Printing the screen status of system <capacity
//included 10 to artificially make parking lot full because there is no time to do that with theses motion sensors
Cap = /*10;*/ v1 + v2 + v3 + v4 + v5 + v6 + v7 +v8 + v9 +v10;
Ava = 10 - Cap;
//Serial.print(val1);
Serial.print(" <");
Serial.print(Cap); //show total capacity
Serial.print(".");
Serial.print(Ava);
Serial.print(".");
Serial.print(t1);
Serial.print(".");
Serial.print(t2);
Serial.print(".");
Serial.print(t3);
Serial.print(".");
Serial.print(t4);
Serial.print(".");
Serial.print(t5);
Serial.print(".");
Serial.print(t6);
Serial.print(".");
Serial.print(t7);
Serial.print(".");
Serial.print(t8);
Serial.print(".");
Serial.print(t9);
Serial.print(".");
Serial.print(t10);
Serial.print("> ");
if (Cap == 10){
digitalWrite(ledred, HIGH); // turn LED ON
digitalWrite(ledgreen, LOW); // turn LED ON
lcd.setCursor(0, 0);
lcd.print(" PARKING ");
lcd.setCursor(0, 1);
lcd.print(" FULL ");
//delay (2000);
}
else {
// LED becomes green
digitalWrite(ledred, LOW);
digitalWrite(ledgreen, HIGH);
// screen show available parking
lcd.setCursor(0, 0); // print on line 1 powsition 0
lcd.print(" PARKING ");
if (Ava < 10){ // condition for printing one digit or two digits
lcd.setCursor(1, 1); // print on line 2 powsition 0
lcd.print(" ");
lcd.setCursor(2,1);
lcd.print(Ava);
lcd.setCursor(3, 1);
lcd.print(" Spots OPEN ");
}
else {
lcd.setCursor(1, 1);
lcd.print("10 Spots OPEN ");
}
}
}