This document describes an automatic railway gate crossing and track switching system using a microcontroller. It aims to improve safety by preventing collisions through anti-collision techniques and automatic control. Sensors are used to detect train positions and speeds in order to calculate the timing of automatic gate closure and track switching. The system is designed to avoid both head-on and rear-end collisions through predictive position sensing and switching trains to alternate tracks when collisions are detected.