This document proposes an automatic control system for unmanned railway gates using sensors to reduce accidents. The objectives are to decrease costs by automating gates and reducing accidents through automatic closure when trains approach. The methodology uses infrared sensors to detect approaching trains and microcontrollers to signal gate motors. When a train is sensed, the system checks for vehicles near the gate before closing it, and reopens the gate once the train passes. This system could automate gates at road-rail crossings in Pakistan to improve safety.