Professional Documents
Culture Documents
Automatic Railway Gate Control System - Circuit & Source Code
Automatic Railway Gate Control System - Circuit & Source Code
Automatic Railway Gate Control System - Circuit & Source Code
Power
Forum
Electronica
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 1/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
tutorial we need to get an idea about what is automation and what exactly
one can expect from it.
The complexity of the automation can vary from a basic” on/off “control to
highly complex multivariable algorithms. The control systems for the
automation purpose can either be open loop or closed loop meaning it
can work either with a single input parameter or in response to the output
fed as the input as in case of closed loop systems. The automation in the
railway industry is an important need as we are stepping into the
advanced era and to reduce the risk of accidents due to human induced
errors it is very important that we let these tasks be handled by these
smart machines.
Like in the case of every technology automation also has its pros and
cons:
Pros
El t i
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 2/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
1. Increase in productivity
2. Predictable quality (Quality Improvement)
3. Increased robustness
4. Great output consistency
5. Reduction in human labour expenses
6. Highly accurate
7. Reduces human efforts in monotonous works
Cons
The pros mentioned far outweigh the cons and that is why the entire
world is stepping into the era of automation.
In this tutorial we are trying to automate a railway gate to open and close
whenever the circuit detects an train along the track and we will also
initiate a buzzer or an alarm depicting the speed of the train is higher than
a particular threshold and for achieving that we are going to use the two
very widely used electronic components i.e. Arduino and servo motor.
The sensor which we are going use in this tutorial is the ultrasonic sensor
but it is not mandatory to use this sensor we can also make a different
version of this project using the IR sensor module and it depends on our
choice, what we want to use and what is readily available to us.
Table of Contents
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 3/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Software Required:
1. Arduino IDE
2. Proteus
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 4/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Component Description
Arduino UNO
Arduino is basically a development board which is open source and
primarily utilizes the Microchip ATmega328P microcontroller and is
manufactured by Arduino.cc. The board comes with a set of input/output
pins comprising of digital and analog which can be interfaced to different
expansion boards and external circuits.
The board comes with 14 digital pins along with 6 analog pins which are
utilized or made programmable with the help of an IDE (Integrated
Development Environment) that comes along with it which is Arduino IDE.
The programmed is burned via a USB cable type B. Powering up
methods for the board can be either by the USB cable or by connecting 9
volts dc supply. Acceptable voltage range varies from 7 to 20 volts. By the
design and working point of view it is not too different from its other family
members namely Arduino Nano and Arduino Leonardo.
STK500 is still the original protocol for Uno to communicate. The major
difference from its predecessors is that it does not make use of the FTDI
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 5/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Trig pin
Echo pin
GND pin
VCC pin (+5V)
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 6/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Get your o
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 7/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Servo Motor
These are a special kind of motors which are employed for very specific
movement at a particular angle. It is a rotary or linear actuator that
permits precise control at certain angular or linear positions. Servo motor
is not a single entity but a combination of a suitable motor along with a
sensor which gives the feedback of the current position of the motor.
In order to use this servo motor several other advanced module are to be
used as it is not similar in terms of ease to use the DC motor. These
motors are basically used in robotics and the large scale manufacturing
industries.
These motors have a little similarity to the stepper motors which represent
the open-loop control. The stepper motors have inbuilt steps at which
they rotate but with the lack of a feedback system there use is limited to
one specific application for which they were designed and manufactured.
This lack of feedback is what sets a servo motor apart from these stepper
motors and give them an upper hand as they are dynamic and can be
customized according to the task at hand with a little alteration in the
programming. A dedicated controller module is generally provided with
the servo motor by the manufacturer.
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 8/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Buzzer
Buzzer can be of mechanical, electronic, electromechanical and
piezoelectric in nature. Generally we use the electronic one in ovens,
game shows and appliances etc. These buzzers have an internal circuit.
The sound produced is because of the movement of a disk. The disk is
ferromagnetic in nature. It is a current driven device which has a voltage
source as an input to it.
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 9/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Get your o
If the track is clear then servo motors will do nothing but if a train arrives
on either side of the track then distance measured by one of the sensors
will vary from the previous distance. In this way we will get informed about
the arrival of the train and in no time, Arduino will set its digital pins 7 and
8 to HIGH.
These pins are connected with the two servo motors and then the servo
will cover an angular distance of 90o and hence the gate will get closed to
block the path for vehicles. When the train will go away from the other
sensor it will get the Arduino notified about departure of the train and
servo motors will once again attain its previous position to open the gate.
Considering safety of the people we have added one more feature to this
circuit and it is about alerting them in case of a high-speed train. This is
achieved by calculating the time between the transitions of two sensors in
one cycle. If time is found to be less than a certain value then buzzer will
make a buzzing sound to alert people in the vicinity of crossing.
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 10/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Baud rate is set to 9600 bits/sec and is responsible for the communication
between board and the serial monitor.
Functions included in the void setup () will run only once during execution
and their task is to define baud rate and mode of the pin as input or
output.
void setup() {
// put your setup code here, to run once:
pinMode(tr1, OUTPUT);
pinMode(tr2, OUTPUT);
pinMode(bz, OUTPUT);
pinMode(eh1, INPUT);
pinMode(eh2, INPUT);
myservo1.attach(8);
myservo2.attach(7);
Serial.begin(9600);
}
There is one more conditional statement that checks if two sensors are
sensing the object quickly then it will set the pin 11 high to power the
buzzer so as to alert the people. All these processes are encompassed in
void loop () and they are repeated until the Arduino is reset or the supply
is stopped.
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(tr1, LOW);
delayMicroseconds(2);
digitalWrite(tr1, HIGH);
delayMicroseconds(10);
digitalWrite(tr1, LOW);
val1 = pulseIn(eh1, HIGH);
dis1 = (val1 * 0.0343) / 2;
digitalWrite(tr2, LOW);
delayMicroseconds(2);
digitalWrite(tr2, HIGH);
delayMicroseconds(10);
digitalWrite(tr2, LOW);
val2 = pulseIn(eh2, HIGH);
dis2 = (val2 * 0.0343) / 2;
Serial.println(“distance is “);
Serial.println(dis1);
Serial.println(dis2);
if(dis1 < 100 || dis2 < 100)
{
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 12/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
if(pos==-1){
for (pos = 0; pos <= 90; pos += 1) {
myservo1.write(pos);
myservo2.write(pos);
delay(15);}
}
delay(1000);
digitalWrite(tr1, LOW);
delayMicroseconds(2);
digitalWrite(tr1, HIGH);
delayMicroseconds(10);
digitalWrite(tr1, LOW);
val1 = pulseIn(eh1, HIGH);
dis1 = (val1 * 0.0343) / 2;
digitalWrite(tr2, LOW);
delayMicroseconds(2);
digitalWrite(tr2, HIGH);
delayMicroseconds(10);
digitalWrite(tr2, LOW);
val2 = pulseIn(eh2, HIGH);
dis2 = (val2 * 0.0343) / 2;
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 13/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
}
}
digitalWrite(bz, LOW);
delay(200);
}
}
Interfacing Hex file with Proteus for simulation: In your Arduino IDE
click on File>Preferences and then in “Show verbose output” check both
the options compilation and upload. And, upon the compilation of the
code in the window below select and copy the location of the hex file and
in Proteus double click on Arduino and paste the file location in the
Program file option and click on OK. Now your circuit will be ready for
simulation into Proteus.
Related Projects:
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 14/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Get your o
Electronics Engineering Project HC-SR04 Railway Gate Control Circuit Servo Motor
Ultrasonic Sensor
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 15/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code
Checkouts
These actuators convert the electrical energy into physical unit called
force, speed etc. A relay is basically a binary actuator with two stable
states. In this article, we will be discussing the details of relay switch
circuit, it designs and features.
Table of Contents
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 18/18