Home Back Story Track Plan Progress... Electricals... Buildings... Arduino... Links...

A Basic Level Crossing…

Most crossings will have either two or four gates. Frequently the four gate version will be more complicated with respect to the timing of the motion than will the two gate version. However, since we are only going to consider the very basic program structure needed to make things happen, I will be considering a two gate crossing here.

So, what do we need to make happen:
1) Detect the approach of a train.
2) Warn road traffic that the gates are about to close.
3) Wait for road traffic to clear the crossing.
4) Move the first gate to the ‘closed to road traffic’ position.
5) Move the second gate to the ‘closed to road traffic’ position.
6) Detect that the train has passed through the crossing.
7) Move the first gate to the ‘closed to rail traffic’ position.
8) Move the second gate to the ‘closed to rail traffic’ position.
9) Remove road traffic warning.

(The above assumes that the gates will be moved one at a time. While it is possible to move the gates at the same time, it does become a little more complicated to program.)

Now, looking at the connections to the Arduino:
‘A’ an input that detects if there is a train approaching.
‘B’ an input that detects that the train has passed.
‘C’ an output that drives a servo to operate gate 1.
‘D’ an output that drives a servo to operate gate 2.
‘E’ an output that drives the warning lights for the road traffic.

So, now let’s re-write the above list of requirements as a sort of pseudo computer code:

(we will use the numbers assigned above as our reference)
1) If input ‘A’ is ‘low’ – go to 1, if input ‘A’ is ‘high’ go to 2.
2) Send a continuing train of pulses to ‘E’.
3) Pause for a few seconds.
4) Send an ‘angle’ instruction to ‘C’ to move gate 1 to ‘closed to road traffic’ position.
5) Send an ‘angle’ instruction to ‘D’ to move gate 2 to ‘closed to road traffic’ position.
6) If input ‘B’ is ‘low’ – go to 6, if input ‘B’ is ‘high’ go to 7.
7) Send an ‘angle’ instruction to ‘C’ to move gate 1 to ‘closed to rail traffic position’.
8) Send an ‘angle’ instruction to ‘D’ to move gate 2 to ‘closed to rail traffic position’.
9) Stop sending pulse train to ‘E’.

As you can see, we have made use of 5 input/output pins on the Arduino. An Arduino Mega has over fifty input/output pins available.

What else could you be doing with it at the same time as controlling a crossing gate?
How about, just as an example, controlling a few points, again using a servo, in slow fashion. You could actually drive many points from a single Mega at a much lower cost than any of the slow motion point motors available.
You could drive colour light or mechanical signals. This could be done in conjunction with detector circuitry to automate the entire procedure.
You could use it, in conjunction with a stepper motor, to operate a turntable with perfect accuracy
And loads more things…..
The ideas above include gates operated by servos and a turntable which would be driven by a stepper motor. I am currently involved with some experiments using servos. I have not used a stepper with my Arduinos - yet!

What is Arduino?

Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message and many more options - and turn it into an output - activating a motor, turning on an LED, publishing something online etc. You can tell your board what to do by sending a set of instructions to the micro controller on the board. To do so you use the Arduino programming language (based on Wiring - a sort of a subset of C), and the Arduino Software IDE (based on Processing).

It is actually very difficult to interface with the physical world using only a PC (ok, or a Mac). The Arduino, in one of its many guises, can step up and become that missing interface.

When I first started to implement my long held wish to have a model railway, I had been involved for a while with hobby robotics. I quickly realise that there were a lot of places where the two pastimes overlapped. I had been using Arduino boards in my robotic platforms so I knew a little about the programming of them and about their capabilities.

But wait, what can this chunk of electronics really do that can't be done with a few switches? Well, not a lot really - but, it does it so very elegantly!

This section of the site is not going to become a full scale Arduino teach-in. There are a huge variety of sources that are better suited to that than what I have here. I’ll list a few of those in the ‘links’ section for those who are interested.
What I will do, however, is show the basic breakdown of a simple Arduino program and the essence of how it works. I should say here, for some unknown reason an Arduino program is referred to as a ‘sketch’ – don’t ask, I don’t know, but it annoys me. Grrrrr.

I am not any kind of an expert programmer and what I intend to show is simply the approach that I take to using Arduino as a peripheral controller. The eventual program will not be here, well, not yet anyhow. Just enough to let a reader decide if they want to take the idea of using an Arduino any further.

Next Page... Previous Page...

Copyright © 2016 Zog Trains.
All rights reserved.
Contact zogbertsplod@zogtrains.com


Servo experiments......