← Advanced Instrumentation

PHYS 351 · Advanced Instrumentation

Lab 5 · Stepper & servo motor control

PHYS 351 LAB 5
Stepper and Servo Motor Control

© Ran Yang, Ph.D.
SUBMISSION   Submit the completed lab report as a PDF on Gradescope.

Due: 2:00 p.m. next Monday.

Policies and Instructions
  1. Report Format: Submit a formal, typed lab report in PDF format. Handwritten lab reports will not be accepted. Hand-drawn circuit schematics are allowed only when explicitly permitted in the task instructions. Include screenshots, code, and simulation or measurement results where specified.
  2. AI Policy: The use of any AI tool, including a large language model (LLM), to write, generate, debug, or modify code or any portion of the lab report is prohibited unless the course instructor grants explicit permission in advance. A teaching assistant (TA) cannot grant permission to use AI tools.

By signing below, I acknowledge that I have read and understood the policies and instructions above and agree to follow them.

Student Name (print):  

Student Signature:       Date:  

Tasks

You have used simple logic sequences to control LEDs and pulse-width modulation (PWM) to control a DC motor. In this lab, you will control the direction and speed of a stepper motor by changing the polarities of its coil sets in a defined sequence. You will also control a servo motor by varying the PWM duty cycle. Include relevant screenshots, photographs, and videos in your report, and add descriptive comments to your programs. Use the terminal to create a directory for your lab files.

  1. Read the datasheets for the NEMA 17 stepper motor and motor-driver chip. Identify the motor-driver pins and the stepper motor’s four colored wires. Draw a schematic showing how you plan to connect the driver, motor, Raspberry Pi, and power supply. Show your design to the course instructor or a TA.
  2. Create full-step and half-step logic tables for both clockwise and counterclockwise rotation. Show the logic tables to the course instructor or a TA.
  3. Construct the circuit you designed to run the stepper motor. Obtain approval from the course instructor or a TA before applying power. Your code must be able to:
    1. turn the motor clockwise for at least two full rotations using both full-step and half-step sequences;
    2. turn the motor counterclockwise for at least two full rotations using both full-step and half-step sequences; and
    3. report the total runtime, number of revolutions, period, frequency, rotation angle per step, and total number of steps. Compare the reported values with your observations.
TASK APPROVAL Tasks 1–3 (Stepper Motor)

Course Instructor or TA Signature:  

Date and Time:  

  1. Connect the MG996R servo motor to the Raspberry Pi. Attach the two-pronged servo horn to the output gear. Do not rotate it by force; forced rotation can damage the servo. To change the horn orientation, remove it and reinstall it at the desired angle. Write a program that rotates the servo to 30°, and verify the angle with a protractor.
  2. Modify your code so that the servo rotates through its full range. Measure the angular range and compare it with the datasheet. Create a table of duty cycle versus rotation angle, determine a fitting formula that predicts angle from duty cycle, and evaluate its accuracy. Finally, modify your code to accept a valid angle as input and reject values outside the permitted range.
TASK APPROVAL Tasks 4–5 (Servo Motor)

Course Instructor or TA Signature:  

Date and Time:  

Submission Reminder

  • Your stepper-motor connection schematic and the full-step/half-step logic tables.
  • Your complete, commented Python scripts for both the stepper and servo motors.
  • The reported runtime, number of revolutions, period, frequency, rotation angle per step, and total number of steps for the stepper motor, compared with your observations.
  • The duty-cycle-vs-angle table for the servo, your fitting formula, and an assessment of its accuracy.
  • A discussion of any challenges encountered and how you overcame them.

← All course materials