Altium
Arduino Projects

Car Parking Monitoring System using Arduino and vb.net

Car Parking Monitoring System, Project Description:

car parking

Car Parking Monitoring System using Arduino and vb.net– This tutorial is about the Car parking Slots monitoring system using a computer application designed in Visual Basic .net Which is also known as vb.net.  this project is based on the vb.net, Arduino, and infrared sensors. A total of six IR sensors are used in this car parking project. The car parking area is divided into two parking areas, Parking 1 and Parking 2. Each Parking slot has an infrared sensor, which is used for car detection. Depending on the detection of the car the box next to the slot is checked or unchecked. If the box is checked it means the slot is occupied by a car.

This Tutorial covers

  1. IR Sensors installation
  2. Car Parking System Circuit diagram
  3. IR Sensors Interfacing with Arduino
  4. Car Parking System Arduino programming
  5. Car Parking system Computer Application
  6. application designing and finally
  7. Testing

checkout another version of the same project based on the IoT. In this project, the car slots are monitored using the Cell phone application.


Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

Obstacle IR Infrared Sensor:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Car Parking Monitoring System Circuit Diagram:

car parking

This is the complete circuit diagram of the car parking monitoring system. The circuit diagram is designed in cadsoft eagle version 9.1.0. These are the six infrared sensors.  Each infrared sensor represents a Slot.

Vcc of all the infrared sensors are connected together and are connected with Arduino’s 5v. Similarly, the ground pins of all the infrared sensors are connected together and are connected with the Arduino’s ground. While the out pins of the infrared sensors are connected with

 pin number 4

pin number 5

pin number 6

pin number 7

pin number 8 and

pin number 9


Car Parking Monitoring System Arduino Programming:

First I started off by defining pins for the infrared sensors. Then I defined 6 variables of the type String with names sensor1 to sensor6. Finally, I defined a variable cdata of the type String for storing the complete message.

int parking1_slot1_ir_s = 4; // parking slot1 infrared sensor connected with pin number 4 of arduino
int parking1_slot2_ir_s = 5;
int parking1_slot3_ir_s = 6;

int parking2_slot1_ir_s = 7;
int parking2_slot2_ir_s = 8;
int parking2_slot3_ir_s = 9;

String sensor1; 
String sensor2; 
String sensor3; 
String sensor4; 
String sensor5; 
String sensor6; 


String cdata =""; // complete data, consisting of sensors values

void setup()
{
Serial.begin(9600); 

activates the serial communication, 9600 is the buad rate.

Using the pinmode function set all infrared sensors as input. Pinmode function is a built in function and it takes two arguments as the input, the pin number or pin name and the status which can be input or output.

pinMode(parking1_slot1_ir_s, INPUT);
pinMode(parking1_slot2_ir_s, INPUT);
pinMode(parking1_slot3_ir_s, INPUT);

pinMode(parking2_slot1_ir_s, INPUT);
pinMode(parking2_slot2_ir_s, INPUT);
pinMode(parking2_slot3_ir_s, INPUT);


}

void loop()
{

For monitoring each infrared sensor individually I created 6 functions. So these are the six calling functions.

p1slot1(); 
p1slot2();
p1slot3(); 

p2slot1();
p2slot2();
p2slot3();

  
  
   cdata = cdata + sensor1 +"," + sensor2 + ","+ sensor3 +","+ sensor4 + "," + sensor5 + "," + sensor6 +","; // comma will be used a delimeter
   Serial.println(cdata); 
   nodemcu.println(cdata);
   delay(2000); // 2 seconds
   cdata = ""; 
digitalWrite(parking1_slot1_ir_s, HIGH); 
digitalWrite(parking1_slot2_ir_s, HIGH); 
digitalWrite(parking1_slot3_ir_s, HIGH);

digitalWrite(parking2_slot1_ir_s, HIGH);
digitalWrite(parking2_slot2_ir_s, HIGH);
digitalWrite(parking2_slot3_ir_s, HIGH);
}

P1slot1 is a user defined function, it has no return type and it doesn not take any argument as the input.  if there is a car infront of the sensor it gives digital logic 0, and if no car then it give digital logic 1, depending on this, then we store p1s1on or p1s1off.  The same mechanism is used for all the other infrared sensors.

void p1slot1() // parkng 1 slot1
{
  if( digitalRead(parking1_slot1_ir_s) == LOW) 
  {
  sensor1 = "p1s1on"; // parking1 slot1 
 delay(200); 
  } 
if( digitalRead(parking1_slot1_ir_s) == HIGH)
{
  sensor1 = "p1s1off";  
 delay(200);  
}

}

void p1slot2() // parking 1 slot2
{
  if( digitalRead(parking1_slot2_ir_s) == LOW) 
  {
  sensor2 = "p1s2on"; 
  delay(200); 
  }
if( digitalRead(parking1_slot2_ir_s) == HIGH)  
  {
  sensor2 = "p1s2off";  
 delay(200);
  } 
}


void p1slot3() // parking 1 slot3
{
  if( digitalRead(parking1_slot3_ir_s) == LOW) 
  {
  sensor3 = "p1s3on"; 
  delay(200); 
  }
if( digitalRead(parking1_slot3_ir_s) == HIGH)  
  {
  sensor3 = "p1s3off";  
 delay(200);
  } 
}


// now for parking 2

void p2slot1() // parking 1 slot3
{
  if( digitalRead(parking2_slot1_ir_s) == LOW) 
  {
  sensor4 = "p2s1on"; 
  delay(200); 
  }
if( digitalRead(parking2_slot1_ir_s) == HIGH)  
  {
  sensor4 = "p2s1off";  
 delay(200);
  } 
}


void p2slot2() // parking 1 slot3
{
  if( digitalRead(parking2_slot2_ir_s) == LOW) 
  {
  sensor5 = "p2s2on"; 
  delay(200); 
  }
if( digitalRead(parking2_slot2_ir_s) == HIGH)  
  {
  sensor5 = "p2s2off";  
 delay(200);
  } 
}


void p2slot3() // parking 1 slot3
{
  if( digitalRead(parking2_slot3_ir_s) == LOW) 
  {
  sensor6 = "p2s3on"; 
  delay(200); 
  }
if( digitalRead(parking2_slot3_ir_s) == HIGH)  
  {
  sensor6 = "p2s3off";  
 delay(200);
  } 
}

Car Parking Monitoring System Computer application:

car parking

This is how the computer application looks like. In this application we are using only one serial port and only one timer. If you double click on the application form you will get access to the programming.

First I started off by importing the system.io and system.io.ports.

Then I defined  one variable of the type integer which is value1.


Imports System.IO
Imports System.IO.Ports

Public Class Form1

    Dim value1 As Integer

Double click on the form and add the code for the Serial port. currently the port name is com19 which is as per my laptop. You can check your Arduino’s port number from the device manager. Change com19 to the number as per your laptop or computer.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SerialPort1.Close()
        SerialPort1.PortName = "com19"
        SerialPort1.BaudRate = "9600"
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
        SerialPort1.Open()
    End Sub



    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim s As String

Defines a variable s of the type string.

the purpose of this line of code is to store the complete message in variable s. this is the message which is received from Arduino.

s = TextBox1.Text + "," + "," + "," + "," + "," + "," + ""

        Dim somestring() As String
        ' Split string based on comma
        somestring = s.Split(New Char() {","c})

        TextBox2.Text = somestring(0)
        TextBox3.Text = somestring(1)
        TextBox4.Text = somestring(2)
        TextBox5.Text = somestring(3)
        TextBox6.Text = somestring(4)
        TextBox7.Text = somestring(5)
        TextBox1.Text = ""

    End Sub

then these instructions are used to set the delimiter type which is comma in my case, with the help of comma the entire message will be split in six strings, then each string will be displayed in its corresponding text box, Each textbox represents the infrared sensor.

Data received function, I have used this function in so many projects, and I have already explained  this in very detail. the purpose of this function is to read the serial port and store the data in textbox1.


    Private Sub DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Try
            Dim mydata As String = ""
            mydata = SerialPort1.ReadExisting()

            If TextBox1.InvokeRequired Then
                TextBox1.Invoke(DirectCast(Sub() TextBox1.Text &= mydata, MethodInvoker))
            Else
                TextBox1.Text &= mydata
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub



    Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
        If InStr(TextBox2.Text, "p1s1on") Then
            chkp1slot1.Checked = True
        End If

        If InStr(TextBox2.Text, "p1s1off") Then
            chkp1slot1.Checked = False
        End If
    End Sub

    Private Sub TextBox3_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox3.TextChanged
        If InStr(TextBox3.Text, "p1s2on") Then
            chkp1slot2.Checked = True
        End If

        If InStr(TextBox3.Text, "p1s2off") Then
            chkp1slot2.Checked = False
        End If
    End Sub

    Private Sub TextBox4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox4.TextChanged
        If InStr(TextBox4.Text, "p1s3on") Then
            chkp1slot3.Checked = True
        End If

        If InStr(TextBox4.Text, "p1s3off") Then
            chkp1slot3.Checked = False
        End If
    End Sub

    Private Sub TextBox5_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox5.TextChanged
        If InStr(TextBox5.Text, "p2s1on") Then
            chkp2slot1.Checked = True
        End If

        If InStr(TextBox5.Text, "p2s1off") Then
            chkp2slot1.Checked = False
        End If
    End Sub

    Private Sub TextBox6_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox6.TextChanged
        If InStr(TextBox6.Text, "p2s2on") Then
            chkp2slot2.Checked = True
        End If

        If InStr(TextBox6.Text, "p2s2off") Then
            chkp2slot2.Checked = False
        End If
    End Sub

    Private Sub TextBox7_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox7.TextChanged
        If InStr(TextBox7.Text, "p2s3on") Then
            chkp2slot3.Checked = True
        End If

        If InStr(TextBox7.Text, "p2s3off") Then
            chkp2slot3.Checked = False
        End If
    End Sub
End Class

Watch Video Tutorial:

Other Related Project:

IOT based Car Parking System using Arduino and Nodemcu esp8266

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

9 Comments

  1. Hi, can i know what is the problem when the program run it only will loop 3 times after that it stop refreshing the sensor? Thank You.

    1. Once i run the vb program, the program will hang after refreshing few time of sensors, can i know what’s the problem? It can’t keep refresh again and again. It will stop and not running anymore. Thank You.

      1. I have to train this project to university. Please help me. I am your strict follower. Look, I’m writing this code:

        int parking1_slot1_ir_s = 4; // parking slot1 infrared sensor connected with pin number 4 of arduino
        int parking1_slot2_ir_s = 5;
        int parking1_slot3_ir_s = 6;

        int parking2_slot1_ir_s = 7;
        int parking2_slot2_ir_s = 8;
        int parking2_slot3_ir_s = 9;

        String sensor1;
        String sensor2;
        String sensor3;
        String sensor4;
        String sensor5;
        String sensor6;

        String cdata =””; // complete data, consisting of sensors values

        void setup()
        {
        Serial.begin(9600);
        pinMode(parking1_slot1_ir_s, INPUT);
        pinMode(parking1_slot2_ir_s, INPUT);
        pinMode(parking1_slot3_ir_s, INPUT);

        pinMode(parking2_slot1_ir_s, INPUT);
        pinMode(parking2_slot2_ir_s, INPUT);
        pinMode(parking2_slot3_ir_s, INPUT);

        }

        void loop()
        {
        p1slot1();
        p1slot2();
        p1slot3();

        p2slot1();
        p2slot2();
        p2slot3();

        cdata = cdata + sensor1 +”,” + sensor2 + “,”+ sensor3 +”,”+ sensor4 + “,” + sensor5 + “,” + sensor6 +”,”; // comma will be used a delimeter
        Serial.println(cdata);
        nodemcu.println(cdata);
        delay(2000); // 2 seconds
        cdata = “”;
        digitalWrite(parking1_slot1_ir_s, HIGH);
        digitalWrite(parking1_slot2_ir_s, HIGH);
        digitalWrite(parking1_slot3_ir_s, HIGH);

        digitalWrite(parking2_slot1_ir_s, HIGH);
        digitalWrite(parking2_slot2_ir_s, HIGH);
        digitalWrite(parking2_slot3_ir_s, HIGH);
        }

        P1slot1 is a user defined function, it has no return type and it doesn not take any argument as the input. if there is a car infront of the sensor it gives digital logic 0, and if no car then it give digital logic 1, depending on this, then we store p1s1on or p1s1off. The same mechanism is used for all the other infrared sensors.

        void p1slot1() // parkng 1 slot1
        {
        if( digitalRead(parking1_slot1_ir_s) == LOW)
        {
        sensor1 = “p1s1on”; // parking1 slot1
        delay(200);
        }
        if( digitalRead(parking1_slot1_ir_s) == HIGH)
        {
        sensor1 = “p1s1off”;
        delay(200);
        }

        }

        void p1slot2() // parking 1 slot2
        {
        if( digitalRead(parking1_slot2_ir_s) == LOW)
        {
        sensor2 = “p1s2on”;
        delay(200);
        }
        if( digitalRead(parking1_slot2_ir_s) == HIGH)
        {
        sensor2 = “p1s2off”;
        delay(200);
        }
        }

        void p1slot3() // parking 1 slot3
        {
        if( digitalRead(parking1_slot3_ir_s) == LOW)
        {
        sensor3 = “p1s3on”;
        delay(200);
        }
        if( digitalRead(parking1_slot3_ir_s) == HIGH)
        {
        sensor3 = “p1s3off”;
        delay(200);
        }
        }

        // now for parking 2

        void p2slot1() // parking 1 slot3
        {
        if( digitalRead(parking2_slot1_ir_s) == LOW)
        {
        sensor4 = “p2s1on”;
        delay(200);
        }
        if( digitalRead(parking2_slot1_ir_s) == HIGH)
        {
        sensor4 = “p2s1off”;
        delay(200);
        }
        }

        void p2slot2() // parking 1 slot3
        {
        if( digitalRead(parking2_slot2_ir_s) == LOW)
        {
        sensor5 = “p2s2on”;
        delay(200);
        }
        if( digitalRead(parking2_slot2_ir_s) == HIGH)
        {
        sensor5 = “p2s2off”;
        delay(200);
        }
        }

        void p2slot3() // parking 1 slot3
        {
        if( digitalRead(parking2_slot3_ir_s) == LOW)
        {
        sensor6 = “p2s3on”;
        delay(200);
        }
        if( digitalRead(parking2_slot3_ir_s) == HIGH)
        {
        sensor6 = “p2s3off”;
        delay(200);
        }
        }

        But I’m getting an error.

  2. bonjour je rencontre un problem au niveau de mon port serie

    Severity Code Description Project File Line Suppression State
    Error BC30451 ‘com5’ is not declared. It may be inaccessible due to its protection level. WindowsApp1 C:\Users\hp\source\repos\WindowsApp1\WindowsApp1\Form1.vb 10 Active

    svp besion d’aide. merci

  3. morning i have a problem witch my serial port. please I neet help

    Severity Code Description Project File Line Suppression State
    Error BC30451 ‘com5’ is not declared. It may be inaccessible due to its protection level. WindowsApp1 C:\Users\hp\source\repos\WindowsApp1\WindowsApp1\Form1.vb 10 Active

    thank’s

Leave a Reply

Your email address will not be published.

Back to top button