Skip to main content
Version: FILS English

Project Name

Railway Simulator

info

Author: Turcu Mihai Alexandru
GitHub Project Link: https://github.com/UPB-PMRust-Students/project-mihai-alex-71

Description

This project is a railway crossing simulator developed using the Rust programming language and two Raspberry Pi Pico 2 microcontrollers—one dedicated to system control and the other used as a debugger. The system employs two ultrasonic proximity sensors to detect the approach and passage of a train. When a train is detected, servo motors lower the crossing barriers, and both a light and sound signal are activated to warn nearby pedestrians and vehicles. The motion sensors are also used to estimate the speed of the train, based on the number of cars it consists of. This simulation offers a simple yet effective way to demonstrate how real-world railway safety systems operate.

Motivation

The goal of this project was to simulate a real-world railway crossing system using low-cost and accessible hardware. By combining Rust's performance and safety features with the versatility of the Raspberry Pi Pico 2, I aimed to deepen my understanding of embedded systems, sensor integration, and real-time control. This project also allowed me to explore practical applications of automation in transportation safety.

Architecture

Schematic diagram

  1. Train Detection Module Function: Detects whether a train is approaching or has passed using two ultrasonic sensors placed at different points on the track. Output: Sends proximity data to the Control Module.

  2. Speed Estimation Module Function: Calculates the speed of the train and estimates the number of cars based on the time difference between the sensor triggers. Input: Data from both ultrasonic sensors. Output: Speed and train state (e.g., "approaching", "passed") sent to the Control Module.

  3. Control Module Function: Core logic running on the main Raspberry Pi Pico 2. It processes sensor data, calculates train speed and state, and controls all other modules. Input: Proximity and speed data, joystick input. Output: Sends display data to the OLED Display Module Sends actuation commands to the Barrier & Signal Module Communicates system state to the Debug Module

  4. Barrier & Signal Module Function: Controls the crossing barriers (via servo motors), LED warning lights, and acoustic buzzer. Input: Commands from the Control Module or manually from the Joystick.

  5. OLED Display Module Function: Displays current system status: Train state (e.g., "no train", "approaching", "passing") Estimated speed Barrier state Input: Data from the Control Module via I2C/SPI.

  6. Joystick Input Module Function: Allows manual control of the barriers for testing or override. Input: Analog signals read by the Control Module.

  7. Debug Module Function: Logs and monitors system states and sensor values. Platform: Second Raspberry Pi Pico 2 connected to the main controller.

Connections Overview: Ultrasonic Sensors → Control Module: via GPIO (Trigger/Echo) Joystick → Control Module: via ADC (analog pins) Control Module ↔ OLED Display: via I2C or SPI Control Module → Servos/LEDs/Buzzer: via GPIO/PWM Control Module ↔ Debug Module: via UART/I2C/SPI

Log

I have focused on the research phase—reading documentation, watching tutorials to understand component wiring, and setting up the debugger on one Raspberry Pi Pico.

Week 5 - 11 May

Week 12 - 18 May

Week 19 - 25 May

Hardware

The project uses two Raspberry Pi Pico 2 boards (one as debugger), ultrasonic proximity sensors to detect the train, servo motors to control the barriers, LEDs and a buzzer for signals, an OLED display to show status and speed, and a joystick for manual control.

Schematics

Place your KiCAD schematics here.

Bill of Materials

DeviceUsagePrice
Raspberry Pi Pico WMain microcontroller for processing and control35 RON
Ultrasonic Proximity Sensors (HC-SR04)Detect train approach and passage~12 RON each
Servo Motor (SG90)Control railway barriers15 RON
OLED Display (SSD1306)Displays train status and speed25 RON
Joystick ModuleManual control of barriers10 RON
BuzzerAcoustic signal when train approaches5 RON
LEDs (Red and Green)Visual indicators for crossing status~1 RON each
Resistors (220Ω)For LEDs current limiting~0.5 RON each
Jumper WiresConnecting components~10 RON (set)
USB CablePower and programming-
Optional External Power SupplyExtra power for servo motorOptional

Software

LibraryDescriptionUsage
st7789Display driver for ST7789Used for the display for the Pico Explorer Base
embedded-graphics2D graphics libraryUsed for drawing to the display
rp-picoBoard support crate for Raspberry Pi PicoMain framework for controlling the Pico
rp2040-halHAL for the RP2040 microcontrollerControls GPIO, ADC, PWM, I2C, etc.
  1. Ultrasonic sensor guide
  2. Servo motor guide
  3. Rust Book
  4. Oled Display guide
  5. Joystick guide
  6. Tutorial