PLC Project for Car Parking System: Design and Code Example
A
PLC project for a car parking system controls entry and exit gates using sensors and counters to track available parking spots. The program uses inputs for sensors and buttons, outputs for gate motors and indicators, and counters to manage parking space availability.Syntax
The basic syntax for a PLC car parking system involves defining inputs (like entry sensor, exit sensor, and push buttons), outputs (gate motors, indicator lights), and counters to track the number of cars inside.
Typical elements include:
Inputs:Sensors and buttons (e.g., EntrySensor, ExitSensor)Outputs:Gate control signals (e.g., OpenGate, CloseGate), indicator lightsCounters:To count cars entering and leavingLogic:Conditions to open/close gates based on sensor signals and counter values
structured_text
(* Define Inputs *) EntrySensor : BOOL; (* Sensor at entry gate *) ExitSensor : BOOL; (* Sensor at exit gate *) CarLimit : INT := 50; (* Maximum parking capacity *) (* Define Outputs *) OpenEntryGate : BOOL; (* Output to open entry gate *) OpenExitGate : BOOL; (* Output to open exit gate *) (* Define Counters *) CarCount : INT := 0; (* Current number of cars inside *)
Example
This example shows a simple PLC program in Structured Text that controls a car parking system. It opens the entry gate if there is space and a car is detected, increments the car count, and opens the exit gate when a car leaves, decrementing the count.
structured_text
(* PLC Program for Car Parking System *) VAR EntrySensor : BOOL; (* Input: Car detected at entry *) ExitSensor : BOOL; (* Input: Car detected at exit *) OpenEntryGate : BOOL := FALSE; (* Output: Open entry gate *) OpenExitGate : BOOL := FALSE; (* Output: Open exit gate *) CarCount : INT := 0; (* Number of cars inside *) CarLimit : INT := 50; (* Max parking spots *) EntryPrev : BOOL := FALSE; (* Previous state of EntrySensor *) ExitPrev : BOOL := FALSE; (* Previous state of ExitSensor *) END_VAR (* Detect rising edge for EntrySensor *) IF EntrySensor AND NOT EntryPrev THEN IF CarCount < CarLimit THEN OpenEntryGate := TRUE; (* Open gate to let car in *) CarCount := CarCount + 1; (* Increment car count *) ELSE OpenEntryGate := FALSE; (* Parking full, do not open gate *) END_IF; ELSE OpenEntryGate := FALSE; (* Close gate otherwise *) END_IF; EntryPrev := EntrySensor; (* Detect rising edge for ExitSensor *) IF ExitSensor AND NOT ExitPrev THEN IF CarCount > 0 THEN OpenExitGate := TRUE; (* Open gate to let car out *) CarCount := CarCount - 1; (* Decrement car count *) ELSE OpenExitGate := FALSE; (* No cars inside, keep gate closed *) END_IF; ELSE OpenExitGate := FALSE; (* Close gate otherwise *) END_IF; ExitPrev := ExitSensor;
Output
When a car arrives at the entry sensor and parking is not full, the entry gate opens and car count increases by 1. When a car arrives at the exit sensor and there is at least one car inside, the exit gate opens and car count decreases by 1.
Common Pitfalls
- Not handling sensor signal edges: Without detecting rising edges, the gate may open repeatedly or stay open.
- Ignoring parking capacity: Failing to check if parking is full can cause overcounting and unsafe conditions.
- Incorrect counter updates: Incrementing or decrementing counters incorrectly leads to wrong car counts.
- Gate control timing: Not closing gates after opening can cause security issues.
structured_text
(* Wrong: Using level detection instead of edge detection *) IF EntrySensor THEN OpenEntryGate := TRUE; (* Gate stays open as long as sensor is active *) CarCount := CarCount + 1; (* Car count increments continuously, wrong *) END_IF; (* Correct: Use rising edge detection *) IF EntrySensor AND NOT EntryPrev THEN OpenEntryGate := TRUE; CarCount := CarCount + 1; END_IF;
Quick Reference
Remember these key points for your PLC car parking project:
- Use rising edge detection on sensors to detect car arrivals and departures.
- Maintain a car count variable to track occupancy.
- Check parking capacity before allowing entry.
- Control gate outputs to open only briefly when a car is detected.
- Reset previous sensor states each cycle to detect edges correctly.
Key Takeaways
Use sensor rising edge detection to accurately detect car arrivals and departures.
Maintain and update a car count to track parking occupancy safely.
Check parking capacity before opening the entry gate to prevent overflow.
Control gate outputs to open only when needed and close promptly.
Test your PLC logic with real sensor signals to avoid counting errors.