Introduction: Railroad Control and Speed Measurement (Arduino)

Railroad Control and Speed Measurement

Nathan Bearden, William Morgan, Son Quang

Since there are many add-ons to use for the Arduino board and MATLAB to control and analyze the SMART RAIL system, it was difficult to choose. After doing some research, we decided to focus on power control, lighting control, and analyzing parameters of the train. Our team chose to use two inputs and three outputs: the button to control the power and the LED, and the signal from Emitter Detectors to calculate the speed of the train. This Instructable will show you how to setup a system to start a train and measure the speed of the train.

Step 1: Parts and Materials

Arduino Board

Double-ended wires

10K Ohm resistor

Blue LED light

330 Ohm resistor

Infrared Emitter and Detector




Transistor P2N

Laptop installed with MATLAB R2017a and Arduino add-on

Step 2: Problem Statement

We used a button to start the train and also turn on the LED to let the user know that the train is running. The second input is the signal from the Emitter Detector. When the train starts to pass the detector, a time counter will start and the timer will stop when the train pass through. The time will be used to calculate the speed with the length of the train, which was measured. The equation we used to find the velocity was:

velocity = time/length

Step 3: Design Your Circuit

This shows how the button, light, and other components are wired in the circuit. The open wire green will connect to the power source, and the open white wire will connect to the track.

Step 4: Coding


configurePin(a, 'D10', 'pullup') %Configures the button to read as "0" when pressed.

while 1 %While the button is idle.

button = readDigitalPin(a, 'D10');

if button == 0

writeDigitalPin(a,'D3',1); %Power the circuit (Start the train and LED).





%IR Sensor test code

voltage= readVoltage(a,'A0'); %When the train passes through, the voltage spikes

if voltage < 1



time_end = toc;

end end length = 6.75; %inches speed = length./time_end;

fprintf('The train is moving %6.2f inches/second', speed);

When the button is hit, a signal will be sent to the D10 port. When the program receives the signal from D10, it will power the circuit and the LED. When the train starts, it will drive until it passes through the detector. When the train begins to pass through the detector, the program will start a time counter which will stop when the train has completely exited the detector. By using the time it takes to pass through, we use MATLAB to calculate and display the speed at which the train was moving.

Step 5: Controlling the Train

Because we use the button to control the power of the rail, we had to connect one end of

the power source to the Arduino board and from the Arduino board to one rail of the track. The other end of the power source is then wired to the other rail of the track. We used a 3D printed part designed in in SOLIDWORKS to hold the Infrared Emitter and Detector. Alligator clips were ran from the Arduino board to the sensors in order to control them.

Step 6: Conclusion

We had many challenges when creating this project, including the coding and wiring of the circuit. We overcame these problems by researching and from help from our Teacher's Assistants. One problem that we still experience is that the detectors are crooked sometimes and cannot detect the train. By adjusting it, however, we were able to make the detectors work. This could be solved by making the holes in the 3D printed part a little smaller. We had a lot of fun making the circuit and creating codes, and we also learned a lot from this experience.