Projects / Model boom gate

Model boom gate

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO59°

    Fit a light card boom to the servo

    Closed at 0 degrees.

  2. NANO

    Place the approach and exit sensors

    One before and one after the gate line.

  3. NANO59°15.3 mA

    Wire sensors, servo and LEDs

    D2, D3, D9, D7 and D8.

  4. NANO

    Upload and open the serial monitor at 9600

    It says Gate closed.

  5. NANO

    Roll a toy car to the approach sensor

    The gate opens.

  6. NANO

    Let the car pass under

    The gate stays open.

  7. NANO

    Wait after it leaves

    The gate closes.

In short

How do you build a model boom gate?

Two infrared sensors on either side of a toy car park gate tell a Nano when a car arrives and when it has gone, and a servo lifts and lowers the boom, with a red and green light. The gate stays up while a car is under it. A model only, not a real barrier. You need Arduino Nano, SG90 Micro Servo, IR obstacle avoidance sensor module × 2, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 80 minutes.

Level
Beginner
Time
About 80 min
Parts
8

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Approach sensor OUTNano D2Goes low when a car is in front of it
Exit sensor OUTNano D3Goes low when a car is past the gate
Both sensors VCC and GNDNano 5V and GNDSensor power
Servo signalNano D9Lifts the boom
Servo red and brownNano 5V and GNDServo power, a light card boom only
Red LED long legNano D7 through a 220 ohm resistor, short leg to GNDGate closed
Green LED long legNano D8 through a 220 ohm resistor, short leg to GNDGate open

Code

Two infrared obstacle modules act as the eyes of a toy car park gate. The approach sensor sits just before the gate and sees a car arriving, and the exit sensor sits just after it and sees the car leave. The module's output goes low when something is in front of it, so the sketch treats low as a car. When a car appears at the approach sensor the red light goes out, the boom lifts slowly and the green light comes on. The gate stays open while either sensor sees a car, and it closes only after both have been clear for one and a half seconds, so it can never come down on a car that is still passing under. Use a light card boom, and keep fingers clear while it moves. This is a classroom model of a barrier and a safety rule, and a real barrier needs proper safety sensors and a qualified installer. Try making a second car wait, or counting cars in and out.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Servo.h>

const uint8_t APPROACH_PIN = 2;
const uint8_t EXIT_PIN = 3;
const uint8_t RED_LED = 7;
const uint8_t GREEN_LED = 8;
const uint8_t SERVO_PIN = 9;

const int CLOSED_ANGLE = 0;
const int OPEN_ANGLE = 85;
const unsigned long CLEAR_DELAY = 1500;     // how long both sensors must be clear

Servo boom;
int angle = CLOSED_ANGLE;
bool gateOpen = false;
unsigned long clearSince = 0;

bool carThere(uint8_t pin) { return digitalRead(pin) == LOW; }   // module output is low when it sees something

void moveBoom(int target) {                  // slow, one degree at a time
  while (angle != target) {
    angle += (target > angle) ? 1 : -1;
    boom.write(angle);
    delay(15);
  }
}

void setup() {
  pinMode(APPROACH_PIN, INPUT);
  pinMode(EXIT_PIN, INPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  boom.attach(SERVO_PIN);
  boom.write(CLOSED_ANGLE);
  digitalWrite(RED_LED, HIGH);
  Serial.begin(9600);
  Serial.println("Gate closed.");
}

void loop() {
  bool car = carThere(APPROACH_PIN) || carThere(EXIT_PIN);
  if (car) clearSince = millis();            // a car is present, restart the clear timer

  if (!gateOpen && carThere(APPROACH_PIN)) {
    digitalWrite(RED_LED, LOW);
    moveBoom(OPEN_ANGLE);
    digitalWrite(GREEN_LED, HIGH);
    gateOpen = true;
    Serial.println("Gate open.");
  }
  if (gateOpen && !car && millis() - clearSince > CLEAR_DELAY) {
    digitalWrite(GREEN_LED, LOW);
    digitalWrite(RED_LED, HIGH);
    moveBoom(CLOSED_ANGLE);
    gateOpen = false;
    Serial.println("Gate closed.");
  }
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Gate closed.
Gate open.

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
No carRed light, gate closed
Car at the approach sensorBoom rises, green light
Car under the gateGate stays open
Car gone for 1.5 secondsGate closes, red light
Hand in front of a sensorCounts as a car

If it does not work

Gate never opens

Turn the sensor's small knob until its light shows a detection.

Gate opens at once

A sensor may see the table, adjust its range.

Gate closes on the car

Increase CLEAR_DELAY.

Servo twitches

Use a lighter boom.

Sensor light does not change

Check its 5V and GND wires.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the model boom gate?

Arduino Nano, SG90 Micro Servo, IR obstacle avoidance sensor module × 2, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the model boom gate take to build?

About 80 minutes for a beginner maker, in 7 steps.

How do I know the model boom gate works?

No car: Red light, gate closed. Car at the approach sensor: Boom rises, green light. Car under the gate: Gate stays open.

Gate never opens: what should I check?

Turn the sensor's small knob until its light shows a detection.

Gate opens at once: what should I check?

A sensor may see the table, adjust its range.

Gate closes on the car: what should I check?

Increase CLEAR_DELAY.

Servo twitches: what should I check?

Use a lighter boom.