JMRI Arduino Turnout Setup

In this blog I will be setting up a turnout on my layout which will be controlled by an Arduino using JMRI PanelPro.

The first thing I will need to do is setup the servo with an Arduino sketch so that I know the values to put into the servo throw command and the servo close command. Below is a simple sketch that will read the keyboard input with the Arduino Serial monitor and if the key input is "t" the servo will throw the turnout and if the input is "c" it will close the turnout. I can then adjust the servoWrite commands by 1 each time until the turnout has been moved enough to make a good connection with the running rails and not derail the train.

Below is the setup code for the Arduino which I run with the servo connected to one of my turnouts on my layout. Once I got the values for throw and close I could place these into the Arduino code for panelPro as shown in the previous blog.

#include <Servo.h>;
Servo myservo;

void setup(){

void loop (){
char inChar = (char);
if (inChar == 't'){
    Serial.println ("Turnout Thrown");
if (inChar == 'c'){
    Serial.println ("Turnout Closed");

You may have noticed I have two myservo.write commands for the turnout throw. This was due to the constant buzzing then trowing the turnout. myservo.write(10) is needed to get the points to throw over, I then back this off by 1 with myservo.write(9) which stops the buzzing but keeps the points in a good position to not derail the train.

Below is the Arduino code with the new values for panelPro JMRI to use.

#include <CMRI.h>
#include <Auto485.h>
#include <Servo.h>

#define CMRI_ADDR 1

#define DE_PIN 2
int turnout1 = 0;

Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
CMRI cmri(CMRI_ADDR, 24, 48, bus); // defaults to a SMINI with address 0. SMINI = 24 inputs, 48 outputs
Servo turnOut1;

void setup() {

void loop() {
    turnout1 = (cmri.get_bit(47));
    if (turnout1 == 1){



Cookie Policy

About Us

Privacy Policy

This site was created and designed by S Brackstone