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

IMG_2239_.JPG

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

Control your model locomotive with a Stepper motor! | Stepper Motor as Rotary Encoder

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

IMG_2228.JPG
IMG_2229.JPG
IMG_2231.JPG

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

Arduino code.PNG

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

IMG_2232.JPG

Make sure the track rails are cleaned.

Install the Motor Shield on the Arduino Board

IMG_2167.JPG

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

IMG_2233.JPG

Connect the track power feeder's wires to the terminals of the motor shield marked 'M4'.

Connect the Stepper Motor to the Amplifier

Circuit schematic.png
IMG_2234.JPG
  • For unipolar stepper motors:
    1. Connect the center tap wire of the motor to the pins marked 'Q' or 'R'.
    2. 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

IMG_2235.JPG
IMG_2236.JPG

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

IMG_2237.JPG

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

Controlling model locomotives using a stepper motor | Stepper motor as rotary encoder | Arduino

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

IMG_0859_.JPG

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!