Automatic Railway Gate Control System - Circuit & Source Code

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code

Power
Forum
Electronica

Automation Control Electronics Engineering Project How To Sensors

Automatic Railway Gate Control


System – Circuit & Source Code
 Electrical Technology 2  9 minutes read

High Speed Auto Railway Gate Controller Circuit Using


Arduino and Ultrasonic Sensors
In this tutorial, we will learn how to design a simple and efficient automatic
high-speed railway gate controller system. This is a relatively simple
approach to this project but you can take this as a basic building block
and in further modification we can also track the speed of the train with
which it passes and so much more. But before we jump right into the

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.

Automation basically means to devise a method to reduce or eliminate


human efforts/intervention. In this tutorial we are going to explain how to
automate a railway gate with Arduino using servo motor along with the
Proteus software.

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.

Related Post: Car Speed Detector Circuit – Working and Source


Code

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

1. Susceptible to security threats


2. Development cost might excess beyond the prediction
3. High setting up cost
4. Cause of unemployment in many sectors

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.

Related Post: Smart Home Automation System – Circuit and


Source Code

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

1. Components Required for Railway Gate Controller


2. Software Required:
3. Circuit Diagram of Railway Gate Controller 
4. Component Description
4.1. Arduino UNO
4.2. Ultrasonic Sensor (HC-SR04)
4.3. Servo Motor
4.4. Buzzer
5. Working of Automatic Railway Gate Controller
6. Project Source Code & Explanation

Components Required for Railway Gate Controller


1. Arduino UNO
2. Buzzer
3. Ultrasonic Sensor (HC-SR04)
4. Servo Motor

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

Circuit Diagram of Railway Gate Controller 

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

USB-to-serial driver chip. On the contrary it uses ATmega 16U2


(Atmega8U2 up to version R2) which is programmed like USB-to-serial
converter.

Related Post: Variable Power Supply Using Arduino UNO –


Circuit and Code

Ultrasonic Sensor (HC-SR04)


The Ultrasonic sensor is the basic sensor that we use to determine the
distance of an object. In another way we can say that it is used to
measure how far away the object is located from a particular reference
point. It has basically 4 pins;

Trig pin
Echo pin
GND pin
VCC pin (+5V)

How ultrasonic works? The transmitter (trig) sends a high frequency


sound signal which is then reflected by the object and then the reflected
signal is then received at the receiver (echo). Hence the speed of sound
in air is known to us we can calculate the distance. This sensor is
extremely popular among the Arduino tinkerers who use this in their
projects on a daily basis and to trigger this sensor we require a high pulse
of 10 microseconds or more.

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

Features of ultrasonic sensor:-

Power Supply: +5V DC


Quiescent Current: <2mA
Working Current: 15mA
Effectual Angle: <15°
Ranging Distance: 2cm – 400 cm/1″ – 13ft
Resolution: 0.3 cm
Measuring Angle: 30 degree
Trigger Input Pulse width: 10uS
Dimensions: 45mm x 20mm x 15mm

Related Post: Automatic Plant Watering & Irrigation System –


Circuit, Code & Project Report

Get your o

See how Googl


offline, in-store

Google Maps Platform

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.

Mechanism– It is basically a closed-loop servomechanism that utilize the


feedback system for updating the motion and the ultimate position of the
rotor. The input to the control of the motor can either be analog or digital
in.

Related Post:  Distance Measurement Using Arduino and


Ultrasonic Sensor

An encoder of some type is paired to the motor so as to give the position


and speed feedback to the control which generates an error signal till the
desired output is not reached. And in order to reduce this error signal the
motor may move in either direction to finally reduce the error signal to
zero. When this condition is achieved the desired output is achieved.

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

Enhanced and sophisticated servo motors have an optical rotary encoder


at the output shaft to measure its speed.

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.

Working of Automatic Railway Gate Controller


In this circuit we have used ultrasonic sensors and servo motors to
replicate the working of a railway crossing. Both the sensors are triggered
with the help of trigger pins attached to Arduino board and distance is
calculated. Further working of the circuit completely depends upon the
distance measured.

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

See how Googl


offline, in-store

Google Maps Platform

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.

Related Post: Smart Irrigation System – Circuit Diagram and


Code

Project Source Code & Explanation


In this sketch, we have defined five variables of integer type and four of
long type. Variables tr1, tr2, eh1 and eh2 are used to send pulse and
receive value of time in microseconds while variables val1, val2, dis1 and
dis2 are used to store values of time in microseconds and distance in cm.

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.

const int tr1 = 13, eh1 = 12, tr2 = 3, eh2 =


2;;
int bz = 11;
unsigned long val1, dis1, val2, dis2;
#include
Servo myservo1;
Servo myservo2;
int pos=-1;

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);
}

As per the required functioning, we continuously measure the distance by


triggering the ultrasonic sensor and computed distance is set as the
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 11/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code

parameter of conditional statement. If condition is found to be true then


variable “pos” increments its value to run the servo motors and when
condition is found incorrect then “pos” variable decrease its value to bring
back the servo motors to their previous position.

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;

   if(dis1 < 100 || dis2 < 100)


{digitalWrite(bz, HIGH);
Serial.println(“distance2 is “);
Serial.println(dis1); Serial.println(dis2);} }
else if(dis1 >= 100 && dis2 >= 100)
{ if(pos==91){
   for (pos = 90; pos >= 0; pos -= 1) {
myservo1.write(pos);
myservo2.write(pos);
delay(15);

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:

Automatic Doorbell with Object Detection By Arduino


Automatic Night Lamp Using Arduino
Arduino PWM Programming and its functions in Arduino
Arduino Serial: Serial Communication by Arduino
Electronics Final Year Projects Ideas List
Electronics Engineering Project Ideas for Engineering Students
Simple and Basic Electronics Mini Project Ideas for Beginners

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

See how Googl


offline, in-store

Google Maps Platform

 Tags ARDUINO UNO Automatic Railway Gate Control System

Electronics Engineering Project HC-SR04 Railway Gate Control Circuit Servo Motor

Ultrasonic Sensor

SHOW ALL COMMENTS

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

Predict delivery with accurac

Build improved solutions with Google Map


fleets

Google Maps Platform

Basic Electronics Control Electrical Design Electronics

Electronics Engineering Project How To

Electronic Relay Switch Circuit – NPN,


PNP, N & P Channel Relay Switches
 Electrical Technology 4  9 minutes read

Checkouts

Get started wit


to make checko

Google Maps Platform

Electronic Relay Switch Circuit Diagram and Its Working


There are a variety of electrical and electronic devices which are
classified as Output devices such devices are used to control or operate
some external physical process of a machine or device. These output
devices are commonly called Actuators.
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 16/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code

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.

Click image to enlarge

Electronics Engineering Project Electronics LED How To

LED Roulette Circuit Diagram using


555 Timer & 4017 Counter
 Electrical Technology 3  7 minutes read

Table of Contents

Maps Platform for


developers

Flashing LED Roulette Circuit Diagram using 555 Timer &


4017 ICs
There is a casino game and a French word accompanying it called
“Roulette”. This circuit resembles the functioning of a Roulette wheel
game, hence
1. What the name Relays?
are Electrical given to it. This circuit consists of a timer IC and a
special IC called CD 4017,
2. Electromechanical which is a decade counter.
Relays:
https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 17/18
12/6/22, 2:57 PM Automatic Railway Gate Control System – Circuit & Source Code

2.1. Construction of Electromechanical Relay


Related
3. Solid Post:
State Simple LED Flashing Circuit using 555 Timer IC
Relay:
4. NPN Relay Switch Circuit:
5. PNPofRelay
Table Switch Circuit:
Contents
6 N-Channel Relay Switches Circuit:
1 LED R l tt Ci it Di

https://www.electricaltechnology.org/2020/04/auto-railway-gate-control-circuit-source-code.html 18/18

You might also like