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 and 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 and then Arduino control motor to open or close the gate.

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

Arduino Code:

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:

Arduino Based Automatic Gate Opening and Closing Circuit Diagram

Parts List:

ComponentsValuesQuantity
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 and the same battery can also power the Arduino UNO through its Vin pin 7 to 12V input range.

Connect the Arduino and battery grounds together, the ultrasonic sensor then transmits ultrasonic sound waves and receives the reflected echo.

After that, Arduino calculate distance from object and if distance is less than fixed value like 20 cm then Arduino send HIGH signal to transistor base, hence, this drive the motor and opens the gate.

After some delay the Arduino stop motor and gate closes and then LCD display show message like “Gate Open” and “Gate Close”.

Here, 1k resistor R2 is for pull-up or pull-down resistor which is for current limiting for small signals and 220Ω resistor R1 is for Current limiting for LEDs.

Finally, 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:

Overall, this article shows how to build Arduino Based Automatic Gate Opening and Closing Circuit, it uses distance measurement to control motor.

Also, gate open and close happen automatically and then LCD display make system easy to use; Furthermore, this project can improve with motor driver IC, limit switch or remote control.

Exit mobile version