• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Circuit Ideas for You

Get free circuit ideas online.

  • Home
  • Privacy Policy
  • About
Home » Arduino Based Automatic Gate Opening and Closing Circuit

Arduino Based Automatic Gate Opening and Closing Circuit

Last updated on 7 September 2025 by Admin-Lavi Leave a Comment

This project is for Arduino Based Automatic Gate Opening and Closing Circuit.

This system uses Arduino UNO, Ultrasonic sensor, NPN transistor, Servo motor, LCD display ,12V battery and few resistors.

When someone comes in front of the gate the ultrasonic sensor detect distance and send signal to Arduino.

Arduino then control motor to open or close the gate.

This system is useful for small automatic door, toy gates model houses and learning automation.

Circuit Coding:

Circuit Coding

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int trigPin = 9;
const int echoPin = 10;
const int motorPin = 8;
long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorPin, OUTPUT);
lcd.begin(16,2);
lcd.print("Gate System Ready");
delay(2000);
lcd.clear();
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;

if(distance < 20) {
digitalWrite(motorPin, HIGH);
lcd.setCursor(0,0);
lcd.print("Gate Opening");
delay(3000);
digitalWrite(motorPin, LOW);
lcd.clear();
lcd.print("Gate Closed");
delay(2000);
}
else {
digitalWrite(motorPin, LOW);
lcd.setCursor(0,0);
lcd.print("Waiting...");
myservo.attach(6);
}
}

Code Explanation:

  • First LCD library is added and pins are defined.
  • In this design, LCD is started and pins are set.
  • In loop ultrasonic sensor measure distance using pulseIn function.
  • Distance is calculated with formula distance = (time x speed of sound) / 2.
  • If distance is less than 20 cm then motor pin become HIGH so motor run and gate open.
  • After delay motor stops and LCD show different messages.

Circuit Working:

Arduino Based Automatic Gate Opening and Closing Circuit Diagram

Parts List:

ComponentValueQuantity
Resistors1k 1/4 watt1
220Ω 1/4 watt1
Potentiometer 10k1
SemiconductorsArduino UNO1
LCD Module 16×2 Display1
HC-SR04 Ultrasonic Sensor Module1
DC Servo Motor1
Transistor TIP122 NPN1
Battery 12V lead acid1

The 12V battery gives power to the DC motor through the TIP122 transistor.

The same battery can also power the Arduino UNO through its Vin pin 7 to 12V input range.

The grounds of Arduino and battery are connected together.

The ultrasonic sensor send ultrasonic sound and receive echo back.

Arduino calculate distance from object.

If distance is less than fixed value like 20 cm then Arduino send HIGH signal to transistor base.

This drive the motor and opens the gate.

After some delay the Arduino stop motor and gate closes.

LCD display show message like “Gate Open” and “Gate Close”.

1k resistor R2 is for pull-up or pull-down resistor which is for current limiting for small signals.

220Ω resistor R1 is for Current limiting for LEDs.

VR1 adjust voltage to an analog input pin 0 to 5V and it control brightness, motor speed or servo position.

Formulas:

Below is the formula for Arduino Based Automatic Gate Opening and Closing Circuit.

Formula for distance: distance = (time * speed of sound) / 2

Speed of sound in air = 0.034 cm per microsecond.

Example: if echo time = 1200 microseconds

distance = 1200 * 0.034 / 2 = 20.4 cm

So Arduino decide if object is closer than 20 cm.

How to Build:

To build a Arduino Based Automatic Gate Opening and Closing Circuit follow the below steps for connections:

  • Collect all parts as shown in circuit diagram.
  • Connect ultrasonic sensor like VCC to 5V of Arduino, GND to GND of Arduino, Trig to pin 9 and Echo to pin 10.
  • Connect LCD display to Arduino pins like RS to pin 12, EN to pin 11, D4 to pin 5, D5 to pin 4, D6 to pin 3, D7 to pin 2.
  • Potentiometer first pin connect to VCC (+5V), Middle pin to VEE(contrast) of LCD and Third pin to VSS pin on LCD.
  • Servo Motor Red pins connects to 5V of Arduino, Brown/Black pin connects to GND of Arduino and Orange/Yellow pin to Arduino pin 6.
  • Emitter of transistor goes to GND and base of transistor go to Arduino pin D8 with 1k resistor.
  • Battery positive goes to servo motor positive and battery negative go to transistor emitter and Arduino GND.
  • And transistor collector go to motor negative.
  • One side of 220Ω resistor go to Arduino +5V and other side go to LCD LED+.

Conclusion:

This article shows how to build Arduino Based Automatic Gate Opening and Closing Circuit.

It uses distance measurement to control motor.

Gate open and close happen automatically.

LCD display make system easy to use.

Project can improve with motor driver IC, limit switch or remote control.

References:

Design and Construction of an Automatic Gate

Filed Under: Arduino Projects, Sensors and Detectors

About Admin-Lavi

Lavi is a B.Tech electronics engineer with a passion for designing new electronic circuits. Do you have questions regarding the circuit diagrams presented on this blog? Feel free to comment and solve your queries with quick replies

Previous Post: « POV Project with LEDs and Arduino Circuit
Next Post: Arduino Based Obstacle Avoidance Robot Circuit »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar




Categories

  • Alarm Circuits (33)
  • Amplifier Circuits (67)
  • Arduino Projects (36)
  • Audio Circuits (94)
  • Automobile Circuits (19)
  • Battery Charger Circuits (48)
  • Free Energy (13)
  • Heater and Temperature Controllers (10)
  • High Voltage (1)
  • Indicator Circuits (38)
  • Inverter Circuits (13)
  • LDR Circuits (15)
  • LED and Lamps (116)
  • Meters and Testers (28)
  • Motor Controllers (18)
  • Oscillator Circuits (34)
  • Power Supply Circuits (92)
  • Remote Control Circuits (6)
  • Security and Protection (25)
  • Sensors and Detectors (84)
  • Solar Circuits (17)
  • Timer Circuits (30)
  • Transistor Circuits (57)
  • Transmitter Circuit (12)
  • Tutorials (5)
  • Water Level Controller (4)

Recent Posts

  • Sound Sensor Circuit using IC LM393
  • Sound Sensor Direction Circuit using Arduino
  • Dancing Water Fountain Circuit with Arduino
  • Arduino Based Obstacle Avoidance Robot Circuit
  • Arduino Based Automatic Gate Opening and Closing Circuit

Recent Comments

  1. Admin-Lavi on Constant Voltage, Constant Current Battery Charger Circuit
  2. Bill on Constant Voltage, Constant Current Battery Charger Circuit
  3. Admin-Lavi on Long Range FM Transmitter Circuit (2km)
  4. Sina on Long Range FM Transmitter Circuit (2km)
  5. Admin-Lavi on Long Range FM Transmitter Circuit (2km)

Copyright © 2025 | New Circuit Ideas