Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560 Controlled Railway Crossing with Servo Barriers and Audio Alerts

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Controlled Railway Crossing with Servo Barriers and Audio Alerts

Circuit Documentation

Summary

The circuit in question appears to be a complex system involving an Arduino Mega 2560 microcontroller as the central processing unit. It interfaces with various components including servos, a DFPlayer Mini MP3 module, a loudspeaker, a real-time clock (RTC DS3231), a 3.5" TFT LCD Shield, and several pushbuttons and LEDs for user interaction and feedback. The circuit is likely designed for a model railway crossing with light signals and barrier control, featuring sound playback capabilities and a display for user interface or status information.

Component List

Microcontroller

Audio Components

Display

Sensors and Actuators

Power Supply

User Interface

Miscellaneous

Wiring Details

Arduino Mega 2560

DFPlayer Mini

Servos

RTC DS3231

3.5" TFT LCD Shield

Pushbuttons and LEDs

Resistor

Octocoupler

Documented Code

The code provided is for the Arduino Mega 2560 microcontroller and is written in C++ using the Arduino IDE. It includes libraries for controlling the servo motors (Servo.h), interfacing with the TFT LCD (MCUFRIEND_kbv.h, Adafruit_GFX.h), managing the real-time clock (RTClib.h), and controlling the DFPlayer Mini (DFRobotDFPlayerMini.h). The code is structured to manage a model railway crossing with light signals and barrier control, featuring sound playback capabilities and a display for user interaction or status information.

The code is organized into several functions and states to handle the railway crossing logic, including signal light control, barrier movement, and sound playback. It also includes functions for displaying messages on the TFT LCD and handling button presses.

The main loop (void loop()) cycles through different states of the railway crossing, such as detecting an approaching train, securing the crossing by activating lights and barriers, and eventually reopening the crossing once the train has passed. The code uses a state machine approach with enumerated types (Status0 and Status1) to manage the crossing's status and transitions between states.

The setup function (void setup()) initializes the hardware components, sets pin modes, and establishes communication with the DFPlayer Mini and RTC. It also sets the initial state of the crossing and displays a startup message on the LCD.

The code includes error handling for component initialization, such as checking if the RTC is found and if the DFPlayer Mini is successfully initialized. If any component fails to initialize, the system continues to operate with limited functionality (e.g., without sound).

Throughout the code, there are informative comments and serial print statements to aid in debugging and provide real-time feedback on the system's status.


Note: The actual code is not included in this document due to its length, but it is summarized to provide an understanding of its functionality and structure.