Creating a Functioning Mini Railway Crossing
by jacobHIM in Circuits > Arduino
23 Views, 0 Favorites, 0 Comments
Creating a Functioning Mini Railway Crossing
Welcome to my submission for the "Make It Move" contest! For this project, I designed and built a Mini Railway Crossing that uses 3D-printed parts and an interactive electronic circuit to simulate the functionality of a real-world railway crossing. The project combines mechanics, electronics, and programming to bring a functional and visually engaging model to life.
The system operates as follows:
- Magnetic Reed Switch: Detects the presence of a magnetic object (representing a train) on the tracks.
- Servo Motor: Controls the movement of the crossing gate, lowering it when the train is detected and raising it once the train has passed.
- Small Red LED Lights: Enhances the realism by warning of an approaching train, flashing while the gate is down.
The moment a magnetic object enters the track, the reed switch triggers the sequence: the servo motor lowers the gate, and the red lights begin to flash. Once the train is removed, the gate lifts, and the lights stop flashing when the crossing reopens completely.
This project not only demonstrates how 3D printing can bring mechanical designs to life but also highlights the integration of basic electronic components for dynamic motion and interactivity. Whether you're an enthusiast of model trains, robotics, or interactive design, this mini railway crossing is an exciting and accessible project to try! Let’s dive in and make it move!
Supplies
Below is a comprehensive list of all the materials and tools you'll need to build the Mini Railway Crossing:
- 3D Printing Equipment
- 3D Printer and Compatible Filament (to print pieces)
- Electronic Components
- Servo Motor (SG90 or similar, 1 unit)
- Magnetic Reed Switch (1 unit)
- Red LEDs (2 units)
- Resistor (1 unit)
- Wires
- Microcontroller (Arduino Uno)
- Breadboard
- Computer with Arduino and Fusion 360 Installed (for coding functionality and designing 3D pieces)
- Magnetic Object
- Small Magnet (to simulate the train)
- Additional Materials
- Superglue (for combining 3D printed pieces)
- Small screw (to mount 3D printed part to servo motor)
- Tools
- Small Screwdriver (for screws and clearing 3D printing structural support)
- Ruler or Caliper (for precise measurements of parts)
This list covers everything needed to build, assemble, and program the Mini Railway Crossing. Be sure to gather all the supplies before starting to ensure a smooth workflow!
Assemling Wiring for Circuit
In this step, we’ll wire the components necessary for the railway crossing to function as intended. The wiring will connect the servo motor, magnetic reed switch, and red LEDs to the Arduino. Below is a description of how to set up each component:
Components and Pin Connections:
- Magnetic Reed Switch:
- Connect one leg of the reed switch to digital pin 2 on the Arduino.
- Connect the other leg to GND.
- Servo Motor:
- Connect the signal wire of the servo to digital pin 9.
- Connect the power wire to 5V on the Arduino.
- Connect the ground wire to GND.
- Red LEDs (Flashing Lights):
- Connect the positive leg (longer leg) of one LED to digital pin 7.
- Connect the positive leg of the second LED to digital pin 8.
- Connect the negative legs of both LEDs to separate resistors, then to GND.
Wiring Diagram Overview:
- Reed switch: Pin 2 → GND
- Servo motor: Pin 9 → 5V → GND
- LEDs: Pins 7 & 8 → Resistors → GND
Once the wiring is complete, our circuit will be ready to detect a magnetic object, trigger the servo motor to move the gate, and activate the flashing LEDs. Double-check all connections to ensure proper functionality and to avoid short circuits!
Writing Code for Circuit Functionality
In this step, we'll program the Arduino to control the Mini Railway Crossing. The code integrates the magnetic reed switch, servo motor, and red LEDs, enabling the system to simulate a functional railway crossing. Here's a breakdown of the code and its functionality:
Key Components of the Code:
- Libraries and Variables
- The Servo.h library is included to control the servo motor.
- Variables are defined to store the pin numbers for the reed switch and LEDs, and to track the servo motor's position (pos).
- Setup Function
- The setup() function initializes the reed switch and LED pins.
- The servo motor is attached to pin 9.
- Serial communication is also initialized for debugging.
- Loop Function
- The loop() continuously checks the state of the magnetic reed switch using digitalRead().
- If the reed switch detects a magnetic object (train), the following happens:
- Flashing LEDs: The LEDs connected to pins 7 and 8 flash alternately to simulate warning lights.
- Gate Movement: The servo motor lowers the gate (from position 90 to 0).
- Once the magnetic object is removed, the sequence reverses:
- The servo motor raises the gate (from position 0 to 90).
- The LEDs stop flashing.
- Smooth Servo Movement
- The gate movement is controlled using incremental adjustments to the servo's position. This ensures smooth and realistic motion of the crossing gate.
- LED Flashing Sequence
- The LEDs alternately turn on and off with a delay of 250 ms, mimicking real railway warning lights.
Uploading the Code
- Copy the provided code into the Arduino IDE.
- Connect your Arduino to your computer via USB.
- Verify and upload the code to the Arduino.
Once uploaded, the system will automatically detect a train using the reed switch, lower the gate, and activate the warning lights. When the train leaves, the gate will rise, and the lights will stop flashing. This step brings the Mini Railway Crossing to life!
Modelling the Servo Motor
In this step, we’ll focus on accurately modeling the servo motor to ensure it fits seamlessly with the 3D-printed components of the Mini Railway Crossing. Proper modeling is crucial for designing the mounting brackets and aligning the servo with the crossing gate mechanism.
Process:
- Measuring the Servo Motor
- Use a caliper or ruler to measure the dimensions of the servo motor (e.g., length, width, height).
- Pay special attention to the location of the mounting holes and the arm’s position.
- Record the measurements for precision in modeling.
- Creating the 3D Model
- Using 3D modeling software (e.g., Autodesk Fusion 360, Tinkercad, or SolidWorks), create a simple 3D model of the servo motor based on your measurements.
- Include key features such as the body, mounting holes, and servo arm for alignment purposes.
Purpose of the Model:
The 3D model will serve as a reference for designing and testing the assembly of the railway crossing gate. It ensures that the servo motor integrates smoothly with the other components, providing reliable and accurate movement for the gate.
Once the model is complete, you’re ready to move on to designing the mounting bracket and assembling the mechanical components!
Designing the Motor Encasings
In this step, we’ll design an encasing to securely house the servo motor and provide space for the necessary wiring. The encasing ensures that the motor stays in place during operation while keeping the wires organized and protected.
Process:
- Referencing the Servo Motor Model
- Use the 3D model of the servo motor created in Step 3 as a reference.
- Ensure the encasing fits snugly around the motor without obstructing its movement or the servo arm.
- Designing the Encasings
- Create a rectangular shell in your 3D modeling software with internal dimensions slightly larger than the servo motor for a precise fit.
- Add slits at the top for the red LED lights
- Add cutouts or channels around the encasing for the servo motor’s and lights' wires to pass through without strain.
Purpose of the Encasings:
The motor encasing not only protects the servo motor and its wiring but also ensures a clean and organized build. This step is essential for maintaining the durability and functionality of the Mini Railway Crossing.
Once the encasing is designed, the main motor component will be completed.
Designing the Base and Rails
In this step, we’ll design the base and rails for the Mini Railway Crossing. The base serves as the foundation for the entire project, providing stability, wiring, space for the magnetic reed switch, and a plate for the motor encasing to stand on. The rails add a realistic touch.
Process:
- Designing the Base
- Create a rectangular base in your 3D modeling software, ensuring it’s large enough to support the servo motor encasing, the reed switch, and any other components.
- Include cutouts or channels in the base for neatly routing the wiring from the motor, LEDs, and reed switch to the microcontroller.
- Add a mounting slot for securing the motor encasing in place.
- Incorporating the Rails
- Model rails on top of the base to simulate a railway track and a cutout in the base for them.
- Ensure the rails are evenly spaced.
- Positioning the Magnetic Reed Switch
- Add a small slot or recess in the base, located underneath the rails, to securely hold the magnetic reed switch. This ensures the switch is properly aligned to detect the magnetic object as it passes over the track.
Purpose of the Base and Rails:
The base provides a stable structure for all components, while the rails add functionality and realism to the project. The spacing for wiring and the reed switch ensures that the system operates efficiently without clutter or interference.
Once the base and rails are designed, the overall structure of the project will be completed.
Designing the Arm and Head
In this step, we’ll design the key visual and functional components of the Mini Railway Crossing: the arm, the head for the motor encasing, and the iconic railway crossing sign in the form of a cross. These parts bring the project to life, replicating the look and movement of a real railway crossing.
Process:
- Designing the Arm
- Create a long, narrow arm in your 3D modeling software, similar to the gate arms used in real railway crossings.
- Add a mounting hole or slot at one end of the arm that fits snuggly onto the motor. This allows the arm to move up and down as the motor rotates.
- Designing the Head (Cap)
- Model a cap that fits over the servo motor encasing, closing te opening.
- Add a face where the cross can be glued onto.
- Designing the Cross
- Create a simple cross-shaped sign resembling the ones found on real railway crossings.
Once these components are designed, you’re ready to 3D print them and assemble the final parts of your Mini Railway Crossing!
3D Printing and Assembling
Now for the fun part—bringing everything together! In this step, we’ll 3D print the parts you’ve designed and assemble the mini railway crossing. By combining the printed components with the electronic circuitry, you’ll complete the project and see it in action.
Process:
- 3D Printing the Parts
- Export your designs as STL files and load them into your 3D printing software.
- Choose appropriate print settings, such as layer height, infill percentage, and material type (e.g., PLA or ABS).
- Print the following parts:
- Top motor encasing
- Bottom motor encasing
- Base
- Rails
- Arm
- Head (cap)
- Railway crossing sign (cross)
- Post-Processing
- Once the prints are complete, carefully remove them from the printer bed.
- Clean up any rough edges or supports using sandpaper or a utility knife for a smooth finish.
- Assembly
- Start by attaching the servo motor to its encasing and securing it to the base.
- Install the magnetic reed switch in its designated slot on the base.
- Mount the arm to the servo motor.
- Glue the railway crossing sign to the encasing.
- Glue the head (cap) onto the motor encasing.
- Integrating Electrical Components
- Carefully route and connect the wiring for the servo motor, LEDs, and reed switch.
- Use tape or zip ties to keep wires organized and prevent them from interfering with moving parts.
- Final Test
- Power up the system and test its functionality. The arm should move up and down when the magnetic object (train) is detected, and the LEDs should flash as the gate lowers.
And with that, we’re finished!
Your mini railway crossing is now complete, ready to simulate a real-world railway crossing with its functional gate and warning lights. Enjoy showing off your creation and experimenting with its operation!