Here's a complete Arduino Uno project to simulate an H0 scale model railway semaphore with 2 arms, including movement simulation and fading out effects. This is great for model railroading enthusiasts or hobbyists working on automation.
Control two servo motors simulating the movement of a railway semaphore with two signal arms, using smooth transitions and fading animations.
🔧 Hardware Requirements:
Arduino Uno
2 x Micro Servo Motors (e.g., SG90)
Jumper wires
Breadboard
Optional: LED for light indication
Optional: Potentiometer (to control speed manually)
🧠 Concept Overview:
A semaphore signal typically has one or more arms that move between positions:
Horizontal (Stop) – red light or arm visible.
45° Downward (Proceed) – green or no arm shown.
We will simulate this behavior by rotating two servos simultaneously from one position to another with a fade effect, which can be simulated via:
Gradual servo movement.
Optional LED fading if lights are included.
📜 Code (Arduino Sketch)
cpp
#include <Servo.h>
// Define servos
Servo leftArm;
Servo rightArm;
// Positions
int stopPosition = 0; // Horizontal (stop)
int proceedPosition = 60; // 45 degrees downward (proceed)
// Timing variables
int fadeSpeed = 15; // ms delay between steps (smaller = faster)
int holdTime = 3000; // time in each position (ms)
void setup() {
// Attach servos to pins
leftArm.attach(9);
rightArm.attach(10);
// Start at "Proceed" position
leftArm.write(proceedPosition);
rightArm.write(proceedPosition);
delay(2000);
}
void loop() {
// Move to Stop position
moveBothServos(stopPosition);
delay(holdTime);
// Move to Proceed position
moveBothServos(proceedPosition);
delay(holdTime);
}
// Smooth movement function
void moveBothServos(int targetAngle) {
int currentLeft = leftArm.read();
int currentRight = rightArm.read();
while (currentLeft != targetAngle || currentRight != targetAngle) {
if (currentLeft < targetAngle) currentLeft++;
else if (currentLeft > targetAngle) currentLeft--;
if (currentRight < targetAngle) currentRight++;
else if (currentRight > targetAngle) currentRight--;
leftArm.write(currentLeft);
rightArm.write(currentRight);
delay(fadeSpeed);
}
}
🔌 Wiring Instructions:
Component
Pin on Arduino
Left Arm Servo
D9
Right Arm Servo
D10
Servo GND
GND
Servo VCC
5V
Make sure your servos don't draw too much current from the Arduino. If they cause resets, power them externally with a common ground.
🖥️ Optional: Add LED Fading Effect (for realism)
If you want to add LEDs to simulate signal lights (red/green), you can connect LEDs to PWM pins and use analogWrite() to simulate fading in/out along with the servo motion.
Example:
cpp
int redLEDPin = 5;
int greenLEDPin = 6;
void fadeLights(int start, int end, int duration) {
for (int i = start; i <= end; i++) {
analogWrite(redLEDPin, i);
analogWrite(greenLEDPin, 255 - i);
delay(duration / 256);
}
}
Call this inside moveBothServos() to sync lighting with movement.
🧪 Simulation Tip:
You can simulate this behavior in software using tools like:
Tinkercad Circuits (online simulation)
Fritzing + code upload
Processing IDE (for graphical simulation)
✅ Enhancements You Can Add:
Use potentiometers to control fade speed or signal timing.
Add push buttons to simulate train detection.
Use a real-time clock (RTC) module for timed signaling.
Integrate with a full layout using multiple signals.
📦 Summary
This project brings realism to a model railway layout using simple components and smooth animation techniques. It’s ideal for beginners and offers many ways to expand functionality.