Site icon Circuit Ideas for You

Arduino Based Automatic Gate Opening and Closing Circuit

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:

Circuit Working:

Parts List:

ComponentValue Quantity
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:

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

Exit mobile version