Electromagnetic Railway Model: Amazing Micro:bit Project (2026)
DIY Electromagnetic Railway Model: Complete STEM Project Using Micro:bit, Electromagnets, and Block-Based Coding
The DIY Electromagnetic Railway Model is an engaging STEM project that demonstrates how electricity and magnetism can be combined to create controlled movement. A small model train is fitted with a permanent magnet, while electromagnetic coils are positioned along the track. A BBC Micro:bit controls the coils one after another through suitable transistor or MOSFET driver circuits. When a coil is energized, it produces a magnetic field that attracts the magnet on the train and helps pull it toward the next section of the track.
Innovation
Combines electromagnetism and Micro:bit programming to create a programmable railway propulsion demonstration. Electromagnetic coils are activated sequentially to attract a magnet attached to the model train.
Materials Required
BBC Micro:bit; Micro:bit expansion board; 3 electromagnetic coils or hand-wound copper-wire coils; 3 MOSFET/transistor driver modules; small permanent magnet; cardboard or foam-board base; craft sticks or cardboard rails; lightweight model train; external low-voltage battery pack; jumper wires; resistors as required; optional LEDs; USB cable; Microsoft MakeCode.
Learning Objectives
Understand how current through a coil produces an electromagnet.
Learn how a Micro:bit can control external electronic loads.
Understand sequential control, timing, and automation.
Practice variables, loops, conditions, and pauses in MakeCode.
Explore magnetic attraction and temporary magnetic fields.
Develop engineering, testing, and problem-solving skills.
Working Principle
Micro:bit output → Driver circuit → Electromagnet → Magnetic attraction → Train movement
The Micro:bit sends control signals to driver modules. The drivers safely switch the higher-current electromagnets using a separate power supply. The coils are energized in sequence so the train is repeatedly attracted toward the next coil.
Detailed Step-by-Step Procedure
Step 1: Prepare the Railway Base—Cut a long cardboard or foam board base and mark two parallel lines for the track. Fix craft sticks or cardboard strips as rails.
Step 2: Build the Model Train—Make a lightweight train from cardboard or a small toy carriage. Attach a small permanent magnet securely underneath it.
Step 3: Prepare the Electromagnets—Wind insulated copper wire around suitable iron cores to create three coils. Keep the two wire ends of each coil accessible.
Step 4: Position the Coils—Place Coil 1, Coil 2, and Coil 3 at different points along the track so that each energized coil can attract the train magnet toward the next section.
Step 5: Connect the Driver Circuits—Never connect electromagnets directly to Micro:bit GPIO pins. Use suitable MOSFET/transistor driver modules and a separate low-voltage supply. Connect grounds as required by the driver design.
Step 6: Connect the Micro:bit—Example control pins: Coil 1 to P0, Coil 2 to P1, and Coil 3 to P2. Optional LEDs or a start button can use additional pins.
Step 7: Create the MakeCode Program—In a forever loop, turn Coil 1 on briefly and off, pause, then activate Coil 2 and Coil 3 in sequence. Adjust timing experimentally.
Step 8: Add Start and Stop Control Button A can start the sequence, and Button B can turn all coils off.
Step 9: Test the Railway—Place the train at the starting point and power the Micro:bit and external coil supply. Observe the movement and adjust coil positions or timing.
Step 10: Improve the Model—Add station LEDs, a buzzer, a train-detection sensor, automatic stopping points, or additional railway sections.
Block-Based Coding Logic
On Start: Set all electromagnet outputs to OFF.
Forever:
1. Turn Coil 1 ON.
2. Pause briefly.
3. Turn Coil 1 OFF.
4. Pause.
5. Turn Coil 2 ON, pause, then OFF.
6. Turn Coil 3 ON, pause, then OFF.
7. Repeat continuously.
Optional: If Button A is pressed, run the sequence. If Button B is pressed, turn all coils OFF.
Expected Output
The model train moves along the track as the electromagnets are activated sequentially. The Micro:bit controls the timing of each coil, demonstrating how electrical energy creates temporary magnetic fields and controlled motion. Optional LEDs can indicate which coil is active.
Applications
STEM classroom demonstrations; electromagnetism experiments; science exhibitions; railway engineering models; robotics and automation activities; magnetic propulsion demonstrations; coding and electronics workshops; engineering design challenges.
Advantages
Combines physics, electronics, and coding; uses simple construction materials; provides a visible demonstration of electromagnetism; allows timing experiments; can be expanded with sensors; encourages problem-solving and engineering design.
Conclusion
The DIY Electromagnetic Railway Model provides a practical way to explore electricity, magnetism, programming, and mechanical motion. By controlling electromagnets with a Micro:bit, students can see how temporary magnetic fields influence a moving object. The project strengthens understanding of electromagnets while developing coding, circuit-building, testing, and engineering skills.
Frequently Asked Questions
1. What is the main idea of this project?
It demonstrates controlled train movement using electromagnets operated sequentially by a Micro:bit.
2. Why is a driver circuit needed?
Electromagnets generally require more current than a Micro:bit GPIO pin can safely provide, so a suitable driver is used.
3. What magnet is attached to the train?
A small permanent magnet can be attached underneath the lightweight model train.
4. Can more electromagnets be added?
Yes. Additional driver channels and coils can create a longer railway.
5. Can sensors be included?
Yes. Distance or other suitable sensors can detect the train and automate the system.
6. Can LEDs be added?
Yes. LEDs can indicate the active railway section or simulate station signals.

















