Train Obstacle Detection System Using Avr Microcontroller and SR04 Ultrasonic Sensor

Received Sep 29, 2017 Revised Dec 27, 2017 Accepted Jan 17, 2018 Malaysia, railway is considered as the backbone of transport, connecting people from all across the country. With the current state of economy, more people prefer to choose train as main transportation especially in big city area such as Kuala Lumpur. With lower cost and relatively the safest form of transports compared to the other transports, like cars, motorcycles or busses, it is a wise choice to use train as daily commute transport. Nowadays, the rail traffic network in Malaysia are getting busier with trains traveling at higher speeds and carrying more passengers with heavier axle loads than before. With the increase of passenger, the risk involved in daily train operation will significantly increase. An improved safety system is required to keep up with the ever growing train loads. The proposed safety system is applied to alert the train operators. The whole system is comprised of an ultrasonic sensor connected to a database and an Atmega328P microcontroller mounted on a custom PCB board. It is found that the train in this country requires a distance of 77 meter in order to completely stop the train with regards to a few assumptions on the average mass and the speed of the train.


INTRODUCTION
The problem arises when, there is an unwanted obstacle present in the train track. This will pose a great danger to the train conductor and its passenger. In a normal train operation, train conductor will scan the track ahead to ensure the track is free from any obstacle [1]. However, there is a drawback with this system, which is the concentration of train conductor can be deteriorated over time thus allowing a room for mistakes. The safety system is a design to give warn to the train conductor and control center when an obstacle is detected on the track. Furthermore, the system also control the train brakes if the train conductor fails to respond from the warning. Previous study has been conducted [2] which characterizing MRT operation in Manila to identify any problem might occur. In India, a study has been done to reduce the number of railway incidents which is about railway anti-collision system using digital single lens reflex (dslr) and ultrasonic sensor to detect the presence of obstacle on the track [3]. In Indonesia, ultrasonic sensor and Atemega 328 Arduino were used in a study to measure the ploughing depth elevation of drainage channel [4].
In this project, an ultrasonic sensor which is placed onboard of the train itself is used. The sensor is used to detect any obstacle present on the track. With a presence of any obstacle, it will send the distance of detection to the control center and if the obstacle is very close to the train, the system will cut off the train's motor power supply.Beside using ultrasonic sensor, computer aided science such as image enchancement with machine vision [5] and real time histogram oriented gradients (HOG) [6] are used for detecting distance of object. The project is aimed to be low cost, affordable and reliable solution to train operator in Malaysia, which would allow more usage of this technology in railway train infrastructure. The development of the system will also open up the possibility of implementing the invented safety system on other area which is not limited on train safety application alone.

RESEARCH METHOD 2.1. Breaking Distance Identification
For a train to stop before hitting the obstacles, it requires a certain amount of distance for the inertia of the train to be reduced and eliminated. The train stopping distance is affected by several factors such as train weight, train speed, and the track geography. In this project, we search for the minimum detection distance before the train hit the obstacle. Below is the formula used to calculate the braking distance of the train with different detection distances. Assuming constant gradient track, the braking distance can be calculated using, From the equation, "m" refers to the train mass in kg, while "a" indicates the acceleration rate while "-a" annotates for deceleration. "S" is the desired component in the equation which is the minimum braking distance. For component "U", it symbolizes the difference of the speed at which deceleration begun. "g" refers to the acceleration provided by gravity. The last component in the equation is "h1-h2" which symbolizes the difference in height (when going on slope).
There are several factors that affect braking distance of a train [7]. The factor are the train speed when the brake is applied, deceleration rate when a brake is engaged which varies according to the coefficient of friction between wheel and rail, the time delay when the brakes are issued by the train driver, and the condition of brake pads used also affect the braking performance which consequently affect the braking distance besides the last factor which is the geography of the track. In this project, scale model is used to demonstrate the detection from the ultrasonic sensor. The scale is based on 1:160 scales. The train model used is 160 times smaller than the real train. The detection range is also be scaled up to compare with the calculation produced from the formula and to match the train size. The detection range scale-up formula is given as equation (2), y x  160 1 (2) Where "x" is the scaled up ultrasonic value (x160) and "y" is the measured value directly from the ultrasonic sensor. Ultrasonic Sensor SR04 involved in this study is using wave propagation concept to measure the distance between the obstacle and the train. operational. From the timing diagram, a short 10µs pulse is supplied to trigger input to start the range of detection, the module will emit an 8 cycle burst of 40 kHz ultrasound and raise its echo. The distance of the object is measured from the echo that is proportion to width and range. The range can be calculated by using the time interval between sending trigger signal and receiving echo signal, as stated in equation 3.
In this case, measurement of a cycle of over 60 ms is recommended to prevent trigger signal to echo signal.

Implementation
The system is started when an object is detected ahead on the track, then the ultrasonic sensor will ping the particular direction, as indicated in Figure 2(a). If the sensor detects object within range below of 77 m, the microcontroller will cut off the engine power supply immediately to stop the train. If there is no obstacle detected, the train will continue its journey as normal. The ultrasonic sensor attends as an input to the microcontroller and it is used to detect the unwanted obstacle on the track and feed the data into ATmega328P as shown in Figure 2(b). ATmega328P act as source controller of open hardware usually used in various applications. It is also used with camera pixy CMUcam5 to detect the presence of objects with specific color [8] All the calculations by taking into account various conditions are implemented in ATmega328P microcontroller. The microcontroller measures the distance using the related formulas, and transmits the information to the control center via Wi-Fi (ESP8266). If the obstacle is too close for safety, the microcontroller will issue an emergency braking to stop the train immediately. At the same time, an alert will be displayed in Control Centre by using Visual Basic. The PCB board used in this project is custom fabricated using single sided PCB. The PCB routing is done by using Proteus software with T30 wire thickness in order to prevent wire disconnects during etching process. Figure 3(a) indicates the PCB layout used in this project, meanwhile Figure 3(b) shows the real fabricated PCB. For the software implementation, Arduino IDE is used as a platform to write and compile the codes. After the code is successfully compiled, then it is uploaded into the ATmega328P using Arduino bootloader. Arduino Uno development board is used as a burner to upload the code. The ATmega328P is inserted into the microcontroller slot and upload process will be begun. In the control centre, Microsoft Visual Studio is used to create a visual basic-based windows application. From the Visual Basic application created, technicians are able to monitor the train in order to sense any unwanted obstacles on the train track ahead. A database is developed within the localhost and indirectly minimizing possible error. MySQL is purposely added to create the database which will be used to store the input data obtained from the Ultrasonic Sensor (SR04). The data from the database is then fed into visual basic window application to the display segment.

RESULTS AND ANALYSIS
The detection distances from the obstacle and its tolerance comparing between ultrasonic value and theoretical value is indicated in Table 1. The average tolerance between real value and both Arduino and Database are about 4.31%, meanwhile the highest tolerance is at 2.00 cm in real value which is 9.50% tolerance and the lowest tolerance is 1.00% measured between real value and both Arduino and Database excluding the first measured value of 0.00cm from real value, Arduino and Database. For a train to stop before hitting the obstacles, it requires a certain amount of distance for the inertia of the train to be reduced and eliminated. A few factors that are affecting the train stopping distance, are train weight, train speed, and the track geography. In this study, we search the minimum detection distance before the train hit the obstacle. By assuming constant gradient track, the braking distance, S can be calculated using equation (1). In order to use this formula, a few assumptions had to be made which the method relies on some simplifying expressions as implemented in Barney et al. [7]  From the calculation, it is shown that the minimum braking distance is approximately 77m from the obstacle. In order for a train stop efficiently, the pre-set stopping distance of a train have to be more than 77m. From Table 2, between the ranges 0.00m to 70.00m the overlap status is yes, this means the train does

CONCLUSION
In conclusion, train collisions could be avoided when an effective safety applied to the system entirely. The train obstacle detection by using AVR microcontroller and SR04 Ultrasonic sensor has been studied in this project to propose the most convenient and affordable safety system into this infrastructure industries. From this project, it is clearly found that the train in Malaysia with few assumptions regarding the average mass and speed requires a distance of 77m to completely stop the train, which means the train has sufficient distance to stop if the pre-set button is applied for the distance of detection more than 77m. It is expected that the invented safety system in this research can be implemented in other train operation services includes the other infrastructures in Malaysia.