Train Crossing Monitor System




Introduction: Train Crossing Monitor System

This instructable will teach you how to use MatLab to code an Arduino to control part of a railroad system.

Step 1: Supplies

For this project you will need:


Arduino Board

Matlab 2017

3D Printer

Model Train

2 Photo Sensors

1 Blue LED Light

2 Red LED Lights

1 Servo Motor

1 Piezzo Speaker

USB Cord

3 330 Ohm Resistors

17 Female-Female Wires

3 Female-Male WIres

34 Male-Male Wires

4 Wooden Blocks

Masking Tape

Step 2: How to Set Up Your Breadboard

When we set up our breadboard we followed the diagrams in the book, modifying it a little to make sure that we were able to fit everything that we needed onto the board.

Step 3: Write Your Code

Once your board is wired and connected to your computer with the USB cord, its time to write your MatLab code. Our inputs consisted of a keyboard input to tell the program to run and photosensors that read a light and tell the program whether or not they see the light. If the light is not being read by the photosensors, then the program does a number of things. The first thing is that the program determines the speed of the train based on the time the first light sensor is blocked to when the second light sensor is unblocked, then it runs a code to determine the speed of the train and sends a message box stating whether the train is going too fast, too slow, or a good speed. Simultaneously, once the first sensor is tripped it then tells the crossbar to lower down, blink red lights, and play a sound at an annoying frequency. The program then waits a certain amount of time after the train passes the second sensor to raise the crossbar back up, stop blinking the lights, and stop the sound.

Step 4: Draw Your Crossbar

I drew the Crossbar that is to be attached to the servo motor in Onshape, but any 3D building system would work. For my dimensions I made the bar 3.5" X .2" X .5" and added a draft to one end and 'CAUTION' to both sides for appearance. I also added a hole through the bar so that we could stick the servo attachment piece through it. An important thing to note is to pay attention to the units that your 3D printer prints in and draw your crossbar in those dimensions to begin with.

Step 5: Set Up Your System and Test It!

Once you have gathered all you components, set up your Arduino, and written your code, its time to set it up and test it! For our project we set the computer in the middle of the track and our adruino an equal distance between where the lights will be and where the road crossing is. To set up our white lights and photo sensors we taped them to wooden blocks so that it would be high enough above the track for the photo sensors to read them but low enough so that they would be blocked when the train passed by. Then to set up our cross bar we attached it to the servo motor and set it in between 2 weights so that the motor would not move when the bar raises and lowers, we even taped the weights together for extra support. We then taped the red lights on either side of the road crossing.

Once our system was set up we tested to make sure everything worked correctly and made changes where we needed to.



    • Metalworking Contest

      Metalworking Contest
    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest

    2 Discussions

    i have ardino uno r3 but the ardino software cant upload gbl to ardino

    Fun project. This would make a good example tutorial for teaching Arduino inputs and outputs.