Toy car barrier gate

A toy car drives under an IR sensor, the green LED comes on and a servo swings the barrier open. Two seconds after the car has gone the barrier closes and the red LED returns.

  • 7 parts
  • 6 wiring steps
  • Arduino code
  • 5 V supply

Quick answer

The short version. Every pin is in the full wiring below.

What you need

  • 5 V 2 A power supply
  • Arduino Nano
  • IR obstacle module
  • SG90 servo
  • 5 mm red LED and 5 mm green LED
  • 330 ohm resistor, two of them, one for each LED
  • 470 uF electrolytic capacitor across the 5 V supply next to the servo leads

How to wire it

  1. Supply plus to the Nano's 5V pin, the IR module's VCC, the servo's red lead and the plus of the 470 uF capacitor.
  2. Supply minus to the Nano's GND, the IR module's GND, the servo's brown lead, the capacitor's minus and both LED cathodes.
  3. IR module OUT to D2.
  4. D5 through a 330 ohm resistor to the red LED anode.
  5. D4 through a 330 ohm resistor to the green LED anode.
  6. D9 to the servo's orange signal lead.

Before you power it: All 5 V, with a peak of about 0.7 A from a 2 A supply. Keep fingers clear of the barrier arm while the servo moves.

An Arduino Nano with a red and a green LED on 330 ohm resistors, a 470 microfarad capacitor, a 5 V 2 A supply, an IR obstacle module over a road, an SG90 servo with a red and white striped barrier arm, and a red toy car driving past
The circuit as wired in the Short. Every wire end is a real pin; the netlist was checked before the video went out.

Parts list

  • 5 V 2 A power supply
  • Arduino Nano
  • IR obstacle module (LM393 type, output active low, 3.3 to 5 V)
  • SG90 servo, with a striped barrier arm on its horn
  • 5 mm red LED and 5 mm green LED
  • 330 ohm resistor, two of them, one for each LED
  • 470 uF electrolytic capacitor across the 5 V supply next to the servo leads

Wiring, step by step

  1. Supply plus to the Nano's 5V pin, the IR module's VCC, the servo's red lead and the plus of the 470 uF capacitor.
  2. Supply minus to the Nano's GND, the IR module's GND, the servo's brown lead, the capacitor's minus and both LED cathodes.
  3. IR module OUT to D2.
  4. D5 through a 330 ohm resistor to the red LED anode.
  5. D4 through a 330 ohm resistor to the green LED anode.
  6. D9 to the servo's orange signal lead.

How it works

  1. The IR module's output goes low when something is under it. The Nano reads it on D2.
  2. With nothing there the red LED is on and the servo holds the barrier closed at 90 degrees.
  3. When the car is seen, the sketch turns the red LED off and the green LED on, and sweeps the servo from 90 to 0 degrees. It turns 3 degrees every 10 ms, so a full open or close takes 0.3 s.
  4. The barrier stays open until the sensor has not seen the car for 2 s. Then the green LED goes off, the red LED comes on and the servo sweeps back to 90 degrees.

The code: barrier_gate.ino

The Arduino code for this circuit is in the Wirecora Discord, in the channel #arduino-code (owner’s choice, 14 October 2026: the code lives where you can ask about it). It is a plain .ino file you can download there.

From the Short's own checked drawing; it needs only the Servo library that comes with the Arduino software. It was checked by simulation and matches the video's timing, but it was not run on a real board.

Get the code in #arduino-code

What the video simplifies

  • This is a model-scale barrier: the IR module senses about 2 to 30 cm.
  • The servo is drawn from the side while the boom swings flat in the picture, like a top-down view. In a real build the boom is fixed to the servo horn.
  • The car speed, LED glow, sparkles, road and all sounds are added for the video.
  • We assumed the usual 10 kohm pull-up inside the IR module and which small on-board LED is its obstacle LED. The servo currents (peak about 0.7 A) are typical values, not datasheet figures. The 470 uF capacitor only smooths servo noise a little; it does not replace thick supply wires.
  • The original viral circuit used an ATtiny85 and one resistor shared by both LEDs. This version uses an Arduino Nano and one resistor per LED.
  • This was checked by simulation and datasheets, not built.

You found this by searching. Here's the whole path.

  1. Read how it works
  2. See it work
  3. Build it
  4. Show it
Next: see it work

Thirty seconds of video shows the circuit doing its job.

Then build it

All 5 V, with a peak of about 0.7 A from a 2 A supply. Keep fingers clear of the barrier arm while the servo moves.

Then show it

Built it, or stuck halfway? Post a photo in the Wirecora Discord. Questions get an answer every day.