IR Sensor Controlled Gate Using IR Sensor and Servo Motor
IR Sensor Controlled Gate Using IR Sensor and Servo Motor
i
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who supported me throughout the
development of this project. First and foremost, I extend my heartfelt thanks to Kenya School of
TVET for providing the opportunity and resources to carry out this project work.
I would also like to acknowledge the invaluable support of my lecturers and laboratory staff
especially Mr. Mwangi, whose expertise and assistance during the prototyping and testing
phases helped me overcome numerous challenges.
Finally, I am grateful to my family and classmates for their moral support, patience, and
encouragement during the course of this project.
This project has been a great learning experience, and I truly appreciate everyone who
contributed to its success.
ii
DEDICATION
This project is wholeheartedly dedicated to my beloved wife, parents, whose unwavering love,
support, and encouragement have been my greatest source of strength throughout my academic
journey. Your sacrifices and belief in my potential have continuously inspired me to strive for
excellence.
I also dedicate this work to my mentors and educators, whose guidance has shaped my
understanding and passion for engineering. Your commitment to knowledge and growth has left
a lasting impact on me.
Lastly, I extend this dedication to all aspiring engineers and innovators, with the hope that this
project will serve as a stepping stone toward practical, meaningful, and accessible automation
solutions for everyday life.
iii
DECLARATION
I hereby declare that this research project is my own original work and has not been
presented in any University or institution for the award of any degree, diploma or certificate.
2024EE159979
Sign…………………….. Date……………………….
Supervisors
This proposal has been submitted for examination with the approval of the following supervisor.
Sign……………………. Date………………………….
iv
CONTENTS
CHAPTER ONE..............................................................................................................................1
1.1 Introduction............................................................................................................................1
1.2 Problem statement..................................................................................................................1
1.3 Objectives /Aims....................................................................................................................3
1.4 Specifications.........................................................................................................................3
1.5 Block diagram........................................................................................................................6
1.6 Brief description of each block..............................................................................................6
CHAPTER TWO.............................................................................................................................8
2.1. Literature Review..................................................................................................................8
Summary of Findings...............................................................................................................9
2.2. Theory of the Circuit Block................................................................................................10
2.3 Theory of the circuit choice.................................................................................................21
2.4 Design of the project............................................................................................................22
CHAPTER THREE.......................................................................................................................28
3.1 Circuit diagram....................................................................................................................28
3.2 Project operation..................................................................................................................28
3.2 Project Test Results..............................................................................................................31
3.4 Recommendations................................................................................................................33
3.5. Conclusion on Testing........................................................................................................35
3.6 REFERENCES.....................................................................................................................35
APPENDICES...............................................................................................................................36
v
CHAPTER ONE
1.1 Introduction
In the modern world, automation plays a significant role in enhancing convenience, security, and
efficiency in daily life. One area where automation has shown considerable benefit is in access
control systems, particularly in automated gate operations. Traditional gate systems require
manual effort or physical contact, which can be inconvenient and, in some cases, insecure or
unhygienic.
This project presents the design and development of an Infrared Operated Gate System, which
allows users to open or close a gate wireless using infrared (IR) technology. The system is based
on an IR transmitter and a receiver module that communicates with a micro-controller. When a
valid signal is received, the micro-controller activates a motor through a driver circuit to open or
close the gate accordingly.
The primary goal of this project is to demonstrate the practical implementation of contact less
control using affordable and accessible components, with applications in residential,
institutional, and industrial settings. By incorporating basic principles of electronics, sensor
interfacing, and embedded programming, this project serves as a foundational step towards more
complex home and industrial automation systems.
1. Human Intervention: Existing gates often require constant human presence for operation,
leading to increased labor costs and potential security risks.
2. Time Inefficiency: Manual operation causes delays in entry and exit, resulting in traffic
congestion during peak hours and frustration for users.
5. Energy Wastage: Gates left open unnecessarily can lead to increased energy consumption in
climate-controlled environments.
1
6. Maintenance Costs: Frequent wear and tear due to manual operation results in higher
maintenance expenses.
7. Accessibility Issues: Current systems may not adequately accommodate people with
disabilities or those carrying heavy items.
8. Integration Challenges: Many existing gate systems cannot be easily integrated with modern
smart home or building management systems.
10. Environmental Concerns: The lack of intelligent control may lead to unnecessary vehicle
idling, increasing local air pollution.
To address these issues, there is a pressing need for an automated, reliable, and efficient gate
system that can operate without constant human supervision. An infrared operated gate system
offers a potential solution by providing:
The proposed infrared operated gate system aims to overcome these challenges by leveraging
infrared sensor technology, intelligent control mechanisms, and robust design principles. This
system will need to be reliable in various environmental conditions, easily maintainable, and
scale able to different types of gates and security requirements.
The successful implementation of such a system would significantly enhance the safety,
efficiency, and user experience of access control in various settings, from residential complexes
to high-security facilities.
2
1.3 Objectives /Aims
The primary objective of this project is to design and implement an Infrared Operated Gate
System that allows for wireless, contact less gate control using IR communication. To achieve
this, the project is guided by the following specific objectives:
1.4 Specifications
This section outlines the technical, functional, mechanical, and environmental specifications of
the Infrared Beam-Based Automatic Gate System.
3
Self-Closing Mechanism:
After a preset delay (e.g., 5–10 seconds), the gate automatically closes unless the beam
remains broken.
Bidirectional Motor Control:
The system drives the gate open and closed using a motor operated in both forward and
reverse directions.
Obstacle-Free Detection:
The IR sensor returns to idle (beam unbroken) state when no object is present.
Visual/Audible Indicators:
LEDs or a buzzer indicate gate status (opening, closing, or idle).
Safety Integration:
Limit switches (optional) prevent gate overrun and protect the motor from mechanical
damage.
Component Specification
Motor Driver L298N H-bridge motor driver (supports two directions and sufficient current)
Gate Operation
Typically, 3–5 seconds to fully open or close (adjustable in code)
Time
Gate Width Model gate (10–30 cm wide); scalable for real applications
Response Time < 0.5 seconds from beam break to gate action
Frame:
Wooden, acrylic, or aluminum base for mounting components and the model gate.
Gate Arm:
Lightweight material (foam board, plastic, or wood) driven by a geared motor or hinge.
4
Sensor Mounting:
IR LED and receiver aligned on opposite sides of the gate entrance for uninterrupted
beam.
Motor Coupling:
Direct shaft or linkage connected to gate arm for controlled movement.
Parameter Specification
Operating Voltage 5V–12V DC (regulated supply for Arduino and sensors)
Operating Temp. 0°C to 50°C
Humidity 10%–85% RH (non-condensing)
IR system works best in low ambient light or with IR shielding to
Light Sensitivity
reduce false triggers
These specifications ensure that the gate operates automatically, safely, and efficiently using a
contact less IR beam system—ideal for training, prototyping, or real-world access control.
5
1.5 Block diagram
An automatic gate opening system typically involves sensors, a microcontroller, and an actuator
(such as a motor) to open or close the gate based on certain inputs (like distance, presence, or a
manual command). Below is a detailed block diagram of such a system, followed by its
application:
The sensor detects the presence of a vehicle or an object in front of the gate. Commonly used
sensors include:
The sensor sends data to the Arduino microcontroller about whether an object is within a
specified range, indicating that the gate should open or close.
1.6.2Arduino Controller:
The Arduino processes the input from the sensor and makes decisions about when to activate the
gate motor. It can also process manual inputs from a button or remote.
The Arduino typically runs a program that checks the sensor readings and sends control signals
to the motor driver.
6
1.6.3 Gate Motor:
A Servo motor is used to physically open or close the gate. The motor is controlled by the
Arduino, which determines whether the gate should move forward or backward.
Provides the necessary power to the Arduino, sensors, and motor. Depending on the motor
specifications, the power supply might need to handle a higher current compared to the Arduino.
7
CHAPTER TWO
2.1. Literature Review
Automation in access control systems has gained significant attention over the past two decades,
driven by the increasing demand for convenience, security, and hygiene. Infrared (IR) sensor-
based technologies, in particular, offer a simple yet effective approach to detecting objects or
individuals in proximity-based automation systems.
Infrared sensors operate by emitting IR radiation and detecting changes in the received signal,
often caused by obstruction or reflection. According to [M. A. Mazidi et al., 2011], IR systems
are widely used in automatic door openers, robotic navigation, and consumer electronics due to
their low cost, reliability, and ease of integration.
Studies like those by Zhang et al. (2012) have shown that IR beam interruption detection is an
effective method for triggering automated processes in access control systems. The simplicity of
line-of-sight operation and fast response time make IR sensors ideal for close-range detection
applications like gate automation.
Automatic gates contribute significantly to the convenience and security of modern facilities.
Traditional systems rely on remote controls, RFID tags, or biometric inputs. However, IR-based
gate systems have emerged as a preferable choice in low-cost installations. According to A. Jain
(2015), IR detection systems are preferred in parking lots, hospital entries, and restricted areas
where contactless operation and quick response are essential.
Kumar and Singh (2017) discussed the integration of IR sensors in automation, noting their
effectiveness in indoor environments where ambient IR interference is minimal. The researchers
emphasized the importance of sensor alignment and environmental calibration in improving
system reliability.
Compared to ultrasonic, RFID, and camera-based systems, IR technology stands out for its
simplicity and power efficiency. Das and Roy (2018) compared IR and ultrasonic sensors in
automatic door applications and concluded that while ultrasonic sensors are better for variable
range detection, IR sensors are more cost-effective and less prone to false triggers in confined
spaces.
8
2.1.4. Microcontroller-Based Control
The use of microcontrollers like Arduino in gate automation has become mainstream due to their
ease of programming and extensive I/O capabilities. According to Smith et al. (2020), Arduino-
based automation projects enable real-time control, customization, and easy integration with
motor drivers and sensor modules. The flexibility allows developers to tailor gate behaviors such
as delay times, obstacle responses, and safety cutoffs.
While IR systems are simple and reliable, they can be affected by sunlight, dust, and
misalignment. Yadav et al. (2019) suggest the use of modulated IR signals (typically at 38kHz)
and sensor shielding to improve outdoor reliability. Furthermore, combining IR with other
sensors such as ultrasonic or limit switches can enhance the robustness of gate systems.
Summary of Findings
Aspect Insight
IR sensors in
Reliable for object detection in controlled environments
automation
IR vs. other
Simpler, cheaper, but sensitive to environmental interference
technologies
This literature review supports the viability of an IR-based automatic gate system as a practical,
low-cost solution for short-range automated access control in domestic or institutional
environments.
9
2.2. Theory of the Circuit Block
Infrared sensor is a sensor that uses infrared rays to measure temperature, analyze gas
composition or perform non-destructive testing. It is a non-contact measurement method.
Infrared sensor includes optical system, detection element and conversion circuit. Optical system
can be divided into transmission type and reflection type according to different structures.
Detection element can be divided into thermal detection element and photoelectric detection
element according to working principle.
10
2.2.1 .2What does an infrared sensor consist of?
Infrared sensors usually consist of three parts: optical system, detection element and conversion
circuit.
Optical system: responsible for receiving and focusing infrared radiation and guiding it to the
detection element. The optical system usually consists of lenses, filters, etc., which are used to
improve the sensitivity and anti-interference ability of the sensor.
Detection element: It is the core part of the infrared sensor and is responsible for converting the
received infrared radiation into electrical signals. There are many types of detection elements,
including thermocouples, thermistors, photodiodes, photomultiplier tubes, etc. Different types of
detection elements have different characteristics and applications.
Conversion circuit: Amplifies filters and converts the electrical signal output by the detection
element, and finally outputs a signal that can be used by the circuit or system. The design of the
conversion circuit is very important for the performance of the sensor.
The working principle of infrared sensors is mainly based on the following effects:
11
Thermoelectric effect
Thermo electric effect is the electromotive force generated when there is a temperature
difference between two different materials. When infrared radiation is irradiated to the target
surface, the target surface absorbs the radiation and is heated, causing the surface temperature to
rise. Thermocouples measure this temperature difference and calculate the temperature of the
target surface. This principle has been widely used in infrared temperature sensors, which can
realize long-distance, non-contact temperature measurement.
Photoelectric effect
The photoelectric effect refers to the interaction between photons and matter, which causes the
matter to absorb the photon energy and release photoelectrons. In infrared sensors, the
photoelectric effect is usually used to measure the reflectivity and transmittance of the target
surface. After the infrared light emitted by the transmitter encounters the object, part of the
reflected light is received by the receiver and converted into an electrical signal. By measuring
the intensity of the reflected light, the existence, distance and surface characteristics of the object
can be judged. The photoelectric effect is mainly used to make devices such as photodiodes and
photomultiplier tubes, which are widely used in infrared imaging, spectral analysis and other
fields.
The pyroelectric effect is that some crystalline materials will produce electrical polarization
when the temperature changes, thereby generating a voltage signal. In infrared sensors, the
pyroelectric effect is used to measure the emissivity of the target surface. When the infrared
radiation emitted by the target surface passes through the crystal, the electrical polarization of the
crystal changes and generates a voltage signal. By measuring this voltage signal, the emissivity
of the target surface can be determined, and then the properties and temperature distribution of
the target surface can be analyzed.
The core component of the pyroelectric infrared sensor is the pyroelectric detection element. It is
made by plating metal electrodes on both sides of the pyroelectric crystal and then polarizing it.
This detection element is equivalent to a flat plate capacitor with a pyroelectric crystal as the
12
dielectric. When exposed to infrared light of non-constant intensity, the temperature change of
the detection element causes the charge density of its surface electrode to change, thereby
generating a pyroelectric current. The pyroelectric infrared sensor responds very sensitively and
can detect infrared temperature changes.
Infrared thermopile sensor is a sensor that can detect infrared radiation in the surrounding
environment. It uses the thermoelectric effect to convert infrared radiation into electrical signals.
The sensor usually consists of an integrated circuit chip, an infrared detector and a lens. It can
detect infrared radiation emitted by people, animals and objects, realize non-contact temperature
measurement and long-distance monitoring. Infrared thermopile sensors have the advantages of
fast response speed, high accuracy and long service life.
Infrared gas sensor is a device that uses the principles of infrared absorption, scattering,
transmission and reflection to measure gas concentration. It determines the gas concentration by
emitting infrared light through the gas being measured and measuring the intensity of the
remaining infrared light after transmission. Infrared gas sensor is an optical sensor because it
uses the optical principle of infrared light to measure gas concentration. However, it is different
from general optical sensors because it measures the intensity of infrared light instead of visible
light.
This sensor is a device that uses infrared thermal imaging technology to measure the temperature
distribution on the surface of an object. It can convert the infrared radiation emitted by the
surface of an object into electrical signals, and generate corresponding temperature images by
analyzing the intensity and distribution of these electrical signals. There are many types of
infrared thermal imaging sensors, among which the most commonly used is the infrared thermal
imaging sensor based on focal plane array (FPA) technology. Infrared thermal imaging sensors
can intuitively display the temperature field on the surface of an object, are not affected by
strong light, and are widely used.
13
2.2.1.4.5. Active infrared sensors
Active infrared sensor can actively emit infrared beams and detect the presence of targets by
detecting the reflection of the beam. When a person or object passes through the infrared beam
between the transmitter and the receiver, the infrared signal received by the receiver will change,
thus triggering an alarm. This type of infrared sensor is not affected by environmental factors and
has more measurements that are accurate.
Fiber optic infrared sensor is a device that uses fiber optic technology combined with infrared
detection technology. It is mainly used to detect and measure physical quantities such as infrared
radiation, gas composition and temperature changes. The working principle of this type of sensor
is based on the change of specific absorption wavelength and intensity of infrared radiation on
the substance. The optical fiber transmits the infrared signal to the detector for analysis. Fiber
optic infrared sensors are not affected by electromagnetic interference and are particularly
suitable for use in strong electromagnetic environments.
A miniature infrared spectrometer is a device that can use infrared spectroscopy technology to
analyze and detect substances. Its main features are small size, low power consumption, and fast
response. It usually obtains information by analyzing the absorption characteristics of substances
to infrared light of a specific wavelength. It is widely used in gas detection, environmental
monitoring, food safety, medical diagnosis and other fields.
Industrial Sensors and Actuators
Top 10 IoT Sensors and Actuators
Here is how to build a simple infrared sensor circuit that can be used in any application that
requires detection. Infrared sensor module circuit design:
14
Processing:
A simple infrared LED and photodiode are used to emit and sense the infrared beam. The
operational amplifier IC 741 is used as a comparator to switch the output level to logic 1 or logic
0. The variable resistor RV1 is used to adjust the sensitivity of the detector by changing the
reference voltage of the comparator. Finally, the LED D3 is used as an indicator when it is
detected or reflected.
When the circuit is powered, the infrared LED D1 emits an infrared beam. The photodiode D2 is
connected in series with the resistor R2 in a reverse biased manner. When there is no infrared
beam incident in the photodiode, no current passes through it, which in turn causes the voltage to
not drop and the inverting terminal of the operational amplifier is fed with a maximum voltage of
5V. Since the voltage at the inverting terminal is greater than the reference voltage at the “+”
terminal of the operational amplifier, the output remains low or logic 0.
When the infrared beam is reflected by an object on the photodiode, current passes through it and
in turn a voltage drop occurs between the terminals. Now, the reference voltage at the “+”
terminal of the operational amplifier is greater than the “-” terminal. The output of the
operational amplifier switches to high or logic 1 state.
This design is useful for interfacing with microcontrollers for detection as it provides two logic
level outputs, compatible with many microcontrollers.
15
2.2.1.6Application of infrared sensors
Automatic control
In the process of automated production, infrared sensors can be used to detect the position, speed
and shape of objects to achieve precise control of the production process. For example, control
the grabbing and placing actions of the robotic arm, detect the approach of pedestrians and
automatically open the door.
Security monitoring
By detecting the infrared radiation emitted by the human body, infrared motion detectors can
detect and alarm intruders. Widely used in anti-theft alarm systems in homes, offices,
warehouses, laboratories, etc.
Smart home
By detecting the infrared radiation and motion information of people, infrared sensors can realize
functions such as intelligent lighting and intelligent temperature control. For example, when a
person enters a room, the infrared sensor can automatically turn on the lights and air
conditioners.
Medical field
Infrared sensors can be used for contactless temperature measurement and disease diagnosis. For
example, the thermal image of the surface temperature of a person is measured at a long distance,
and the abnormal temperature is found to assist doctors in diagnosis. Infrared sensors can also be
used to measure blood flow rate and monitor heart function.
In the military, infrared sensors can be used for target tracking, missile guidance and satellite
remote sensing. By detecting the infrared radiation emitted by the target and analyzing and
processing it, the target can be tracked and located. Infrared sensors can monitor environmental
data such as the earth’s clouds and ocean temperature.
16
Nondestructive testing
This is a method of testing the physical or chemical properties of an object without damaging it.
Infrared sensors are also widely used in the field of nondestructive testing. Nondestructive
testing is an indispensable technology in modern industry to ensure product quality and safety.
2.2.3.1. Definition
A servo motor is a rotary actuator or linear actuator that allows for precise control of angular or
linear position, velocity, and acceleration. It consists of a motor coupled with a sensor for
position feedback and is controlled by a signal (usually PWM).
2.2.3.2. Construction
A servo motor receives a Pulse Width Modulated (PWM) signal from a microcontroller (like
Arduino). The width of the pulse determines the angle of rotation:
- 1 ms → 0°
- 1.5 ms → 90°
- 2 ms → 180°
The internal control circuit compares the received signal with the feedback from the
potentiometer. If there is a mismatch, the DC motor rotates in the required direction to correct it.
17
- 1.5 ms → 90°
- 2.0 ms → 180°
2.2.3.6. Characteristics
-High precision
- Quick response
- Low noise
- Controlled by microcontrollers
- Position feedback
2.2.3.7. Applications
- Robotic arms
- Automatic gates/doors
- Antenna positioning
- Remote-controlled cars and planes
- Industrial automation
18
2.2.3.9. Limitations
2.2.3.10. Conclusion
The servo motor is a crucial component in automation and robotics, offering compact size,
reliability, and precision. In the context of an infrared-operated gate system, it plays the key role
of actuating the gate based on sensor input.
2.2.3.1 Definition
19
2.2.3.3 Working Principle
2.2.3.4Features
Arduino is programmed using the Arduino IDE with a simplified version of C/C++. The basic
structure of a sketch (program) includes:
- void setup(): runs once when the board is powered on or reset
- void loop(): runs continuously after setup
The code is compiled and uploaded to the board via USB.
20
2.2.3.7 Applications
2.2.3.8 Advantages
2.2.3.9 Conclusion
In designing an infrared operated gate system, selecting the appropriate blocks is crucial for
ensuring functionality, efficiency, and reliability. Each block—Infrared Sensor, Arduino
Microcontroller, Servo Motor, and Gate Mechanism—was chosen based on its suitability for a
contactless and automatic control system. The following is a theoretical justification for each
choice.
The IR sensor is used for object detection without physical contact. It emits infrared light and
detects the reflection from nearby objects. This block was chosen due to its simplicity, low cost,
fast response time, and ability to detect the presence of an object or person, which makes it ideal
for initiating the gate-opening mechanism in an automatic system.
21
2.3.2. Arduino Microcontroller
The Arduino (Nano or Uno) serves as the control unit, reading sensor input and
controlling the actuator. It was selected because of its:
- Open-source and cost-effective nature
- Ease of programming using Arduino IDE
- Compatibility with sensors and actuators
- Sufficient I/O pins and built-in support for PWM (to control the servo)
Arduino is user-friendly for beginners and powerful enough for handling real-time
operations in embedded systems.
A servo motor is used to actuate the gate due to its precise angular control and reliability. It was
chosen because:
- It can rotate to a specific angle based on the PWM signal
- It maintains position without drift
- It provides enough torque for lightweight gates
- It is compact and energy-efficient
Servo motors like SG90 are ideal for small mechanical applications like opening or closing a
mini gate.
The gate mechanism represents the physical barrier that opens or closes upon activation. The
gate is directly connected to the servo motor horn. It was chosen to demonstrate real-world
application and mechanical movement. The gate can be made from light materials like plastic or
cardboard to suit the torque limitations of small servo motors.
2.3.5. Conclusion
Each block in the infrared operated gate system was carefully selected for its cost-effectiveness,
ease of integration, and functional performance. The combination of these components ensures
that the system operates efficiently and can be easily implemented in real-life applications such
as automated doors, smart homes, or school gates.
The design phase of this project focuses on translating the conceptual idea of an IR-operated gate
system into a tangible and functional prototype. This involves careful consideration of the
22
system's architecture, selection of appropriate components, meticulous circuit design, and robust
software development.
Sensor Layer (Input): This layer is responsible for detecting the presence of an
object. It comprises an Infrared (IR) Transmitter and an IR Receiver pair. The
transmitter continuously emits an IR beam, while the receiver monitors for this
beam. An interruption in the beam indicates the presence of an object.
Processing Layer (Control Unit): The Arduino nano serves as the central
processing unit. It reads the analog or digital signals from the IR receiver, interprets
whether an object is detected, and executes the pre-programmed logic for gate
operation. It also manages the timing for automatic gate closure.
Actuator Layer (Output): This layer is responsible for physically operating the
gate. A Servo Motor is selected for this purpose due to its ability to precisely
control angular position. The Arduino sends control signals to the servo motor to
move the gate to its "open" or "closed" positions.
Interaction Flow:
23
2.4.2 Component Selection Rationale
The selection of specific components is crucial for the system's performance, cost-effectiveness,
and ease of implementation.
Rationale: Servo motors offer precise angular control, allowing the gate to open and
close smoothly to specific predefined positions. The SG90 is suitable for small-scale
prototypes (e.g., a model gate), while an SG5010 or similar standard servo would be
appropriate for a slightly larger, more robust physical model due to its higher torque.
They are easy to interface with Arduino using the Servo.h library.
Power Supply:
24
Rationale: A stable 5V DC power supply is essential. While the Arduino can be
powered via USB for prototyping, a dedicated external power supply (e.g., a 9V or
12V adapter connected to the Arduino's barrel jack or Vin pin, or a regulated 5V
supply connected directly to the 5V pin, with caution) is recommended for driving the
servo motor, especially larger ones, to avoid drawing excessive current from the
Arduino's onboard regulator.
Specifics: For an SG90, the Arduino's 5V output is often sufficient for testing. For an
SG5010, a separate regulated 5V supply capable of providing at least 1A is
recommended to prevent brownouts or instability.
The circuit design ensures proper electrical connections and component interaction.
Key Connections:
Arduino Power:
25
Servo Motor:
Orange/Yellow Wire (Signal): right arrow Arduino Digital PWM Pin (e.g., D9 or
D10)
Red Wire (VCC): right arrow Arduino 5V (for SG90) or External Regulated 5V
Supply (for larger servos)
Brown/Black Wire (GND): right arrow Arduino GND (and External Supply
GND if applicable)
The Arduino sketch (.ino file) is the core intelligence of the system. It defines how the
microcontroller interprets sensor data and controls the actuator.
Libraries
Servo.h: This standard Arduino library simplifies the control of servo motors. It handles
the specific PWM signals required to move the servo to desired angles
26
#include <Servo.h>
Servo gateServo; // Create a servo object
const int irSensorPin = 2; // IR sensor connected to digital pin 2
const int openAngle = 90; // Angle to open the gate
const int closeAngle = 0; // Angle to close the gate
void setup() {
gateServo.attach(9); // Servo signal connected to pin 9
pinMode(irSensorPin, INPUT);
gateServo.write(closeAngle); // Ensure gate is closed at start
Serial.begin(9600); // For debugging (optional)
}
void loop() {
int sensorState = digitalRead(irSensorPin);
if (sensorState == LOW) { // Object detected (IR interrupted)
Serial.println("Object detected - Opening gate");
gateServo.write(openAngle); // Open gate
delay(5000); // Wait for 5 seconds
Serial.println("Closing gate");
gateServo.write(closeAngle); // Close gate
delay(1000); // Short delay before next detection
}
}
27
CHAPTER THREE
3.1 Circuit diagram
This section describes the step-by-step operation of the infrared-operated gate system, from
object detection to gate closure. It ties together the hardware components and the software logic
to illustrate the system's dynamic behavior.
28
3.2.1 System Initialization:
The loop() function runs continuously, performing the following actions repeatedly:
29
3.2.4 Gate Holding (Staying Open):
1. OPEN State: If an object remains in front of the sensor, the objectDetected flag
will still be true. In this case, the gateOpenTime is continuously reset to the
current time. This prevents the auto-close timer from starting, keeping the gate
open as long as the object is present. This is crucial for allowing a car to pass
completely through the gate.
1. Object No Longer Detected: Once the object moves away and no longer blocks
the IR beam, objectDetected becomes false.
2. Delay Before Closing: The code checks if the autoCloseDelay (e.g., 5 seconds)
has elapsed since the last time an object was detected AND if objectDetected is
now false. This ensures the gate stays open for a sufficient time before attempting
to close.
3. Closing the Gate: If the delay has passed and no object is detected, the gate
Servo.write(CLOSED_ANGLE) command is sent, and the currentGateState
transitions to CLOSING.
4. CLOSING State: Similar to opening, an optional delay (servoMovementDelay)
can be used to wait for the servo to reach the CLOSED_ANGLE. The state then
returns to CLOSED.
1. The Serial.println() statements throughout the code send messages to the Arduino
IDE's Serial Monitor. This is invaluable for debugging, allowing you to see the
values of variables, the states of the system, and the timing of events.
30
3.2 Project Test Results
This section details the testing procedures performed on the infrared-operated gate system and
presents the observed results. The primary goal of testing was to verify the system's
functionality, responsiveness, and adherence to the design specifications.
Hardware Setup: The Arduino Uno, IR sensor module (transmitter and receiver), and
servo motor were assembled on a breadboard according to the circuit diagram. The servo
motor was attached to a simple physical model representing a gate (e.g., a cardboard flap
or a small plastic arm).
Power Supply: Arduino powered via USB initially for programming and debugging. For
final testing, an external 5V regulated power supply was used for the servo to ensure
stable operation.
Software Setup: The Arduino IDE was used to upload the compiled sketch to the
Arduino Uno. The Serial Monitor was utilized to observe system status messages and
debugging information.
Test Object: A hand or a small piece of cardboard was used to simulate the presence of
an object interrupting the IR beam.
A series of tests were conducted to evaluate different aspects of the system's operation.
Procedure: With the gate in the closed position, place the test object in the path of the IR
beam, interrupting it.
Expected Result:
31
Within a very short delay (milliseconds), the servo motor should smoothly rotate
from the CLOSED_ANGLE to the OPEN_ANGLE (e.g., 90 degrees), simulating
the gate opening.
Observed Result: the gate opened at 90 degrees for as long the object is dected
Procedure: Keep the test object continuously in the path of the IR beam after the gate
has fully opened.
Expected Result:
The gate should remain in the OPEN_ANGLE position indefinitely, as long as the
object is present.
Observed Result: the gate remained opened as long the object was detected
Procedure: After the gate has opened and an object was present, remove the test object
from the IR beam path.
Expected Result:
The gate should remain open for the specified autoCloseDelay (e.g., 5 seconds) after the object is
removed.
After the delay, the servo motor should smoothly rotate from the OPEN_ANGLE back to the
CLOSED_ANGLE, simulating the gate closing.
Procedure: Briefly interrupt the IR beam (less than the autoCloseDelay), then quickly
remove the object.
Expected Result:
32
Observed Result: The gates opened and after the object passed and delayed time lapsed
the gate automatically closes
Gate observed at
Gate closed, Serial 0 degrees, Startup sequence as
1 Initial State Pass
Monitor messages messages expected.
confirmed
Gate stayed
Gate remains open
open for 30+ Timer effectively reset by
3 Gate Hold while the object Pass
seconds with continuous detection.
present
object
Gate opened,
Rapid Gate opens, then then closed after System correctly handled
5 Pass
Passage closes after delay 5s despite brief quick object passage.
interruption
3.4 Recommendations
Based on the design, testing, and successful operation of the infrared operated gate system, the
following recommendations are proposed to enhance performance, durability, and usability in
practical applications:
33
3.4.1 Use Protective Housing:
Enclose the infrared sensor and servo motor in weatherproof and dustproof casing to
protect against environmental factors and physical damage, especially in outdoor
installations.
For larger or heavier gates, consider using a high-torque servo motor or a DC gear
motor with relay control to handle greater mechanical loads efficiently.
Add an LED indicator or buzzer to provide visual/audible signals when the gate is
opening or closing, improving user awareness and safety.
Integrate GSM, Bluetooth, or Wi-Fi modules for remote gate control via mobile
devices, which would enhance convenience and security.
Introduce obstacle detection (e.g., ultrasonic sensors) during gate operation to avoid
accidental injury or damage by halting the gate if an obstruction is detected.
Schedule regular checks of the servo motor alignment, IR sensor calibration, and
wiring connections to maintain optimal system performance over time.
Use professional enclosures and proper mounting for components to make the system
visually appealing and mechanically stable for real-world deployment.
34
3.5. Conclusion on Testing
The testing results confirm that the infrared-operated gate system successfully meets its core
objectives. The Arduino microcontroller effectively interprets IR sensor input and precisely
controls the servo motor for gate actuation. The implemented state machine and timing logic
ensure accurate object detection, proper gate opening, and reliable automatic closure after a
defined delay. Minor limitations related to environmental factors (e.g., direct sunlight on IR
sensors) were identified, which are inherent to the chosen sensor technology but can be mitigated
with appropriate physical design considerations. Overall, the system demonstrates a robust and
functional automated access control solution.
3.6 REFERENCES.
1. Banzi, M., & Shiloh, M. (2014). Getting started with Arduino (3rd ed.). Maker Media,
Inc.
2. Monk, S. (2016). Programming Arduino: Getting started with sketches (2nd ed.).
McGraw-Hill Education.
3. McRoberts, M. (2013). Beginning Arduino (2nd ed.). Apress.
4. Sharma, R. K. (2020). Embedded Systems and Robotics with Open Source Tools. CRC
Press.
5. SparkFun Electronics. (n.d.). How to use an IR sensor. Retrieved from
https://learn.sparkfun.com/tutorials/ir-sensor-basics
6. ServoCity. (n.d.). How servo motors work. Retrieved from
https://www.servocity.com/servo-motors-explained
7. Arduino. (n.d.). Arduino Nano documentation. Retrieved from
https://docs.arduino.cc/hardware/nano
8. Circuit Digest. (2019). IR Sensor with Arduino – How IR sensor works, Arduino Code,
Circuit Diagram. Retrieved from
https://circuitdigest.com/microcontroller-projects/interfacing-ir-sensor-with-arduino
9. Components101. (n.d.). SG90 Micro Servo Motor Datasheet. Retrieved from
https://components101.com/motors/sg90-servo-motor
10. Instructables. (n.d.). Automatic Gate System Using IR Sensor. Retrieved from
https://www.instructables.com/Automatic-Gate-Using-IR-Sensor-and-Arduino/
35
APPENDICES
Libraries
Servo.h: This standard Arduino library simplifies the control of servo motors. It handles the
specific PWM signals required to move the servo to desired angles
#include <Servo.h>
void setup() {
pinMode(irSensorPin, INPUT);
}void loop() {
Serial.println("Closing gate");
36
3.1 Circuit diagram
37