The document describes an automatic control system for railway gates at level crossings. It uses infrared sensors to detect arriving and departing trains and control opening and closing gates via a motor. When the first IR sensor detects a train, traffic signals turn yellow and a buzzer activates. When the second sensor detects the train, signals turn red and the motor closes the gates. The gates reopen when the third sensor detects the train has passed. The system prevents accidents by automating gate operations instead of relying on human gatekeepers. It also uses additional sensors to detect obstacles on the tracks that could prevent gate closure.