Smartphone Controlled Model Railroad With an ESP8266

by KushagraK7 in Circuits > Remote Control

3828 Views, 18 Favorites, 0 Comments

Smartphone Controlled Model Railroad With an ESP8266

20210902_130033.jpg

A while back, I made a project where a stepper motor's position is controlled using a smartphone with the help of an ESP8266 microcontroller. After doing that project, I thought why not try controlling a model railway layout with the same concept, so here we are with this project.

Today, let's learn how to control a model railroad layout using a smartphone through Wi-Fi with the help of an ESP8266 microcontroller.

Let's get started!

Supplies

For this project, you will need:

  • An ESP8266 microcontroller(With least 4 digital outputs, including 2 PWM outputs)
  • A dual-channel motor driver(One channel for track power, other for turnout)
  • A breadboard
  • Male to male jumper wires
  • A 5-volt output voltage regulator(Example: L7805CV)
  • A small heatsink(Screwing a small piece of aluminium to the voltage regulator can also work)
  • *A DC power source

*The voltage of the power source depends on the operating voltage of the locomotive and the turnout, make sure the voltage regulator and the motor driver are rated for the supply voltage.

Watch It Working

Smartphone Controlled Model Railway with an ESP8266 | ESP Web-Browser Model Railroad Control

Watch the above video to know how it works and understand the controls.

Program the Microcontroller

ESP8266_Model_Railroad_Layout_Control _ Arduino IDE 2.0.0-beta.6 01-09-2021 18_07_36.png

You can get the Arduino code folder from here. Extract the contents of the zip folder and copy the folder named "ESP8266_Model_Railroad_Layout_Control" to the sketch folder of the Arduino IDE. Generally, it is in the Documents folder of the computer.

Before uploading, make sure to put in the name(SSID) and password of the Wi-Fo router to which you intend to connect the ESP.

Check the Web Controller

ESP8266_Model_Railroad_Layout_Control _ Arduino IDE 2.0.0-beta.6 01-09-2021 18_14_30.png
Screenshot_20210901-181806_Chrome.jpg

After uploading, open the serial monitor and make sure the baud rate is set to 115200. The blue LED on the ESP will blink until it is connected to the router, after that, it will display an IP address on the serial monitor. Note or copy it and enter it in the address bar of the web browser of a device that is connected to the same Wi-Fi router. You should see a page as in the second pic.

On sliding the slider or tapping on the buttons, you should see the ESP displaying some text on the serial monitor.

Set Up the Layout

Set up the turnout in layout.jpg

Put the Microcontroller and Motor Driver on the Breadboard

Plug ESP and motor driver on breadboard.jpg

You can also use a PCB with soldered female headers to make a more permanent setup but a breadboard is good for testing the setup for the first time and setting it all up quickly.

Connect the Motor Driver to the Microcontroller

Input pins for Turnout.jpg
Connect track power driver input.jpg
Connect Motor Driver to ESP.jpg

Connect the +ve input pin of the motor driver(Usually marked 'VIN', 'VMOT', etc.) to the +12-volt supply and connect its GND pin to the -ve of the supply.

Make the following connections from the microcontroller to the motor driver:

D5 - > IN1

D6 - > IN2

D7 - > IN3

D8 - > IN4

A lot of motor drivers, like the one which I use, require an enable pin to be connected to the +ve of the logic voltage, so connect it to the 3.3-volt pin of the microcontroller.

Connect Track Feeder and Turnout to the Setup

Connect track power feeder.jpg
Connect the Turnout.jpg

Connect the track power feeder's wires to the pins of the motor driver marked OUT1 and OUT2 as they correspond to the pins IN1 and IN2.

Connect the turnout's wires to the pins of the motor driver marked OUT3 and OUT4 as they correspond to the pins IN3 and IN4.

Connect the Voltage Regulator to the Setup

Connect Voltage regulator.jpg

Mount a small heatsink to the regulator to keep its temperature in a safe range.

Connect the regulator's left pin to the +12-volt supply, its middle pin to the GND of the circuit, and its right pin to the VIN pin of the ESP board.

Connect the Setup to Power

Connect power.jpg

You can use a barrel-type connecter to connect the setup to a 12-volt DC adapter easily.

Place the Locomotive on the Tracks

Place the Locomotive.jpg

Make sure the locomotive is sitting properly on the tracks to prevent derailments and short-circuit of track power.

Power Up the Setup and Open the Controller Page

After powering up the setup, the LED on the ESP board should blink until it gets connected to the Wi-Fi router. After that open the control page on the browser of the device from which you want to control the layout by entering the IP address you noted from Step3. Make sure that device is connected to the same Wi-Fi router.

Test the Controls

Smartphone Controlled Model Railroad with ESP8266

Check if your controls are working as shown in the video.

If the locomotive is moving in the wrong direction, just reverse the polarity of track power by swapping the track feeder wires with each other. You can do the same with the turnout wires if you want to switch it in the opposite direction.

Add More to the Project

The example provides here can only control a single locomotive and a turnout and I am sure that it is not enough for a regular model railroad layout. So why don't you try to add another turnout or maybe a locomotive control?

It might be but difficult to understand the code and modify it, but when you start to understand it, you can do a lot of things to improve this project and suit it to your liking.
Whatever you do, try to share your creation with the community to inspire more people to try this project.

All the best!