Motor Rotation Based on Turn Input Value
This program demonstrates a simple motor control application using Python. The main objective of the script is to rotate a motor by a specific number of turns, which is determined by the user input. The motor's position is tracked, and it continues to rotate until the desired number of turns is achieved.
About Tools and Materials:
SMD USB Gateway (Purchase Here)
Arduino Gateway Module (Purchase Here)
Step 1: Hardware & Software Overview
Project Key Components
SMD The SMD acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the Button Module and actuate the BDC motor, the RGB LED Module and the Buzzer Module.
BDC Motor The motor is controlled using velocity commands, allowing for smooth acceleration and deceleration.
Project Key Features
Establishes a connection with the SMD Red motor using the Master and Red classes from the smd.red library.
Allows users to specify the number of turns for the motor, using an encoder with a predefined steps-per-turn value.
Continuously monitors the motor’s position and stops it once the desired rotation is achieved.
Sets the motor velocity dynamically, starting with maximum speed and stopping precisely at the target position.
Designed to work efficiently within multi-threaded applications for real-time motor control.
Step 2: Assemble
Getting Started
Hardware Setup
Connect the SMD to the PC or Arduino board using USB Gateway Module or Arduino Gateway Module.
Connect the 100 RPM BDC Motor with Encoder to the motor ports of the SMD using an RJ-45 cable.
Make sure that the SMD is powered and all connections are correct.
Project Wiring Diagram

Step 3: Run & Test
Run the Script
Execute the script to initiate the Motor Rotation Based on Turn Input Value project.
Enter different turn values in the control interface to observe the motor behavior.
Input a positive value to rotate the motor clockwise (CW).
Input a negative value to rotate the motor counterclockwise (CCW).
Input zero (0) to stop the motor.
Observe how the motor speed dynamically adjusts based on the magnitude of the input value.
Customize and Experiment
• Modify input values in the script to control the speed and rotation direction.
• Experiment with different PWM signal ranges to fine-tune motor performance.
• Implement acceleration profiles to create smoother speed transitions.
• If using an encoder, integrate it for closed-loop control and precise motor positioning.
Example Usage:
When the program is executed, it will ask the user to input the number of turns:
After the user inputs the value (e.g., 5), the motor will rotate the equivalent number of turns. The program will print a message once the motor has completed the rotation:
Codes
Last updated