Go Down

Topic: model railway signalling (Read 538 times) previous topic - next topic


This is the story so far...


My thanks to everyone who answered my questions.

work continues...

Saddo railway nerd (65yrs)


My thanks to everyone who answered my questions.
What questions?

Why isn't this posted along with the questions?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Nice video, the signals look good.

Looks like you have an upper track as well, so expect you have plenty more coding /signals to do.


Nice video, the signals look good.

Looks like you have an upper track as well, so expect you have plenty more coding /signals to do.
Thanks v much

the bulk of the set-up is done now.

It's just a question of duplicating hardware (signal heads) and software (arduino subroutines).

Next step is to attempt semaphores using servos.   Expect I'll be back with more dopey questions.

(and finding other uses for the arduino)
Saddo railway nerd (65yrs)


This may be of use to You. I developed it to change my points via servo but it would also work for semaphore signals. Summary of function is at the top. :)

Code: [Select]
/*This sketch is designed to operate Model Railway Points that are driven by Servo Motors
 *A SPDT switch connected to + and - 5vDC with the centre tap going to an Input Pin.
 *This will scan a predefined set if Pins and allocate as INPUT then set them LOW.
 *Dependant on the PIN STATE and whether or not it has changed it will rotate a SERVO on the active pin
 *to a pre-determined location as set out in the SERVOMIN/SERVOMAX arrays.
 *Millis() function has been used to streamline the operation.
 *Serial.print can be removed, they are just for checking.
 *Machine:- UNO R3 and 16 Servo Controller
 *Created by Doug Reed 10/05/2016
 *My thanks to the Forum Members who pointed me in the right direction.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

unsigned long previousMillisSWITCH=0;                                         //Button Millis() setup
int intervalSWITCH = 20;                                                      //intervals for millis()

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();                      // called this way, it uses the default address 0x40

unsigned  int SERVOMIN[11] = {172,172,172,246,246,172,246,200,200,150};       //servo lower setting to suit individual servo
unsigned  int SERVOMAX[11] = {565,530,500,492,492,565,492,550,550,525};       //servo upper setting to suit individual servo                                 
int InPin[11] = {2,3,4,5,6,7,8,9,10,11,12};                                   //array of input pins
int PinCount = 11;                                                            //the number of pins used, lenght of array
int Dir = 0;
int OldDir[11];
int NewDir[11];
int thisPin;
int degrees;

void setup() {
    pwm.setPWMFreq(60);                                                       // Analog servos run at ~60 Hz updates
   for (int thisPin = 0 ; thisPin < PinCount ; thisPin++) {                   //"thisPin" is array position                                           
      pinMode(InPin[thisPin],INPUT);                                          //sets all pins 2 -12 as INPUT
   for (int thisPin = 0 ; thisPin < PinCount ; thisPin++) {
      digitalWrite(InPin[thisPin],0);                                         //sets all pins 2 -12 to LOW

    Serial.print("   InPin  ");                                               //displays the STATE of the PIN
      int p = digitalRead(InPin[thisPin]);
    Serial.print("   State  ");
void loop() {
    unsigned long currentMillis = millis();                                           // get current time stamp, only need one for all if-statements
    if ((unsigned long)(currentMillis - previousMillisSWITCH) >= intervalSWITCH) {    // time between button presses
    for (int thisPin = 0 ; thisPin < PinCount ; thisPin++) {                          //assess the direction settings
        Dir = digitalRead(thisPin+2);
        OldDir[thisPin] = NewDir[thisPin];
            Serial.print("    Dir    ");
    if ((Dir == 1) && (OldDir[thisPin] == 0)){
        for (uint16_t pulselen = SERVOMIN[thisPin]; pulselen < SERVOMAX[thisPin]; pulselen++) {
            pwm.setPWM(thisPin, 0, pulselen);
            Serial.print("    HIGH    ");
         NewDir[thisPin] = 1;
    if ((Dir == 0 ) && (OldDir[thisPin] == 1)) {
        for (uint16_t pulselen = SERVOMAX[thisPin]; pulselen > SERVOMIN[thisPin]; pulselen--) {
            pwm.setPWM(thisPin, 0, pulselen);
            Serial.print("    LOW    ");
         NewDir[thisPin] = 0;
previousMillisSWITCH = currentMillis;


Very cool!! Good work. I'm working on a controller for my layout too using Arduino, so much fun.


Sorry for the long delay...I have the controller side pretty much worked out, am just waiting on a sound card to add engine sound, at this stage either from within the hand controller or as a type of surround sound, not sure until i can get the sound card working. If you haven't already, have a look at adding a 1602 LCD to your controller, that way you can add/adjust various features as you need to or just see what the controller is doing.

hope your project is going well.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131