Introduction: Laptop Touchpad Controlled Model Railroad | PS/2 Arduino Interface
A laptop's touchpad is one of the great devices to use as an input for microcontroller projects. So today, let's implement this device with an Arduino microcontroller to control a model railroad. Using a PS/2 touchpad, we will be able to control 3 turnouts and track power.
Keeping the touchpad with its width at the bottom(Sort of like portrait mode), sliding the finger along each of the two diagonals will be used to control two turnouts, sliding the finger horizontally will be used to control another turnout and sliding the finger vertically will be used to control the locomotive's speed and direction.
So, without further ado, let's get started!
Step 1: Watch the Video
Watch the video to understand all the controls and know more about how it works.
Step 2: Get All Parts and Supplies
For this project, you will require:
- An Arduino microcontroller compatible with Adafruit Motor Shield V2(UNO, Leonardo, etc)
- An Adafruit Motor Shield V2
- A PS/2 touchpad
- 4 wires with male Dupont connectors on one side(To connect the touchpad to the Arduino board)
- 2 wires each for connecting track power and turnouts(3 max) to the motor shield
- A 12-volt DC power supply with a current capacity of at least 1A.
Step 3: Get the Ps2 Library
Download the folder of the ps2 library from here. Move the downloaded folder to the desktop as it will be easier to find. Open the Arduino IDE and click Sketch>Include Library>Add .ZIP Library... and then select the ps2 folder from the desktop. The library will be included and you now be able to use the ps2 library.
Step 4: Figure Out the Connections of the Touchpad
If you have a Synaptics touchpad like the above one, the pad 'T22' is +5V, 'T10' is 'Clock', 'T11' is 'Data' and 'T23' is 'GND'. You can also solder the 'GND' wire to a large exposed copper as shown above.
Click on the above image to know more. If you have a different touchpad, try searching for its part number on the internet with 'pinouts' or you can ask the r/Arduino community on Reddit if you get stuck.
Step 5: Test the Touchpad
Make sure the correct connections are made to the touchpad. To test the touchpad, upload the ps2 mouse code on the Arduino microcontroller from Examples>ps2. Connect 'Clock' wire to D6, 'Data' wire to D5, GND to GND, and +5V or VCC to +5V pin of the Arduino board respectively. Reconnect the Arduino board to the computer and open the serial monitor. If you see the numbers changing as you move your finger across the touchpad, the touchpad is working properly and you can proceed.
Step 6: Program the Arduino Microcontroller
It is recommended to go through the code before uploading it to the Arduino microcontroller to understand what all is going on.
Step 7: Set Up the Layout
Set up a layout to test the track power and all the three turnout controls. Make sure all track joints are made properly and the tracks are clean. Cleaning the tracks and locomotives' wheels periodically is recommended to prevent the locomotives from stalling.
Step 8: Install the Motor Shield on the Arduino Board
Carefully align the pins of the motor shield with the female headers of the Arduino board and push the shield on top of the Arduino board. Make sure the shield fits securely on the Arduino board and no pin gets bent.
Step 9: Connect Track Power and Turnouts to the Motor Shield
Make the following connections:
- Connect the track power to the output connector of the shield labeled 'M1'.
- Connect the turnouts to the rest three output connectors 'M2', 'M3', and 'M4'.
Make sure all the wiring connections are tight.
Step 10: Connect the Touchpad to the Setup
Connect the touchpad to the Arduino board by making the following connections between the touchpad and the Arduino board:
- +5-volt or 'VCC' to +5-volt of the Arduino board
- 'GND' to 'GND' of the Arduino board
- 'Clock' to 'D6' of the Arduino board
- 'Data' to 'D5' of the Arduino board
Step 11: Place the Locomotive(s) on the Track
Place a locomotive to be tested. You can also place multiple locomotives as per wish.
The use of a rerailing tool is recommended. Make sure the locomotives are properly placed on the tracks to prevent derailments.
Step 12: Connect the Setup to Power and Turn It On
Connect the 12-volt power supply to the setup and turn it on.
Step 13: Test the Controls
Test all the controls. Refer to the above video again to understand the controls.
Step 14: Share Your Work and Expand It Furthur
If you got your project working and if you can, try sharing the pictures of your creation with the community by clicking on 'I Made It!'.
Also, try adding more features and functions to this project and try to share them as well. Whatever you do, all the best!