AUTOMATIC GATE USING ULTRASONIC SENSOR AND DC MOTOR
by DESHBOT in Circuits > Arduino
11 Views, 0 Favorites, 0 Comments
AUTOMATIC GATE USING ULTRASONIC SENSOR AND DC MOTOR
The Automatic Gate project is an Arduino-based system that automatically opens and closes a gate when an object is detected nearby.
An HC-SR04 ultrasonic sensor is used to measure the distance of an approaching object. When the object comes within 20 cm, the Arduino activates the motor and opens the gate.
The gate remains open for 3 seconds and then the motor rotates in the opposite direction to return the gate to its original position.
An LED indicates that the gate is currently open.
Downloads
Supplies
Components Required
ComponentQuantity
Deshboot shield
Arduino Uno/Nano
HC-SR04 Ultrasonic Sensor
DC Motor
Pin Connections
Ultrasonic Sensor
Sensor PinArduino
TRIG - A3
ECHO - A4
VCC - 5V
GND - GND
Motor Driver
Motor DriverArduino
Motor Input A - D6
Motor Input B - D7
The DC motor is connected to the motor driver's motor output terminals.
Important: The motor should use a suitable external power supply through the motor driver, and the Arduino GND and motor-driver GND should be connected together.
LED
LEDArduino
Positive - D11
Negative - GND through suitable resistor
Working Principle
The system works in the following sequence:
- The ultrasonic sensor continuously measures distance.
- The Arduino checks whether an object is within 20 cm.
- If an object is detected, the motor rotates in the opening direction.
- The motor runs for 1.5 seconds.
- The motor stops and the LED turns ON.
- The gate remains open for 3 seconds.
- The motor rotates in the opposite direction.
- The gate returns to its original position.
- The motor stops and the LED turns OFF.
- The system waits until the object moves away before detecting another object.
Distance Measurement
The ultrasonic sensor sends a sound pulse and measures the time required for the echo to return.
The program calculates the distance using:
The system is configured to detect objects up to:
20 cm
Gate Opening
When an object is detected, the gateOpen() function is called.
This makes the motor rotate in one direction.
The motor runs for:
1500 milliseconds = 1.5 seconds
After that, both motor outputs are turned OFF.
Gate Open Indicator
While the gate is open, the LED is turned ON:
This provides a visual indication that the gate is in the open position.
Gate Closing
After the gate remains open for 3 seconds, the gateClose() function is called.
The motor direction is reversed:
The motor runs for another 1.5 seconds and then stops.
The LED is turned OFF after the gate closes.
. Object Detection Lock
After closing the gate, the Arduino waits until the detected object moves away.
This prevents the gate from repeatedly opening and closing while an object is still in front of the sensor.
Serial Monitor
The Arduino also sends the measured distance to the Serial Monitor.
Example:
When the distance becomes 20 cm or less, the gate-opening sequence starts.
Conclusion
The Automatic Gate project demonstrates how an Arduino can combine an ultrasonic sensor, motor driver, DC motor and LED to create an automated system.
The ultrasonic sensor detects an approaching object, while the Arduino controls the motor to open and close the gate automatically. The LED provides a simple indication of the gate status.
This project demonstrates important embedded-system concepts including distance sensing, motor control, conditional logic, timing and automation.