Introduction: Railway Signal Simulation

Traffic light for railways.

(Simulation of reality)

A simple explanation of the code:

The code allows for a constant sensory for trains. If a train is to pass through the selected section of the railroad, the traffic light will turn red, warning others of danger ahead. At about 10 seconds later, the light will turn yellow, advising for caution for passing drivers. Only 20 seconds after turning yellow will it turn green, meaning it’s completely safe to pass.

With a complete circuit and the right materials, the device should be ready for use. Put it down next to a railway, and once a train passes by, watch it go into action!

Note: This is for simulation purposes only, and is not meant to be applied for real-life uses.

2nd Note: The device may detect the railway instead, and keep changing lights incorrectly, so perching the device on higher grounds may be necessary.

Supplies

3 lights: one for red, yellow, green.

Arduino Uno (Leonardo works too, I used Leonardo for this example.) Cardboard (Best to use a box that you already have).
3 resistors.

An ultrasonic sensor

Trains (with batteries already inside so that it can run.)

Rail tracks suitable for the train.

Step 1: Step 1: Circuit

This is a rendition of the circuit. A few things to note.

The ultrasonic sensor that I used actually has four ports. Trig and Echo are separated. So remember to put Trig in an analog pin (D6) and Echo in another pin (D7) if your ultrasonic sensor is the same model.

Step 2: Step 2: Program

Here is the program. There is actually a large portion of the code that is not used from when I had other ideas for the device. I'll give you an insight into what's important in the comments.

https://create.arduino.cc/editor/Nori456/f7b935dd-e481-4a60-9002-8522b78aedc1/preview

Step 3: Step 3: Decoration

SImply encase the circuit, computers, and machinery into something that shields and covers the delicate electronics. A box shape would do.

Remember to leave openings for the lights, the sensor, and the wire for the Arduino board itself.

The decoration is optional. Consider adding whatever you want to the device!

Also, make sure that everything in the circuit works. All three lights work here as shown in the images.

Step 4: Step 4: Put It to Work!

That's it! Hopefully, the device works on its own. If there is a problem, consider checking the circuit, wires, or electronics to see if there is any problem with any of these. Enjoy.

Here is a link to a video that shows the device in action. Use it as an example: https://www.youtube.com/watch?v=lTxeWCMHB4I