Skip to main content

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.

Arduino Module

Relay Module

RS232 Module

DC_Regulator

Schematic

Breadboard

Attachments

Images (6)
  • Arduino Module
  • Relay Module
  • RS232 Module
  • DC_Regulator
  • Schematic
  • Breadboard
Original Post

Replies sorted oldest to newest

Pretty neat, here's the eBay listing for the Ardunio UNO clone:

 

Enduring ATmega328P CH340G UNO R3 Board 5V DC for Arduino USTO

 

That's pretty impressive, four switch controllers for $16.

 

FWIW, if you use the AC/DC to DC Buck Converter Step Down Module LM2596 Power Supply Output DC1.5-27V you eliminate the extra step of adding the breadboard for the power.

 

A do it your self Arduino Switch Controller for less than $16. Following
is a parts list with prices that include shipping.

 

David thanks for posting this information!  Probably won't do your project, but the Arduino has so much potential in modeling, and your work is inspirational as a starting point.  I've had the MakerSHEd "Getting Started with Arduino Kit" hanging around for way too long, and never did much more than make a few LEDs blink.  Now if I could just find the time...

 

Alan

Originally Posted by gunrunnerjohn:

The command base sends the commands out, it's a one-way conversation.

 

As far as updating, if you can program in a pseudo-C language, you can make it do pretty much anything with the switches.  The limitation is how many I/O ports you need for inputs and outputs.

 

John, couldn't the base receive a command from the Arduino using the proper format, just like it does from the MTH DCS?  I'm trying to get time to play with block detection and signaling with an Arduino.  The stuff is low cost, so time is my only limitation at this point.  Every time I find code, it gives me more insight into how the Arduino works.  Thanks David.

One of the other projects I did was with a Lionel trolley and the MTH

station with the disappearing passengers. The trolley pulls up. stops,

The people go up and the trolley leaves. Next trip. Trolley stops and drops off

the people, and the cycle repeats. A real crowd pleaser.

 

Right now it's being done with a $1500 dollar controller. For the size and price

I may convert to the arduino. Just think what you could do with a switch and

some parallel tracks.

 

I had better quit. To many other project in the que....

Regarding the question, can you add feedback on the switch position. I did this with Arduino by utilizing the yellow wire off the switch. This wire is either high or low, which can be sensed at the Arduino analogRead. My system uses Arduino MEGA - an Arduino derivative version with 53 digital and 16 analog connections. 

I connect the yellow wire to an optical isolator along with the switch's black ground wire. My layout has 15 switches. One MEGA controls all with input from an LCD touch panel. MEGA polls all the isolators once a second and updates the panel.

More than 16 bucks for sure :-).. happy to provide details to anyone interested.

Great project. I've been using 3 Arduino Mega boards to control 35 Atlas switches on my layout. The Arduinos receive input from either a toggle switch on my control panel or an insulated rail. My sketch activates one relay for 0.5 seconds to throw the switch and then toggles another relay that powers indicator lights. I save the switch position in the Arduino's memory so that the indicator lights will be correct when power is first turned on.

I've also been playing around with using the Arduino to control some of the accessories on my layout, and I've been very happy with the results. They really are very useful gadgets.

You can also read the state of a DZ-2500 or DZ-1000 switch machine with a microcontroller; optically isolated if your Arduino ground is the same as the command base (earth ground).

I built a similar module to control my uncouplers. The Arduino reads the serial stream from the base as well as the state of buttons on the control panel.

I also implemented a timed cutoff and lockout to prevent uncoupler magnet from overheating if something gets stuck.

I would like to have a positive indication of the switch position but some of my switches would need 100 ft of wire to get back to the control panel. If this indication could be sent wirelessly I could be interested.

I am presently working on having two serial ports so that control panel  projects could be daisy chained together. These dual ports would have to pass TMCC commands in either direction as well as sending internally generated and receiving externally generated TMCC commands. Control panel projects include a TMCC version of the ECU-1 controller and O22 switch controllers sending TMCC commands to switches in remote places on the layout.

eye311 posted:

Regarding the question, can you add feedback on the switch position. I did this with Arduino by utilizing the yellow wire off the switch. This wire is either high or low, which can be sensed at the Arduino analogRead. My system uses Arduino MEGA - an Arduino derivative version with 53 digital and 16 analog connections. 

I connect the yellow wire to an optical isolator along with the switch's black ground wire. My layout has 15 switches. One MEGA controls all with input from an LCD touch panel. MEGA polls all the isolators once a second and updates the panel.

More than 16 bucks for sure :-).. happy to provide details to anyone interested.

Eye11; I would interested in getting a copy of your work using the Arduino Mega 2560.

Thanks;

idea-thinker

 

eye311 posted:

Regarding the question, can you add feedback on the switch position. I did this with Arduino by utilizing the yellow wire off the switch. This wire is either high or low, which can be sensed at the Arduino analogRead. My system uses Arduino MEGA - an Arduino derivative version with 53 digital and 16 analog connections. 

I connect the yellow wire to an optical isolator along with the switch's black ground wire. My layout has 15 switches. One MEGA controls all with input from an LCD touch panel. MEGA polls all the isolators once a second and updates the panel.

More than 16 bucks for sure :-).. happy to provide details to anyone interested.

 

Add Reply

Post
×
×
×
×
Link copied to your clipboard.
×
×