Embedded Control System of DC Motor Using Microcontroller Arduino and PID Algorithm

ABSTRACT

This study proposes a DC motor hardware design with a low-cost embedded system device, namely the Arduino Uno [35][36] [37]. The PID controller is implemented in the system as an angular velocity controller (omega). PID control was chosen because it has advantages in its characteristics, namely easy to understand, simple but has good system response performance, and easy to implement in both software simulation and hardware implementation. [38][39] [40][41] [42].

System Design
The block diagram of the embedded system for controlling a DC motor's speed is shown in Figure 1. At the same time, the system wiring diagram is shown in Figure 2. The system consists of input devices, processors (processors), output devices, and interface devices. The input device is an encoder sensor that functions to measure the angular speed of a DC motor. The output devices are the L298 motor driver and the JGA25-370 DC Motor. The processing device is the Arduino Uno. The interface device is a serial monitor or serial plotter from the Arduino IDE.
The encoder sensor sends pulse data to the Arduino Uno to calculate the Radian Per Minute angular velocity value (RPM). The features used by the Arduino Uno to process angular velocity are a timer and counter. Angular velocity data is sent to Serial Monitor and Serial Plotter via USB serial. Pulse Width Modulation (PWM) is used to adjust the input voltage to the DC motor so that the DC motor's speed can be varied. The motor driver functions to convert the digital voltage (PWM) into an analog voltage with a higher voltage level (5 volts to 10 volts).

Figure 1. System Block Diagram
The configuration of the input PIN and output PIN can be seen in Figure 2. The Encoder sensor is connected to PIN 2 and 3. Both PINs have a counter feature to count pulses. The motor driver is connected to PIN 6, 7, and 8. PIN 6 functions to adjust the motor's angular speed with the Pulse Width Modulation (PWM) feature. At the same time, PIN 7 and 8 function to regulate the direction of rotation of the motor (clockwise or counterclockwise).
The voltage source is obtained from the Power Supply Unit (PSU) with a voltage of 12V. The encoder sensor requires a voltage of 3.3V, which is obtained from the Arduino Uno minimum system. The L298 Motor Driver requires a 5V and 12V voltage source. In the motor driver, the 5V voltage functions as the electronic circuit voltage source, while the 12V voltage is the DC motor voltage source.
The control system block diagram is shown in Figure 3. This system is categorized into a closed-loop control system. Setpoint block is a reference value that the system must follow. The PID controller is a Proportional-Integral-Derivative Control. The system to be controlled is a DC motor. The system output is angular velocity. The feedback uses an encoder sensor to calculate the angular velocity of the DC motor system.

Angular Velocity Counter
The angular velocity can be obtained by counting the pulses from the encoder sensor in one minute. The angular speed is calculated using an encoder mounted on the end of the DC motor. The angular velocity calculation can be written as Where is the number of rotations on (sample time). The number of rotations can be achieved from, where is the number of pulses in the sample time, the variable ! is the number of pulses in one turn. According to the motor datasheet, there are 600 pulses in one loop. The sample time used in the program " is 50ms need to be changed with (3) to get time, , in one minute.
The constant 1000 is the conversion from milliseconds to seconds, and 60 is the second to minute conversion constant. Thus, the RPM can be calculated as,

Derivative Integral Proportional Control (PID)
PID controls consist of proportional, integral, and derivative controls [43][44] [45]. The PID Control equation in the time domain is, where ( ) is a control signal, $ is the proportional control parameter value, % is integral time dan ( is derived time, ( ) is the error or difference between the reference value and the feedback value. The PID controller can be written in another form as [46][47] The gain constant % is the value of the integral control parameter and ( is the value of the derived control parameter. PID control has characteristics that influence system response. It is because of the different controller structures. Proportional control deals with the error between the reference value and the feedback value. The integral control deals with the sum of all errors. The child control corresponds to the current error with the previous error.

Algorithm
The software used to create an embedded control program is the Arduino IDE. The Arduino IDE software and the embedded control main program with PID control are shown in Figure 4 (a). Simultaneously, the embedded control program flow chart is shown in Figure 4 (b). The main program has two parts, namely the angular velocity calculation program according to Equation (4) and the PID control program based on Equation (6). The parameters that must be determined before running the system are the reference value (SP) and the PID parameter (KP, KI, KD). The control system will continue to run until the supply is turned off or reaches some data. The PID control will calculate the PWM value sent to the motor. The angular velocity value is sent to computer to be displayed on the computer as a value or graph.

RESULT AND DISCUSSION
In this section, there are several tests as follows. The first part is about the open-loop system response [48]. The second part is about the closed-loop system response of the PID Controller. The third part is about the response to variations in the reference value and the effect of different sample times. The last part compares the systems without and with PID control hardware used in this study is shown in Figure 5.
The price of the Arduino Uno component is IDR 70,000. The price of the L298 motor driver is IDR 25,000. The price of a 25GA370 DC Motor with an encoder sensor is IDR 125,000. The PSU price is IDR 30,000. The connecting cable, holder and plastic box is IDR50,000, so the total component price is IDR300,000. These components' price is lower than using other devices such as the NI-DAQ [49] or PLC [50]. System performance is measured using system response. Some of the observed system response parameters are rise time, settling time, overshoot, and steady-state error. The expected system response is that it has a small rise time, has a short stabilization time, has a small overshoot, and the steady-state error is zero.

Open Loop Testing
The results of the implementation of the open-loop test hardware are shown in Table 1 and Figure 6. Arduino Uno uses 8-bit PWM, with a data range between 0-255. The motor driver uses a 12-volt power supply. The maximum voltage to the DC motor is 10 volts measured at the motor driver output. The minimum PWM is 50, and if the PMW is below 50, the DC motor cannot rotate just buzzing. There are two sample times used in this study, namely 50ms and 100ms. Based on Figure 3, the 50ms sample time provides a more stable angular velocity than the 100ms sample time. It can be seen clearly in the system response with PWM = 250 that a sample time of 100ms produces a response with some oscillations (some ripples) after reaching a steady state. Sample time is critical for system accuracy and response speed. Using a smaller sample time, for example, 50ms, the delay for the system to respond to errors is also smaller. Therefore, the system can prevent the output from having errors. The system will then respond more quickly and produce a more stable output.

DC Motor Step Reference Response with PID Control
The proportional control system response is shown in Table 2 and Figure 7. The reference value is 100RPM. In Table 2, increasing proportional control (KP) can reduce steady-state errors. In Figure 4, it can be seen that the steady-state error is reduced. Proportional control increases the overshoot value and reduces the rise time. Thus, in hardware implementations, it can be seen that proportional control affects the reduction in rising time, increased overshoot, and reduction in steadystate errors. Table 2 The response of the integral control system is shown in Table 3 and Figure 8. It can be seen that the increase in integral control (KI) can eliminate steady-state errors and result in faster system response. Larger integral controls have faster ride times but have greater overshoot and undershoot. The change in the value of the integral control that is not too large can make the system experience overshoot and undershoot. Thus, integral control affects increased overshoot, increases undershoot, reduces ride time, and eliminates steady-state errors. The response of the derivative controller is shown in Table 4 and Figure 9. It can be seen that increasing derivative control (KD) can reduce overshoot but make the system experience undershoot. The larger the derivative control, the greater the undershoot value. Descent control can increase the ride time but can also reduce the ride time after the undershoot appears. Thus, derivative control effects reducing overshoot, reducing rise time, and increasing undershoot.   Figure 9. Closed-Loop System Response Derivative Control Table 5 summarizes the characteristics of the PID controller based on the implementation of the hardware system response. Proportional control and integral control are suitable for reducing ride time but have the risk of increasing overshoot. The best function of proportional control is to reduce ride time, and the best function of integral control eliminates steady-state errors. Derivative controls are suitable for reducing overshoot but have the risk of increasing the undershoot. Accordingly, derivative control should not be overestimated.

Testing Reference Value and Sampling Time
The best PID parameters are shown in Table 6 and Figure 10. The setpoint value is 100RPM. The best PID control parameter (KP, KI, KD) is number 4. System response numbers 2 and 3 have undershot. That's because of the great descent controls. Increased derivative control must be careful because it will give a decreased response. The overshoot response is given by number 1 because of its large proportional value.  The next test is the variation of the reference value and the response time of the sample. There are two sample times used in this study, 50ms and 100ms. The results are shown in Table 7 and Figure 11. The PID controller can control and stabilize the system at multiple set points and achieve a reference signal. Sample time affects system response but can still follow set points. 50ms sample time provides a faster response than 100ms response. Thus, a smaller sample time is good for faster system response. However, it should not be too small as it can eliminate the original characteristics of the angular velocity data.

Comparison of Systems without and with PID Control
This section describes the comparison of systems without and with PID control which is summarized in Table 8. A system without PID control is shown in Figure 12 (a), and a system with PID control is shown in Figure 12 (b). The most visible thing from comparing the two systems is that the performance reaches the reference value. Systems without PID control need time to set the correct PWM value for the motor's angular speed to reach the reference value. It takes a lot of experimentation to reach the reference value, especially if the reference value has to be changed. Meanwhile, systems with PID control can easily reach the reference value, even with reference value changes. Systems with PID control can automatically adjust to the reference value, while systems without PID control have to adjust manually.
A system without a PID control cannot withstand disturbances which cause the angular velocity to not match the reference value. Meanwhile, systems with PID control are resistant to interference to maintain the DC motor's angular speed according to the reference value. Systems without a PID control will have a steady-state error value if there is a change in the reference value or interruption. Meanwhile, PID-controlled systems do not have steady-state error values. Therefore, a system with PID control is better than a system without PID control in system performance in achieving the reference value.

CONCLUSIONS
This study proposes controlling a DC motor system using Proportional Integral Derivative Control (PID) using the embedded Arduino Uno system. The PID controller can control and stabilize DC motors in the Embedded System using the Arduino Uno. The system can achieve different reference values with a steady time of under one second. Proportional control has the characteristic of reducing rise time but increasing overshoot. Integral control has the characteristics of eliminating steady-state errors and increasing overshoot. Derivative control has the characteristic of reducing overshoot but increasing undershoot. Shorter sample times provide a faster and more stable system response. However, the sample time should not be too short of giving the original characteristics of the output. The best PID controller for 100RPM reference is KP = 0.7; KI = 0.3; KD = 0.2 with a sample time of 50ms. Comparison with systems without PID control, systems with PID control have the advantage of easily reaching the reference value even when there is a change in the reference value.