You are on page 1of 11

PBL

ME 447

PID Controller Tuning and ArduinoBased DC Control

Submitted to:
Mr. Talha Asif
Group Members:
Saadat Shah 2020420
Affan Hassan 2020466
Talha Shoaib 2020368
Mustafa Khalid 2020390

Ghulam Ishaq Khan Institute of Engineering Sciences


and Technology
Executive Summary
In precision-driven systems like a robotic arm delicately placing parts on an assembly line, PID
control becomes the guiding hand. three crucial factors were considered the immediate distance
to the target, past arrow trajectories, and predicting where the next arrow will land.

Similarly, in Arduino-based DC motor control, PID takes on this role. It's the tool that ensures
the motor attains and sustains desired speeds or positions accurately and steadily. Leveraging the
Arduino platform's accessible programming and supportive libraries makes implementing PID
control seamless.

Tuning a PID controller helps to enhance the rotation of DC motor. It involves fine-tuning three
settings—proportional, integral, and derivative gains—to achieve specific outcomes: swift target
acquisition, minimal overshooting, and resilience against external factors . This tuning can be a
manual, trial-and-error process or automated through smart algorithms that analyze the system's
responses.

Mastering PID control on Arduino unleashes precise motor handling, powering various
applications in robotics, automation, and motion control systems.
Table of Contents
Executive Summary.........................................................................................................................2
Nomenclature...................................................................................................................................3
List of Figures..................................................................................................................................3
Problem Statement:..........................................................................................................................4
Literature Review:...........................................................................................................................4
Experimental Setup..........................................................................................................................4
DC Motor.....................................................................................................................................5
Encoder........................................................................................................................................5
Motor Driver................................................................................................................................6
Arduino........................................................................................................................................7
Mathematical modeling:..................................................................................................................8
Arduino Code.................................................................................................................................10
Results............................................................................................................................................10
Conclusion.....................................................................................................................................10

Nomenclature
KI Integral Gain
KP Proportional Gain
KD Derivative Gain
di
Change in current with respect to time.
dt
ω Angular Speed
L Inductance
R Resistance
I Current
T(s) Torque
J Torque Coefficient

List of Figures
Figure 1. DC motor..........................................................................................................................5
Figure 2.Encoder..............................................................................................................................6
Figure 3. Motor Driver....................................................................................................................7
Figure 4. Arduino Uno.....................................................................................................................8
Problem Statement:
PID is the most prevalent form of feedback control for a wide range of real physical applications.
When working with PID controllers, one of the most challenging tasks is to tune it properly.
Tuning of PID is the process of finding the value of proportional, integral, and derivative gains
of the PID controller. This PBL experiment aims to understand how the PID controller works
and how it is used to control a simple PMDC motor using Arduino and PID logic code.

Literature Review:
Over the past two decades, the process control sector has witnessed significant advancements in
controller design and implementation methods [1]. Widely acknowledged as the predominant
algorithm in process control [2], the PID controller's efficacy largely hinges on precise system
models and parameter accuracy. Tuning a PID controller involves adjusting its proportional,
integral, and derivative values using a tuning algorithm to optimize process response [3]. Despite
technological strides, the classical PID controller remains the industry favorite due to its
simplicity and robust performance across diverse operational conditions. Statistics reveal that
97% of controllers in the refining, paper, and pulp industries employ the PID structure [4].
Critical in implementing a PID controller effectively, the tuning process for its parameters
assumes a pivotal role. J.G. Zeigler and N.B. Nichols were pioneering figures introducing
elementary tuning rules for PID controllers [5]. Inappropriately set tuning constants can render
controlled systems inadequate, leading to instability [6].
DC motors, among the earliest electromechanical machines developed post the inception of DC
sources, offer advantages, particularly in speed regulation over AC machines. They find
extensive application in domains demanding precise speed control and reliable dynamic
responses, such as industrial, medical, and military sectors, necessitating a wide range of variable
speeds [7]. The speed of a DC motor correlates directly with its armature voltage, underlining the
significance of designing an apt controller for speed regulation. Essential for constructing the
mathematical model [8] and subsequently deriving PID controller tuning gzains [9],
understanding the parameters of the DC motor remains paramount.
This paper [10] is aimed at looking into the application and explaining the reason of controller
choice of PID controllers, which are very widely used with their easy functioning principle. In
other words it explores emissions control using robotic vehicle speed control by regulating motor
speed. The authors focus on overcoming problems that arise in the course of the vehicle’s actual
operations. The main purpose is to introduce an automatic tuning method for the PID controller
which will enable it to properly regulate the speed of a DC motor with the aid of an Arduino
microcontroller.

The importance of this work is that it can be applied to DC motors, in which speed control is
essential. The authors use an Arduino Uno board as a low-cost data acquition board, connecting
it to Simulink to control the DC motor’s speed. The system makes use of ultrasonic sensors to
measure obstacle distances. Using these measurements, the PID controller adjusts motor speed
within specified limits.

As to the method, the paper goes over some basic PID controller theory, saying this is a closed-
loop controller. A schematic diagram of the PID controller explains how it computes a control
signal which modifies the plant’s output. Design of PID Controller The paper goes on to describe
the design for the PID controller, which integrates proportional, integral and derivative
components.

With respect to the value of the paper, it is giving people pointers about how PID controllers for
speed control can actually be used in actual applications as exemplified by the robotic vehicle
with obstacle avoidance. The addition of Arduino microcontroller and Simulink for automatic
tuning brings a further level of adaptability and control precision to the system.

Experimental Setup
Following instrument were used in the experimental set up.
DC Motor
A DC (Direct Current) motor is a machine that converts electrical energy into mechanical energy
through the interaction of magnetic fields. It operates on the basis that, when a current-carrying
conductor is placed in a magnetic field it experiences a field of force.
Components of a DC motor include the stator, rotor, commutator, and brushes. The stator
generates a magnetic field using permanent magnets or electromagnets. Meanwhile, the rotor,
consisting of an armature wound around a core, is placed within the stator's magnetic field. The
commutator, made of bars or segments, reverses the current in the rotor windings, ensuring
continuous rotation and unipolar current output. Brushes maintain contact with the commutator,
allowing current flow into the rotor windings and avoiding sparking.
When an electric current flows through the armature windings, it creates a magnetic field around
the rotor. This field interacts with the stator's magnetic field, producing a torque that rotates the
rotor. The commutator and brushes ensure that the current direction in the armature windings
changes at the right time, enabling continuous rotation and unipolar current output.
DC motors come in various types, such as series, shunt, and compound motors. Series motors
provide high starting torque and are used in applications like electric vehicles and cranes. Shunt
motors offer constant speed and find use in devices like lathes and fans. Compound motors
combine features of both series and shunt motors, providing high starting torque and consistent
speed.
Advantages of DC motors include simple speed control by adjusting voltage or current, high
starting torque at low speeds, and reversibility by changing the current direction. However, they
require maintenance due to brushes and commutators and may produce electrical noise during
operation.
These motors are extensively utilized in industries, robotics, automotive systems, household
appliances, and various fields due to their versatility, controllability, and reliability in converting
electrical energy into mechanical motion.

Figure 1. DC motor

Encoder
An encoder in a DC motor is a vital component used for feedback control, providing precise
information about the motor's speed, position, and sometimes direction. It's an electromechanical
device that converts the motion of the motor shaft into digital signals Encoders in DC motors
typically consist of a rotating disc (for incremental encoders) or a series of coded tracks (for
absolute encoders) and sensors that detect changes in the patterns on the disc or tracks.
When the motor shaft rotates, the encoder detects these changes and generates electrical signals
corresponding to the motion. These signals are then processed by control systems or
microcontrollers to determine the motor's precise speed and position. Encoders are integrated
into the motor system, usually attached to the motor shaft. The electrical signals generated by the
encoder are then fed into control systems or microcontrollers, where they're processed to derive
speed and position information used for motor control.
There are two types of encoders: Incremental and absolute
Incremental encoders generate pulses as the motor shaft rotates. They provide information about
the shaft's relative position and speed but don't offer absolute position feedback without a
reference point.
Absolute encoders provide precise position information for the motor shaft without requiring a
reference point.
Figure 2.Encoder

Motor Driver
A motor driver is an essential component in controlling and powering electric motors, providing
the necessary electrical current and voltage required for their operation. It's responsible for
translating control signals from a microcontroller or other control circuitry into power signals
that can drive and control the motor.
Motor drivers take low-power control signals from devices like microcontrollers and amplify
them to provide the higher current and voltage levels needed to drive motors. They enable
precise control over the motor's direction of rotation and speed by modulating the amount of
current and voltage supplied to the motor windings. Many motor drivers include protection
features such as overcurrent protection, overvoltage protection, and thermal shutdown to
safeguard the motor from damage due to electrical faults or overheating.
The IBT2 Motor Driver H-Bridge BTS7960 is being used to drive DC motors efficiently and
effectively. It's based on the BTS7960 H-Bridge driver chip and is capable of handling high
currents, making it suitable for applications that require robust motor control. The H-Bridge
configuration allows bidirectional control of DC motors. It can control the motor's direction of
rotation by controlling the current flow through the motor windings.
The module is capable of handling high currents up to 43A (peak) and 25A (continuous). This
high current capacity makes it suitable for driving motors that require substantial power. It
supports Pulse Width Modulation (PWM) control, enabling precise speed control of DC motors.
PWM signals regulate the average power delivered to the motor, allowing for variable speed
control. It has built-in overcurrent protection that helps to prevent damage to the motor driver
and the connected motor by shutting off the output in case of excessive current. The fins beneath
the driver increase the heat transfer rate of the module to prevent overheating, ensuring the
module operates within safe temperature limits.
Figure 3. Motor Driver

Arduino
The Arduino is a popular microcontroller board widely used in electronics, prototyping, and DIY
projects. It's a key component in creating interactive devices and is favored for its simplicity,
versatility, and accessibility to both beginners and advanced users. It can interface with sensors
and actuators making it suitable for developing control systems for home automation,
environmental monitoring, and more.
The Arduino Uno is being used for this project and it is powered by the Atmega328P
microcontroller. The Arduino Uno provides digital input/output pins, analog inputs, a 16 MHz
ceramic resonator, a USB connection, a power jack, and an ICSP header. The connections
provide versatility to the microcontroller allowing it to connect to several devices such as
laptops, bread boad, and different sensors.
It's programmed using the Arduino Software (IDE), which utilizes a simplified version of C and
C++ languages, making it accessible to beginners while still offering capabilities for advanced
users. The hardware and software of the Arduino Uno are open-source, encouraging the
community to contribute libraries, code examples, and projects, fostering collaboration and
innovation.
Arduino Uno is compatible with a vast array of sensors, actuators, shields, and other hardware
components available in the Arduino ecosystem, allowing for easy integration and expansion of
projects. The Arduino Uno is not capable of doing a complex task which is one of its limitation.
Otherwise, it is a user-friendly micro-controller with both open-source hardware and software.
Figure 4. Arduino Uno

Mathematical modeling:
Both the mathematical model of PMDC and PID controller are derived separately. The
permanent magnet dc motor consists of:
The electrical equation of the Permanent magnet DC motor:
di
V =I a × R a+ L a × + E b
dt
Where L
Back emf equation:
Eb =K b ×ω
Where K b is the back emf constant in voltas/radian/second.
And ω is the angular velocity of the motor.
The torque equation is:
T =K t × I
Where K t is the torque constant of the motor.
Obtaining the Laplace transform of the math model is;

V ( s )=I ( s ) × R+ L× s × I ( s ) + E (s )

E ( s )=K b × ω( s)

T ( s )=K t × I (s)
T (s)
ω ( s )=
J
The transfer function is:

ω (s) 1 Kt
G ( s )= = ×
J s Kb × Kt
R+ L × s+
J

Mathematical Modeling of PID controller:

Proportional Term
Kp is the constant for proportional term gain. The proportional term is Kp.
Integral Term
Ki is the constant for proportional term gain. And s is the Laplace variable frequency term. The
integral term is as follows:
Ki
s
Derivative Term
Kd is the constant for derivative term gain. And s is the Laplace variable frequency term. The
proportional term is as follows:
K d∗s.

The overall transfer function for the PID controller is:

Ki
C ( s )=K p + +Kd . s
s

Where C(s) is the control signal as shown in the figure above


Arduino Code
Results
Conclusion
By Using PID Controller We designed a DC motor control-based system using encoder. The
encoder controlled the movement of DC motor, and it was control through coding on Arduino.
The PID controller was used in Arduino for controlling the speed of rotation of motor.

Reference:
[1] K. Astrom, “Process control--Past, present and future,” IEEE Control Systems Magazine, vol. 5,
no. 3, pp. 3–10, Aug. 1985, doi: 10.1109/MCS.1985.1104958.
[2] S. Skogestad, “Simple analytic rules for model reduction and PID controller tuning,” J Process
Control, vol. 13, no. 4, pp. 291–309, Jun. 2003, doi: 10.1016/S0959-1524(02)00062-8.
[3] N. Khanduja and B. Bhushan, “Intelligent Control of CSTR using IMC-PID and PSO-PID
controller,” in 2016 IEEE 1st International Conference on Power Electronics, Intelligent
Control and Energy Systems (ICPEICES), IEEE, Jul. 2016, pp. 1–6. doi:
10.1109/ICPEICES.2016.7853329.
[4] K. J. Åström and T. Hägglund, “Revisiting the Ziegler–Nichols step response method for PID
control,” J Process Control, vol. 14, no. 6, pp. 635–650, Sep. 2004, doi:
10.1016/j.jprocont.2004.01.002.
[5] V. Vishal, V. Kumar, K. P. S. Rana, and P. Mishra, “Comparative study of some optimization
techniques applied to DC motor control,” in 2014 IEEE International Advance Computing
Conference (IACC), IEEE, Feb. 2014, pp. 1342–1347. doi: 10.1109/IAdCC.2014.6779522.
[6] K. Hameyer and R. J. M. Belmans, “Permanent magnet excited brushed DC motors,” IEEE
Transactions on Industrial Electronics, vol. 43, no. 2, pp. 247–255, Apr. 1996, doi:
10.1109/41.491348.
[7] M. Zhuang and D. P. Atherton, “Automatic tuning of optimum PID controllers,” IEE
Proceedings D Control Theory and Applications, vol. 140, no. 3, p. 216, 1993, doi: 10.1049/ip-
d.1993.0030.
[8] Z. Glowacz and A. Zdrojewski, “Mathematical modelling of commutator DC motor in failure
conditions,” in 2005 5th IEEE International Symposium on Diagnostics for Electric Machines,
Power Electronics and Drives, IEEE, Sep. 2005, pp. 1–5. doi: 10.1109/DEMPED.2005.4662543.
[9] S. Galijasevic, S. Masic, S. Smaka, A. Aksamovic, and D. Balic, “Parameter identification and
digital control of speed of a permanent magnet DC motors,” in 2011 XXIII International
Symposium on Information, Communication and Automation Technologies, IEEE, Oct. 2011, pp.
1–7. doi: 10.1109/ICAT.2011.6102120.
[10] Allam, T., Raju, M., & Kumar, S. S. (2016). Design of PID controller for DC Motor Speed.
Control Using Arduino Microcontroller.

You might also like