Motor Control

C and Matlab / Electronics

Motor Control


For my Introduction to Mechatronics course, I made a motor control system to follow user specified angles and trajectories. The motor was controlled using a PID (proportional-integral-derivative) Feedback Control on the measured electric current and position of the motor.

PID Motor Control System

Motor Control System

Role ― Mechatronics

I programmed the control system in both Matlab and C. The Matlab code was to send instructions to and read data back from the microcontroller. The C code was to read sensors, actually control the motor, and send the trajectory data.

I also wired components on a bread board, so that the components could communicate with each other.




Feedback Control


A normal motor is rather impossible to control well without a control system. Something "simple" like turning to a particular angle would be difficult because a motor would need to react dynamically. 

How can I control a motor precisely to follow trajectories?


I used a PID Feedback Control System. The control system would receive in a user specified instruction and would output an electric control signal so the motor would follow the instruction.

PID Feedback Control

A proportional-integral-derivative (PID) controller has three parts to create an electric control signal. The three parts perform different operations on the error (e), which is the reference signal minus the sensed output. The relationship is show below as the control law.

PID Motor Control Law

Control Law

The figure below shows the nested feedback control loops used in this project. The inner loop is a PI electric current loop, and the outer is PID position loop.

PID Motor Control Loops

Control Loops


The motor control system worked really well and was able to turn to specific angles when given that input. It followed trajectories relatively well, but could use a bit more tuning. A video of the motor control system will be added soon!