How To Design An Arduino Based Automatic Gate Controller

Today, many gate doors are opened by an automated gate operator. Those gates come with many special features. The need for automatic gates has been on the increase in recent times. In this tutorial, we are going to build an automatic gate controller to easily open a model gate which we designed using DIY kit when a model car approaches its front and then let it close after it once the model vehicle has passed.

Automatic gate controller
Automatic gate controller

The theory of the automatic gate is very simple, when we press the open button, a signal is sent to the main circuitry board which then allows the current to pass through to the gates motor causing the motor to run and the gate open. Once the gate is fully open (depending on where the resistant beam is located) the motor stops running causing the gate to stop moving. When the close button is pressed the same thing happens but this time the motor run in the opposite direction, therefore causing the gate to close.

Why Automatic Gate Controllers Are Needed

The gates in the University where this project was designed are operated manually and do take time for the security personnel to open them due to some form of security checks. Nowadays, to open or close the gate people need to step outside from the car or house to open it. It just wastes time. So, they prefer the automatic gate system because it can save time and energy. They just need to push the control remote while in the car to open the gate. The problem with this system is he cost and how to install this part of the gate. The cost includes cost of installation and maintenance and as a result of this we rarely see people use this kind of gate probably because the cost to install this system is high.

A gate man doing manual gate opening
A gate man doing manual gate opening

In order to eliminate human effort in doing the work, the automatic gate controlled system is designed. This can also act as some form of security measure too because the gate will just open for anybody if the microcontroller did not read the code attached to the number plate of a car and there will be a separate route for outsiders to eliminate the wastage of time for members of staff that have their cars configured for the gate.

In the past, many systems that are designed by man are normally operated manually. This mode of operation is accompanied with many defects or disadvantages. Some of the disadvantages involve stress undergone by the operator; the operator is also exposed to health hazards when carrying out his or her duties. These health hazards might be in form of electrocution, skin burn or bruises. To overcome the above mentioned disadvantages that are associated with manual operation of systems, the recent systems are designed with mechanisms that enable them to carry out the required operations automatically.

Components/Materials Needed for The Arduino Based Automatic Gate Controller

In designing this project, our goal was to design a programmable circuit structure with high degree of performance in terms of detecting obstacles utilizing the principle of bodies in motion emitting Infrared Radiation, and using this to control the opening and closing positions of a gating system automatically.  The design was meant to  use two IR 2-30cm Obstacle detection sensor modules FC-51,  to detect two important scenarios viz; when there is a car outside the gate and when the car has pass through the gate and responds to these by giving commands which opens and closes the gate, with addition of natural display of the results on an LCD screen. This chapter explains the materials and the techniques adopted in designing the system.

The block diagram of the design
The block diagram of the design

The Hardware Design consists of:

  • Microcontroller development board like Arduino or its standalone
  • Stepper motor
  • passive Components
  • Power Supply Unit
  • Sensors
  • Flexible wire
CategoryQuantityReferences 
Capacitors1C1 
Resistors4R2,R16-R18 
Integrated Circuits4U2-U5 
Miscellaneous8COL1-COL4,ROW1-ROW4 
Miscellaneous1CON1 
CATEGORYQUANTITYREFERENCESVALUE
Capacitors4C1-C422p
Capacitors2C5-C61000U
Capacitors1C7100n
Resistors5R1,R3,R9,R20-R2110k
Resistors1R21R
Resistors2R4,R1847k
Resistors3R5-R6,R121k
Resistors4R7,R16-R17,R194k7
Resistors3R8,R10-R11390
Resistors3R13-R151k
Integrated Circuits2U1,U3PIC18F4520
Integrated Circuits1U2LM1117T-3,3
Integrated Circuits1U524C64C
Integrated Circuits1U107805
Transistors1Q1TIP42
Transistors2Q2-Q32N2222
Diodes1D1COMM-LED
Diodes2D2-D3LED-RED
Diodes1D41N5400
Diodes1D5PWR-LED
Diodes1D61N4007
Miscellaneous112V ADAPTORTBLOCK-I2
Miscellaneous3BOARD1-BOARD3CONN-SIL12
Miscellaneous2DOWN,UPCONN-SIL6
Miscellaneous2X1-X220MHz
The Bill of Materials (BOM)

The Software Design

Arduino IDE

The software part used for this project includes; circuit diagrams and stimulation developed and simulated with Proteus, an electronic design and simulation software. The software for the microcontroller, motor driver and LCD display module was done with Arduino integrated development environment (IDE).

The Schematic Diagram

Automatic gate controller circuit diagram
Automatic gate controller circuit diagram

Explanation of The Automatic Gate Controller Circuit Diagram

The liquid crystal display is a display module programmable, economical and can display special characters. A 16×2 LCD means it can display 16 characters per line and there are two of such lines. Each character is displayed in 5×7 pixel matrix. The LCD has two registers namely; Command and Data. The pins and their functions are explained as:

Register Select (RS): this pin(pin 4) of the LCD selects Command register when low and Data register when high; this is connected to pin 12 of the microcontroller. Read/Write (R/W): this pin writes to the register when low and reads from the register when high. And this pin is connected to pin 5 of the microcontroller. Enable (E): this pin sends data to the Data pins when a high to low pulse is given to it. This is connected to the pin 11 of the microcontroller. Pin 7 to 14 (D4 to D): these are 8-bit pins that are used to send and receive data to/from the LCD. Pin 15: this is the positive (+Vcc) backlight of the LED (LED+) of the LCD. This pin is usually connected with a pull-up resistor ( ≤ 1kΩ). this is important to limit current flowing in the LEDs of the LCD. Pin 16 (D16): this is the negative (ground ) −Vcc  pin. It is connected to the ground of the DC power supply.

Read Android Platform Based Temperature Monitoring Design for Poultry Farms

Automatic gate controller linear power supply circuit diagram
Automatic gate controller linear power supply circuit diagram

In order to convert 220V – 240V AC to a 5V DC, first we need a step-down transformer to reduce such high voltage. Here we have a step-down transformer, which converts 220V AC to 12V AC. In a transformer, there are primary and secondary coils which step up or step down the voltage according to the number of turns in the each of the coils.

Selection of a proper transformer is very important. Current rating depends upon the Current requirement of Load circuit. This choice was made because the voltage rating should be more than the required voltage. Since we needed a 5V DC output supply, and the transformer with a rating of 12V was ideal.  Because during voltage regulation, our voltage regulator IC need more voltage to operate. For example, L7805 needs at least need 2V more that’s 7V to provide a 5V voltage.

Programming the Project Design

/* Program to monitor and control the opening and closing of a 
  gate using IR module
*/

//include the lcd lib
#include <LiquidCrystal.h>

//state what pins you are using for d LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//state the motor driving pins
int forward = 10;
int reverse = 13;

int switchSense1 = 6;
int switchSense2 = 7;

int IRsense1 = 8;
 int IRsense2 = 9;
 
void setup() {
   //begin the LCD
 lcd.begin(16, 2);
 //make the IO
  pinMode(forward, OUTPUT);
 pinMode(reverse, OUTPUT);
 pinMode(IRsense1, INPUT);
 pinMode(IRsense2, INPUT);
 pinMode(switchSense1, INPUT);
 pinMode(switchSense2, INPUT);

//print a welcome note:
//set the lcd cursor
lcd.setCursor(0,0);
lcd.print("WELCOME EBOSE");
delay(1500);
lcd.setCursor(0, 1);
lcd.print("IR OBSTACLE");
delay(500);
lcd.setCursor(0, 0);
lcd.print("IR OBSTACLE");
delay(500);
lcd.setCursor(0, 1);
lcd.print(" SENSING GATE ");
lcd.setCursor(0, 0);
lcd.print(" SENSING GATE ");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("OPENING PROJECT");
delay(2000);
lcd.clear();
}

void loop() {
  int detect1 = digitalRead(IRsense1);
   int detect2 = digitalRead(IRsense2);
   int switch1 = digitalRead(switchSense1);
   int switch2 = digitalRead(switchSense2);
   
 
  if( switch2 == LOW) {
   if (detect1 == LOW){ 
     digitalWrite(reverse, HIGH);
    digitalWrite(forward, LOW);
    delay(300);
    lcd.setCursor(0, 0);
    lcd.print("GATE STATUS:    ");
    lcd.setCursor(0, 1);
    lcd.print("  OPENED   ");
   }
   }
    else if(switch2 == HIGH){
      
    if (detect1 == LOW || detect1 == HIGH){
    digitalWrite(reverse, LOW);
    digitalWrite(forward, LOW);
    
    }
     
   }
   
   

if( switch1 == LOW ) {
if(detect2 == LOW && detect1 == HIGH)
{
    digitalWrite(reverse, LOW);
    digitalWrite(forward, HIGH);
    delay(300);
    lcd.setCursor(0, 0);
    lcd.print("GATE STATUS:    ");
    lcd.setCursor(0, 1);
    lcd.print("  CLOSED   ");
    
    
  }
}
else if(switch1 == HIGH){
  if(detect2 == HIGH && detect1 == HIGH) {
  digitalWrite(forward, LOW);
  delay(300);
    lcd.setCursor(0, 0);
    lcd.print("GATE STATUS:    ");
    lcd.setCursor(0, 1);
    lcd.print("  CLOSED   ");
    
}

} 
}

Explanation of Arduino Code

screenshot of source code
screenshot of source code

This Arduino code is designed to monitor and control the opening and closing of a gate using an IR (Infrared) sensor module and a motor. The code begins by including the necessary library for controlling an LCD display and defining the pins used for both the LCD and the motor. The LCD is connected using pins 12, 11, 5, 4, 3, and 2, while the motor driving pins are assigned to pin 10 for forward movement and pin 13 for reverse movement. The code also sets up the pins for the IR sensors and switch sensors, which are used to detect the presence of obstacles and the gate’s position, respectively.

In the setup() function, the LCD is initialized and a welcome message is displayed, followed by information about the IR obstacle sensing and gate opening project. This sequence of messages provides feedback to the user, indicating that the system is operational. The function also configures the motor and sensor pins as inputs or outputs as needed. The loop continuously monitors the state of the IR sensors and switch sensors, controlling the gate’s movement based on the inputs received from these sensors.

In the loop() function, the program first reads the state of the IR sensors and switch sensors. If the second switch sensor (switch2) is LOW and the first IR sensor (detect1) detects an obstacle (LOW state), the gate opens by driving the motor in reverse. If no obstacle is detected, the motor stops. Conversely, if the first switch sensor (switch1) is LOW and the second IR sensor (detect2) detects an obstacle, the gate closes by driving the motor forward. The LCD updates to show the current status of the gate, either “OPENED” or “CLOSED,” providing real-time feedback to the user. The code effectively ensures the gate opens or closes automatically based on the sensor inputs, maintaining a safe and controlled environment.

Testing and Implementation of the Arduino Automatic Gate Controller Project

The results of the automatic gate controller project
The results of the automatic gate controller project

The analysis of the automatic gate was carried out using a motor. The electronic device was to function under the operating 5V power conditions and cut-off power when a higher voltage is supplied to the system. The sensor used in this system is to detect motion of a vehicle coming into the compound; it has a transmitter and a receiver end. In this project, the transmitter section includes an IR sensor, which transmits continuous IR rays to be received by an IR receiver module. An IR output terminal of the receiver varies depending upon its receiving of IR rays. An LCD display is programmed to monitor the levels of entry i.e. whether a vehicle has been detected or not and to show it on display.

When the system is turned on, a message describing the project is shown on the LCD screen; the condition at that moment in which the sensor obviously isn’t in use at that time is also indicated on the LCD. When the IR receiver does not receive a signal, the potential at the inverting input goes higher than that non-inverting input of the comparator IC (LM339). Thus the output of the comparator goes low, but the LED does not glow.

Testing the result

This prototype system has been tested, implemented and evaluated to be a very reliable method of solving the problem of gate opening and closing and can be further applied for both domestic and industrial utilization.

Limitation of the Automatic Gate Controller Project Design

The limitations of this Arduino-based gate control project include the following:

  1. Dependence on Sensor Accuracy: The accuracy of the gate’s operation depends heavily on the proper functioning of the IR sensors and switch sensors. Any malfunction or misalignment in the sensors could lead to incorrect gate behavior, such as failing to open or close at the appropriate times.
  2. Limited Obstacle Detection Range: The IR sensors used in the project typically have a limited detection range, which may not be sufficient for larger gates or longer distances. This could result in the system failing to detect obstacles that are further away, leading to potential safety risks.
  3. Environmental Interference: IR sensors can be affected by environmental factors such as sunlight, dust, and rain. These conditions may cause false readings or reduced accuracy, leading to improper gate operation, such as unnecessary openings or closings.
  4. Single Point of Detection: The project relies on only two IR sensors to detect obstacles. This single-point detection approach may not cover the entire area around the gate, potentially missing objects that are not directly in front of the sensors.
  5. Limited Feedback and Control: While the LCD provides basic feedback on the gate’s status, the system lacks more advanced features such as remote control, notifications, or integration with other smart home devices. This limits the user’s ability to monitor and control the gate remotely.
  6. No Safety Mechanisms: The code does not include safety mechanisms such as emergency stop features or obstacle detection during gate movement. If an obstacle is detected while the gate is closing or opening, the system does not automatically stop the motor, which could lead to accidents or damage.

Conclusion

This Arduino-based gate control system efficiently automates the process of opening and closing a gate using IR sensors and a motor. By continuously monitoring sensor inputs, the system determines the presence of obstacles and the gate’s position, driving the motor accordingly to either open or close the gate. The integrated LCD provides real-time feedback, ensuring users are informed of the gate’s status. Overall, the code offers a reliable solution for managing gate operations with minimal manual intervention, enhancing security and convenience.

Leave a Comment

Follow by Email
Pinterest
Pinterest
fb-share-icon
Instagram
Telegram
WhatsApp