A do it your self Arduino Switch Controller for less than $16. Following
is a parts list with prices that include shipping.
Part Price
Arduino Clone $4.45
Relay Module 6.19
RS-232 Module 1.15
DC Regulator 1.53
2A Diode Bridge .25
Hookup Jumpers 2.00
Total $15.57
A breadboard was constructed per the attached schematic and the sketch
(program) was checked out.
The Arduino sketch is as follows:
// Program SC_3 David Nissen 24 Jan 2015
// Switch Control Module to work with Lionel TMCC
int output_pulse = 500; // ms, (500 = .5 sec)
int switch_A = 1; // Switch numbers do not have to be in sequence
int switch_B = 2;
int switch_C = 7;
int switch_D = 8;
int read_delay = 35;
int end_delay = 500;
void setup()
{
Serial.begin(9600);
// ========== Set pins 2-9 to output and set to HIGH (0ff)
int x = 2;
do
{
pinMode(x,OUTPUT);
digitalWrite(x,HIGH);
x++;
} while (x < 10);
// ===========================
}
void loop()
{
int byte_1 = 0;
int byte_2 = 0;
int byte_3 = 0;
int command = 0;
// ========== Loop until byte_1 is FE (254)
do
{
byte_1 = Serial.read();
} while (byte_1 != 254);
// ========== Read byte_2 and byte_3 and form 16 bit command ========
delay(read_delay);
byte_2 = Serial.read();
delay(read_delay);
byte_3 = Serial.read();
command = (byte_2 << 8) + byte_3;
// ========== Switch A straight ==========
if (command == (((switch_A >> 1) + 64) << 8) +((switch_A & 1 ) << 7))
{
digitalWrite(2,LOW);
delay(output_pulse);
digitalWrite(2,HIGH);
}
// ========== Switch A curve ==========
if (command == (((switch_A >> 1) + 64) << 8) +((switch_A & 1 ) << 7) + 31)
{
digitalWrite(3,LOW);
delay(output_pulse);
digitalWrite(3,HIGH);
}
// ========== Switch B straight ==========
if (command == (((switch_B >> 1) + 64) << 8) +((switch_B & 1 ) << 7))
{
digitalWrite(4,LOW);
delay(output_pulse);
digitalWrite(4,HIGH);
}
// ========== Switch B curve ==========
if (command == (((switch_B >> 1) + 64) << 8) +((switch_B & 1 ) << 7) + 31)
{
digitalWrite(5,LOW);
delay(output_pulse);
digitalWrite(5,HIGH);
}
// ========== Switch C straight ==========
if (command == (((switch_C >> 1) + 64) << 8) +((switch_C & 1 ) << 7))
{
digitalWrite(6,LOW);
delay(output_pulse);
digitalWrite(6,HIGH);
}
// ========== Switch C curve ==========
if (command == (((switch_C >> 1) + 64) << 8) +((switch_C & 1 ) << 7) + 31)
{
digitalWrite(7,LOW);
delay(output_pulse);
digitalWrite(7,HIGH);
}
// ========== Switch D straight ==========
if (command == (((switch_D >> 1) + 64) << 8) +((switch_D & 1 ) << 7))
{
digitalWrite(8,LOW);
delay(output_pulse);
digitalWrite(8,HIGH);
}
// ========== Switch D curve ==========
if (command == (((switch_D >> 1) + 64) << 8) +((switch_D & 1 ) << 7) + 31)
{
digitalWrite(9,LOW);
delay(output_pulse);
digitalWrite(9,HIGH);
}
// ========= Clear serial buffer
for (int z = 0; z < 256; z++)
{
Serial.read();
}
// =============================
delay(end_delay);
}
If you use the Arduino clone a Special USB driver is required in order
to download the sketch from you PC.
The RS-232 Rx line must be disconnected in order for the sketch to be
downloaded.
Future projects using this breadboard include an Accessory Controller.
Only a new sketch would be required.
The Tx line from the Arduino to the RS-232 module is not required for
the Switch Controller but was included for future projects that will
send commands out to the base. One possible project could receive a
command from the handheld and then output a command to the base such
as ASC 50 to send a series of whistle commands to a train.
The cable from the project to the base has 3 wires also to make it
bidirectional. Since it is symetrical it doesn't matter which end goes
to the base and which end goes to the project.
Original Post
Replies sorted oldest to newest