Stepper Motor Controlled Model Locomotive | Stepper Motor As a Rotary Encoder
by KushagraK7 in Circuits > Arduino
2879 Views, 16 Favorites, 0 Comments
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!
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.
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.
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.
Set Up the Test Track
Make sure the track rails are cleaned.
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.
Connect Track Power to the Motor Shield
Connect the track power feeder's wires to the terminals of the motor shield marked 'M4'.
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.
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.
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.
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.
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!