Introduction: Stepper Motor Controlled Model Locomotive | Stepper Motor As a Rotary Encoder
In one of the previous Instructables, we learned how to use a stepper motor as a rotary encoder. In this project, we will now use that stepper motor turned rotary encoder to control a model locomotive using an Arduino microcontroller. So, without further ado, let's get started!
Step 1: Watch the Video
Watching the video is recommended before proceeding to help us get a better idea of the project and also understand the controls.
Step 2: Get the Parts and Supplies
For this project, you will require:
- An Arduino microcontroller board compatible with Adafruit Motor Sheild V2.
- An *Adafruit Motor Shield V2.
- A stepper motor turned rotary encoder.
- 4 male to female jumper wires(For connecting the rotary encoder's amplifier to the Arduino microcontroller)
- A 12-volt DC power source.
*The Adafruit Motor Shield V2 communicates with the Arduino microcontroller via I2C and hence uses only two pins of the Arduino microcontroller('SCL', A5 and 'SDA', A4). This helps in saving other I/O pins. Also, plugging on a shield reduces wiring and makes it tidier.
Step 3: Program the Arduino Microcontroller
Make sure you have the Adafruit Motor Shield V2 library installed on the Arduino IDE. If not, you can download it from here.
Step 4: Set Up the Test Track
Make sure the track rails are cleaned.
Step 5: Install the Motor Shield on the Arduino Board
Install the motor driver shield on the Arduino board by carefully aligning the pins of the driver board with the female headers of the Arduino board. Take extra care to ensure the pins do not get bent in the installation process.
Step 6: Connect Track Power to the Motor Shield
Connect the track power feeder's wires to the terminals of the motor shield marked 'M4'.
Step 7: Connect the Stepper Motor to the Amplifier
- For unipolar stepper motors:
- Connect the center tap wire of the motor to the pins marked 'Q' or 'R'.
- Connect any two of the remaining four wires to the pins 'P' and 'S'.
- For bipolar stepper motors:
- Connect the motor's wires to the terminals according to the above circuit schematic.
Step 8: Connect the Amplifier to the Arduino Board
Connect the amplifier's 'GND' and +ve terminal to the 'GND' and '+5-volt' pins of the Arduino board respectively. Connect the output pins of the amplifier board to the digital input pins 'D6' and 'D7' of the Arduino board.
Step 9: Place the Locomotive on the Track
Place the locomotive on the test track. Make sure the wheels are aligned properly with the rails. Use of an appropriate rerailing tool is recommended.
Step 10: Power Up the Setup and Test the Controls
Connect the setup to the 12-volt DC power source and turn the power on. Check if everything is working properly as shown in the above video.
Step 11: Share Your Work
If you have made your project, why not share it with the community. Sharing your project can help inspire others to make this project too.
Go ahead and click on 'I Made It!' and share some pictures of your creation, we are waiting!
Participated in the
Arduino Contest 2020