Using a 4-line, 20-character LCD screen with an ARDUINO UNO board

Marc DANIEL

Well-Known Member
Licensed User


Learn more



Downloading B4R files:

English File


Fichier français



VIDEO


Parking6 - English Version:
'Parking6 - English Version - November 2023 Update - Marc DANIEL
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

' MANAGEMENT OF A PARKING MODEL OF 11 SPACES, 3 of which are FREE at the start of the program
 ' ARDUINO UNO R3 CARD + L293D Integrated Circuit + LCD screen (4 lines of 20 characters) and its I2C interface
' With an Arduino UNO board, the SDA pin of the I2C interface is connected to analog pin A4 and the SCL pin is connected to analog pin A5.
' If you use an Arduino MEGA 2560 board you will need To connect the SDA pin of the I2C interface To the SDA1 pin of the Arduino MEGA 2560 board And the SCL pin To the SCL1 pin

Sub Process_Globals
    Public Serial1 As Serial
    Private pinButtonEntree As Pin                    'pin for parking entry button
    Private pinButtonSortie As Pin                    'pin for parking exit button
    Private pinGreenLED, pinYellowLED, pinRedLED As Pin 'pins for LEDs
    Private PinBuzzer As Pin
    Private pinOpen, pinClose As Pin       'pins for barrier motorization connections
    Public GreenLED = False As Boolean
    Public Places As UInt
    Public Lock As Boolean
    Public Movement As Boolean
    Private LCD As LiquidCrystal_I2C         'Library "rLiquidCrystal_I2C" to load and use
    End Sub


Private Sub AppStart
    Serial1.Initialize(115200)
    pinButtonEntree.Initialize(pinButtonEntree.A0, pinButtonEntree.MODE_INPUT_PULLUP)   'Parking entry button
    pinButtonEntree.AddListener("pinButtonEntree_StateChanged")
    pinButtonSortie.Initialize(pinButtonSortie.A1, pinButtonSortie.MODE_INPUT_PULLUP)   'Parking exit button
    pinButtonSortie.AddListener("pinButtonSortie_StateChanged")
    pinGreenLED.Initialize(7, pinGreenLED.MODE_OUTPUT)                                    ' Green Lights
    pinYellowLED.Initialize(13,pinYellowLED.MODE_OUTPUT)                                    ' Yellow light
    pinRedLED.Initialize(9, pinRedLED.MODE_OUTPUT)                                    ' Red lights
    pinOpen.Initialize(4, pinOpen.MODE_OUTPUT) 'Connection to component L293D pin no. 2 or 1a or "IN1" for opening the barrier
    pinClose.Initialize(6, pinClose.MODE_OUTPUT)'Connection to component L293D pin no. 7 or 2a or "IN2" for closing the barrier
    PinBuzzer.Initialize(3,PinBuzzer.MODE_OUTPUT)                                        ' Buzzer
    'Analog pins A4 and A5 reserved for connecting the LCD display at address “0x27”
    LCD.Initialize(0x27, 20, 4) ' Initialization of the LCD screen with 4 lines of 20 characters
    Places=3 '3 parking spaces are available
    ' You can modify line 43 if you wish to change the number of places available at the start of the program
    Lock=False
    CallSubPlus("Departure", 0,0)
End Sub

Private Sub Departure
    pinGreenLED.DigitalWrite(True)   'lights the green LEDs at the start of the session or in the event of RESET on the ARDUINO UNO card (3 places remain defined on line 43)
    LCD.Backlight = True
    LCD.SetCursor(0,0)
    LCD.Write("  CENTRAL   PARKING  ")
    LCD.SetCursor(0,1)        'Place the cursor at the start of the second line of the LCD screen
    LCD.Write("   03 FREE PLACES  ")
    LCD.SetCursor(0,2)
    LCD.Write("       WELCOME   ")
End Sub

Private Sub pinButtonEntree_StateChanged(State1 As Boolean)
    Movement = True
    If State1 = False Then
        If Lock=False Then
            If Places > 0 Then
                pinGreenLED.DigitalWrite(True)  'lights up the green LEDs (there are places left)
                ' NB: The green LEDs will be lit by default at the start because there are 3 free places
                pinRedLED.DigitalWrite(False) 'turns off the Red LEDs (The parking lot is no longer full)
                Lock=True'Momentarily locks the use of the ENTER (or EXIT) button
                CallSubPlus("Buzzer",0,0)
                CallSubPlus("Opening",500,0) 'Opening the barrier
                LCD.SetCursor(0,3)
                LCD.Write(" INCOMING  VEHICLE ")
                CallSubPlus("Break",5150,0) 'Vehicle movement
                CallSubPlus("Closing", 10300, 0) ' Closing the barrier
                CallSubPlus("EndEntrance",14850,0) ' End of closing the barrier
                EndEntrance
                LCD.SetCursor(0,2)
                LCD.Write("                    ")
                CallSubPlus("Unlock",15300,0)
                Places = Places -1
                CallSubPlus("SpaceManagement",0,0)
           
            End If
        End If
    End If
End Sub

Private Sub pinButtonSortie_StateChanged(State2 As Boolean)
    Movement = False
    If State2 = False Then
        If Lock=False Then
            If Places <> 11  Then
                pinGreenLED.DigitalWrite(True)  'lights up the green LEDs (there are Places left)
                pinRedLED.DigitalWrite(False) 'turns off the Red LEDs
                Lock=True ' Momentarily blocks the use of the EXIT (or ENTER) button
                CallSubPlus("Opening",500,0)'Opening the barrier
                CallSubPlus("Break",5150,0)
                'Vehicle movement
                CallSubPlus("Closing", 10300, 0) ' Closing the barrier
                CallSubPlus("EndOfExit",14850,0) ' End of closing the barrier
                CallSubPlus("Unlock",15300,0)
            End If
            If Places < 11 Then Places = Places + 1
            CallSubPlus("SpaceManagement",0,0)
        End If
    End If
End Sub

Private Sub Buzzer(Tag As Byte)
    PinBuzzer.DigitalWrite(True)  'Activates the buzzer after pressing the Enter button
    Delay (500)
    PinBuzzer.DigitalWrite(False)  'Turn off the buzzer
End Sub

Private Sub Opening(Tag As Byte)
    pinOpen.DigitalWrite(True)'opens the barrier for entry or exit of a vehicle
    LCD.SetCursor(0,3)
    If Movement = True And Places > 0  Then  LCD.Write("  INCOMING VEHICLE  ")
    If Movement = False Then  LCD.Write("  EXITING  VEHICLE  ")
End Sub

Private Sub Break(Tag As Byte)
    pinOpen.DigitalWrite(False) 'Barrier remains open - Movement of vehicle entering or exiting
End Sub

Private Sub Closing(Tag As Byte)
    pinClose.DigitalWrite(True)    'closing the barrier
End Sub

Private Sub EndEntrance '(Tag As Byte)
    pinClose.DigitalWrite(False)   'Stop closing the barrier
        LCD.SetCursor(0,3)
        If Places > 0 Then LCD.Write("                    ")
End Sub

Private Sub EndOfExit(Tag As Byte)
    pinClose.DigitalWrite(False)    'Stop closing the barrier
        LCD.Write("                    ")
End Sub

Private Sub SpaceManagement(Tag As Byte)
    Select Places
        Case 0
            pinRedLED.DigitalWrite(True) 'Lights up the red LEDs (full parking lot 0 free space)
            pinGreenLED.DigitalWrite(False) 'turns off the Green LEDs
            pinYellowLED.DigitalWrite(False)  'turns off the yellow LED
            LCD.Clear
            LCD.SetCursor(0,0)
            LCD.Write("    FULL PARKING  ")
            LCD.SetCursor(3, 1)      
            LCD.Write(NumberFormat(Places, 1, 0))
            LCD.SetCursor(5,1)
            LCD.Write(" FREE PLACE ")
            LCD.SetCursor(0,2)
            LCD.Write("   Wait for a car ")
            LCD.SetCursor(0,3)
            LCD.Write("    to come out   ")
           
        Case 1
            pinGreenLED.DigitalWrite(True)  'Green LEDs on
            pinYellowLED.DigitalWrite(True)'There is only one place left, the yellow light comes on
            LCD.Clear
            LCD.SetCursor(0,0)
            LCD.Write("  CENTRAL PARKING  ")
            LCD.SetCursor(3,1)
            LCD.Write(NumberFormat(Places,2,0))
            LCD.SetCursor(5,1)
            LCD.Write(" FREE PLACE  ")
            LCD.SetCursor(0,2)
            LCD.Write("       WELCOME   ")
            LCD.SetCursor(0,3)
            LCD.Write("                    ")
           
        Case Else ' 2 to 11 free places
            pinRedLED.DigitalWrite(False) ' turns off the red LEDs
            pinYellowLED.DigitalWrite(False) ' turns off the yellow LED
            pinGreenLED.DigitalWrite(True)  ' lights up the green LEDs
            LCD.Clear
            LCD.SetCursor(0,0)
            LCD.Write("  CENTRAL PARKING  ")
            LCD.SetCursor(3,1)
            LCD.Write(NumberFormat(Places,2,0))
            LCD.SetCursor(5,1)
            LCD.Write(" FREE PLACES  ")
            LCD.SetCursor(0,2)
            LCD.Write("       WELCOME   ")
            LCD.SetCursor(0,3)
            LCD.Write("                    ")
           
       
    End Select
End Sub

Private Sub Unlock(Tag As Byte) ' Unlocks the ENTRANCE and EXIT buttons
    Lock=False
End Sub
 

Marc DANIEL

Well-Known Member
Licensed User
Emexes says: "Dare I ask what happens if both the entry and exit buttons are pressed simultaneously ?
eg if two cars have arrived at opposite sides of the boom gate at the same time"

LOL ... I tried but there is always one button that reacts before the other but it's a good question and I didn't foresee a helicopter landing in the parking lot either!
 
Last edited:

Marc DANIEL

Well-Known Member
Licensed User
Of course, you can DIY a small parking simulator with a breadboard, 3 LEDs and 2 buttons:

 

Marc DANIEL

Well-Known Member
Licensed User
It is desirable to create a better parking simulator by adding 2 other LEDs, a blue one which will be lit when a car enters and a white one which will be lit when a car exits


I slightly modified the B4R program by adding a few lines to light the blue LED during inputs and the white LED during outputs, otherwise the program is exactly the same as above...

 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…