Proportional control of a brushed DC motor in Arduino
Version 1.0.2 (76.3 KB) by
David Bombara
Block diagrams for closed-loop position control via Arduino commands.
This code enables control of brushed DC motors using two types of driver control schemes: (1) PWM-DIR and (2) IN2-IN2.
Below is a schematic of the overall system for both driver control schemes. The system is a single-input-single-output closed-loop proportional control system. The "plant" subsystem contains the lower-level functions that depend on if the motor driver is manipulated using PWM-DIR logic or IN1-IN2 logic.
PWM-DIR:
For this scheme, the PWM pin on the driver outputs a pulse-width modulated (PWM) voltage signal whose duty cycle varies between 0% and 100%. The Arduino PWM pins are controlled using 8-bit values, so in the Arduino code, a PWM value of 0 corresponds to 0% duty cycle whereas a PWM value of 255 corresponds to 100% duty cycle. The DIR pin receives a Boolean voltage value from the Arduino digital pin. This value changes the direction of the motor.
IN1-IN2:
This scheme is similar to PWM-DIR. Both IN1 and IN2 receive a PWM signal from the Arduino. However, IN1 turns the motor in one direction, whereas IN2 turns the motor in the opposite direction. The Simulink block diagram is designed such that when IN1 is on, IN2 is off, and vice versa.
Cite As
David Bombara (2024). Proportional control of a brushed DC motor in Arduino (https://www.mathworks.com/matlabcentral/fileexchange/104805-proportional-control-of-a-brushed-dc-motor-in-arduino), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2021b
Compatible with R2021b
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.