15/11/2022
"CAR'S COUNTER"
By :
NURUL WAHIDAH BINTI HANAFIAH
ALICE PRISSILA BT AKIAM
CLASS : WASEDA (EMBEDDED SYSTEM)
SESSION : JAN-JUN 2017
PROJECT NAME : CARโS COUNTER
Introduction :
1) To develop an automatic system using Arduino Mega 2560
R3.
2) To apply the coding of count in Arduino.
3) To make a system that can notify when parking is full on
Liquid Crystal Display (LCD).
Components :
1) Arduino Mega 2560 R3.
2) LCD keypad shield
3) 8 X LED module
4) Photo-electric sensor module
5) Male to female wire jumper
6) Male to male wire jumper
7) Breadboard
Coding :
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //Declared the no pin of lcd, no pin must be follow the datasheet (RS, E, D4, D5, D6, D7)
//The condition state of COUNT is '0', so it will start and count from '0' first
int count=0;
//This void setup for declared the input & output and also the number pin of arduino that we used.
void setup()
{
lcd.begin(16,2);
//The lcd will display 'CARS COUNTER' for awhile when the lcd connect with supply
lcd.print("CAR'S COUNTER:");
delay(500);
pinMode(44, INPUT);
//Declared the no pin of sensor 1, and we used pin number 44 on arduino. The is an input as SENSOR 1.
pinMode(45, INPUT);
//Declared the no pin of sensor 2, and we used pin number 45 on arduino. The is an input as SENSOR 2.
delay(500);
lcd.clear();
lcd.print("CAR TOTAL:");
lcd.setCursor(0,1);
lcd.print(count);
//This is an input as parking sensor that will detect the car, and we declared the pin number of arduino is (22, 23, 24, 25).
pinMode(22,INPUT);//SENSOR PARKING 1
pinMode(23,INPUT);//SENSOR PARKING 2
pinMode(24,INPUT);//SENSOR PARKING 3
pinMode(25,INPUT);//SENSOR PARKING 4
//This is an output as led that will blink when the sensor detect, and we declared the pin number of arduino is (50, 51, 52, 53).
pinMode(50,OUTPUT);//LED 1
pinMode(51,OUTPUT);//LED 2
pinMode(52,OUTPUT);//LED 3
pinMode(53,OUTPUT);//LED 4
}
//This void loop will read the programme as we want.
void loop()
{
if(digitalRead(44)==LOW)//The car will go through the sensor 1 first
{
delay(500);
if(digitalRead(45)==LOW)//Then, go through to the sensor 2
{
//When the SENSOR 1 detects the car first and then go to the sensor 2, it will count increase
count++;
lcd.clear();
lcd.print("CAR TOTAL:");
lcd.setCursor(0,1);
lcd.print(count);
delay(500);
}
}
if(digitalRead(45)==LOW)
{
delay(500);
if(digitalRead(44)==LOW)
{
//When the SENSOR 2 detects the car first and then go to the sensor 1, it will count decrease
count--;
lcd.clear();
lcd.print("CAR TOTAL:");
lcd.setCursor(0,1);
lcd.print(count);
delay(500);
}
}
//If the 22=PARKING SENSOR 1 detects the car, LED 1 will turn ON indicates the parking in is filled by car
if(digitalRead(22)==LOW)
{
digitalWrite(50,HIGH);
digitalWrite(51,LOW);
digitalWrite(52,LOW);
digitalWrite(53,LOW);
}
//If the 23=PARKING SENSOR 2 detects the car, LED 2 will turn ON indicates the parking is filled by car
if(digitalRead(23)==LOW
{
digitalWrite(51,HIGH);
}
//If the 24=PARKING SENSOR 3 detects the car, LED 3 will turn ON indicates the parking is filled by car
if(digitalRead(24)==LOW)
{
digitalWrite(52,HIGH);
}
//If the 25=PARKING SENSOR 4 detects the car, LED 4 will turn ON indicates the parking is filled by car
if(digitalRead(25)==LOW)
{
digitalWrite(53,HIGH);
}
else
{
//If there are no PARKING SENSOR detects the car, all LED will turn OFF
digitalWrite(50,LOW);
digitalWrite(51,LOW);
digitalWrite(52,LOW);
digitalWrite(53,LOW);
}
if(count=4)//If the SENSOR 1 and SENSOR 2 detect 4 cars the lcd will display "PARKING FULL"
{
lcd.clear();
lcd.print("PARKING FULL");
lcd.setCursor(0,1);
delay(200);
}
}