11. Case 02: Smart Car park Access Barrier

Level: level auto_fit

11.1. Goal


Make a smart car park gate which opens automatically if there are vacancies in the car park and there are cars coming in.

11.2. Background


What is smart car park access barrier?

Smart Car park Access Barrier is used to allow people to live conveniently. It can reduce manpower and time in controlling the gate and manage information (e.g. car park vacancies). It will be opened automatically if there are vacancies in the car park and there are cars coming in.

Car park gate operation

The car park gate open and close operation is controlled by 180ᵒ servo. It will be opened if there are vacancies in the car park (i.e. detected by light sensor) and cars near the car park gate (i.e. detected by distance sensor). Otherwise, the gate will be closed.

When there are no vacancies (detected by light sensor), then the gate will keep closed.

pic_70

11.3. Part List


auto_fit

11.4. Assembly step


Step 1

Attach the distance sensor to B1 model with M4 * 10mm screws and nuts.

auto_fit

Step 2

Attach the servo to B1 model with M2 * 10mm screws and nuts

auto_fit

Step 3

Attach the B2 model to the servo with servo M2 * 7.5mm sharp screw. Put B3 model onto B1 model.

auto_fit

Step 4

Assembly completed!

pic_60

11.5. Hardware connect


Connect the Distance Sensor to P14 (trig)/ P15 (echo) port of IoT:bit

Connect Light Sensor to P0 port of IoT:bit

Connect 180° Servo to P2 port of IoT:bit

auto_fit

11.6. Programming (MakeCode)


Step 1. Set variables and servo at start position

  • Inside on start, snap set variable distance to 0 and set light to 0 from variables. Snap Turn Servo to 0 degree at P2. pic_50

Step 2. Get distance and light value

  • Drag get distance to get distance unit cm trig P14 echo P15, store the value to variable distance.

  • Get light value (percentage) at Pin P0, store the value to variable light pic_90

Step 3. Open/close gate with light value

  • Snap if statement into forever, set if variable distance ≤ 5

  • Snap another if statement set variable light value >20 pic_90

Step 4. Set servo position

  • Snap Turn Servo to 90 degree at P2 as the gate is opened.

  • Snap pause to the loop to wait 5 seconds

  • Snap Turn Servo to 0 degree at P2 as the gate is closed. pic_90

Full Solution

MakeCode: https://makecode.microbit.org/_UgRKmX2XzH2u

You could also download the program from the following website:

11.7. Result


The light sensor is used to check the vacancies in the car park while the distance sensor is used to detect if there are any cars coming near the car park gate

The car park gate is controlled by 180ᵒ servo. When there are vacancies in the car park and there are cars near the car park gate, the car park is available. The gate will be opened for 5 seconds and then closed to let the car entering the car park.

auto_fit

11.8. Think


Q1. How can you show the light and distance value on OLED?

Q2. Can you show signals on micro:bit LED to let drivers know there are vacancies in the car park?