PID Arduino Control of Temperature by PWM
PID Arduino Control of Temperature by PWM
Engineering
Manuscript 1004
This item has been accepted for inclusion in DigitalCommons@Fairfield by an authorized administrator of
DigitalCommons@Fairfield. It is brought to you by DigitalCommons@Fairfield with permission from the rights-
holder(s) and is protected by copyright and/or related rights. You are free to use this item in any way that is
permitted by the copyright and related rights legislation that applies to your use. For other uses, you need to obtain
permission from the rights-holder(s) directly, unless additional rights are indicated by a Creative Commons license
in the record and/or on the work itself. For more information, please contact [email protected].
Online at https://digitalcommons.fairfield.edu/ijcase/ Published by Fairfield University, DigitalCommons@Fairfield © 2021
Voltage
by Seiichi Nakamori
INDEX TERMS Constant temperature control, PWM, AC voltage, Arduino, PID controller, A/D conversion
_____________________________________________________________________________________
_____________________________________________________________________________________
Fig. 1 Block diagram of the feedback control system for constant temperature adjustment.
The proportional, integral, and derivative coefficients for the PID controller are tuned based on the above
performance appropriately.
1 𝑡 𝑑𝑒(𝑡)
u(t) = 𝑘𝑝 (𝑒(𝑡) + ∫ 𝑒(𝑡)𝑑𝑡 + 𝑇𝑑 ).
𝑇𝑖 0 𝑑𝑡
𝑘𝑝 : proportional gain; 𝑇𝑖 : integral time constant; 𝑇𝑑 : derivative time constant;
• Fig. 2 shows the circuit scheme for constant temperature control on the thermal sensor IC LM35DZ with
incandescent light as a heat source. The outline of the operation is as follows.
_____________________________________________________________________________________
(2) The IC LM35DZ thermal sensor converts heat from the 100 [W] incandescent lamp to DC voltage.
(3) Both Phototriac and Triac work as a zero-cross solid state relay (SSR) (Nakamori, 2017; Suzuki, 2016). Following
the zero-cross switching of the SSR, the AC voltage, with the zero-cross waveform, is supplied to the filament lamp.
(4) Because the voltage of the IC thermal sensor is low, the operational amplifier LM358N boosts the voltage. The
temperature coefficient of the IC thermal sensor is 10.0 [mV/℃], and the temperature accuracy of LM35DZ is ± 1/4
[℃] at room temperature.
(5) The voltage, amplified in step (2), is A/D converted by Arduino with a resolution of 10 [bits]. The 10-bit analog-
to-digital converter (ADC) divides the voltage range (0 ~ 5 [V]) into 10-bit levels 0 ~ 1023.
(6) In the experiment of Section 3, the reference input level is 400 for temperature 40 [℃].
(7) Comparing the reference input level with the A/D converted value in Arduino, P, PD, PI, I, and PID controllers
operate so that the A/D converted value approaches the reference input level, respectively. If the PWM value
changes to negative, we set the value to zero. If the PWM value exceeds 255, we set the value to 255.
_____________________________________________________________________________________
Fig. 3 shows the experimental picture of constant temperature control. EPS box, Arduino, solid-state relay
semiconductor kit, which consists of phtotriac and triac, etc., liquid crystal display (LCD), etc. are located. As shown
in Fig.4, the IC thermal sensor and the incandescent lamp are placed in the EPS box. The depth, width, height and
thickness within the EPS box are 14.5 [cm], 35 [cm], 28 [cm] and 2.5 [cm]. EPS belongs to the thermal insulation
material. The material having a thermal conductivity not exceeding 0,05 [W/m・K] is referred to as the thermal
insulation material. Fig. 5 shows the PID control program, which controls the temperature of the IC thermal sensor.
In the program, the control input has the form:
𝑘
𝑒(𝑘) − 𝑒(𝑘 − 1)
u(k) = 𝑘𝑝 𝑒(𝑘) + 𝑘𝑖 ∑ 𝑒(𝑖)∆𝑡 + 𝑘𝑑 ,
∆𝑡
𝑖=1
∆t = 1.12 (second), Deviation: e(k) = R(k) − M(k) ( see the block diagram of Fig. 1)
R(k): the desired temperature at discrete time k∆. M(k): the measured temperature at discrete time k∆.
Because the change of the temperature inside the EPS box is relatively slow, the value of ∆𝑡 is set to 1.12. The
discrete-time control input u (k) is not strictly a numerical expression for the control input u(t) in continuous-time
systems. In this paper, we examine to adjust the PID parameters 𝑘𝑝 , 𝑘𝑖 , and 𝑘𝑑 from the viewpoints of the transient
and steady-state performances such as the overshoot, rise time, settling time, delay time, and the steady-state
deviation. In the PID programs of Fig. 5 and Fig. 16, dt stands for ∆𝑡.
_____________________________________________________________________________________
_____________________________________________________________________________________
void loop() {
analogWrite(9,co);
for(int i=0; i<1000; i++){
d+=analogRead(A0);
}
d=d/1000;
dt=(micros()-pretime)/1000000;
//Serial.print("dt=");
//Serial.println(dt);
pretime=micros();
PID_error=moku-d;
I+=PID_error*dt;D=(PID_error-PreP)/dt;
PreP=PID_error;
// PID controller:
co = kp*PID_error+kd*D+ki*I;
// P controller:
//co = kp*PID_error;
// PD controller:
//co = kp*PID_error+kd*D;
// PI controller:
co = kp*PID_error+ki*I;
Serial.print("check=");
Serial.println(d);
delay(500);
if (co <0) {
co=0;
}
else if (co >255) {
co=255;
}
else {
// operation C
co=co;
}
_____________________________________________________________________________________
In Fig.5 the computed value of dt is 1.12 (second). Fig. 6 illustrates the temperature vs. time (second) by the P
controller for 𝑘𝑝 = 1.0, 𝑘𝑝 = 5.0 and 𝑘𝑝 = 100. As 𝑘𝑝 increases, the delay time becomes shorter and the steady-
state deviation is reduced. From Fig. 5 we see that the P controller has this feature so the steady-state deviation
remains. Fig. 7 illustrates the PWM control signal vs. time (second) by the P controller for 𝑘𝑝 = 1.0, 𝑘𝑝 = 5.0 and
𝑘𝑝 = 100. Fig. 8 illustrates the temperature vs. time (second) by the PD controller for 𝑘𝑝 = 5.0, 𝑘𝑑 = 1.0 and 𝑘𝑝 =
5.0, 𝑘𝑑 = 5.0. From Fig. 7 and Fig. 8, for 𝑘𝑝 = 5.0, by adding the D controller to the P controller, i.e. for the PD
controller, the deviation of the stationary state is reduced. Fig. 9 illustrates the PWM control signal vs. time (second)
by the PD controller for 𝑘𝑝 = 5.0, 𝑘𝑑 = 1.0 and 𝑘𝑝 = 5.0, 𝑘𝑑 = 5.0. Fig. 10 illustrates the temperature vs. time
(second) by the PI controller for 𝑘𝑝 = 100.0 and 𝑘𝑖 = 0.8, 𝑘𝑝 = 100.0 and 𝑘𝑖 = 1.0, and 𝑘𝑝 = 100.0 and 𝑘𝑖 = 5.0.
In Fig. 10 the overshoot is significant for 𝑘𝑖 = 1.0 and 𝑘𝑖 = 5.0. By adding the I controller to the P controller, i.e., in
the PI controller, the steady-state deviation converges to zero as time progresses. Fig. 11 illustrates the PWM control
signal vs. time (second) with the PI controller for 𝑘𝑝 = 100.0 and 𝑘𝑖 = 0.8, 𝑘𝑝 = 100.0 and 𝑘𝑖 = 1.0, and 𝑘𝑝 =
100.0, 𝑘𝑖 = 5.0. Fig. 12 illustrates the temperature vs. time (second) by the I controller for 𝑘𝑖 = 0.5, 𝑘𝑖 = 1.0 and
𝑘𝑖 = 5.0. Fig. 13 illustrates the PWM control signal vs. time (second) by the I controller for 𝑘𝑖 = 0.5, 𝑘𝑖 = 1.0 and
𝑘𝑖 = 5.0. Fig. 12 shows that the overshoot by the I controller is significant and the settling time is long. However,
the steady-state deviation converges to zero. Fig. 14 illustrates the temperature vs. time (second) with the PID
controller for 𝑘𝑝 = 30.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, 𝑘𝑝 = 70.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, and 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0 and
𝑘𝑑 = 5.0. Fig. 15 illustrates the PWM control signal vs. time (second) with the PID controller for 𝑘𝑝 = 30.0, 𝑘𝑖 = 5.0
and 𝑘𝑑 = 5.0 , 𝑘𝑝 = 70.0 , 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0 , and 𝑘𝑝 = 100.0 , 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0 . Compared to the I
controller, the settling time by the PID controller is short. The steady-state deviation by the PID controller converges
to zero about 300 (second) later. The overshoot by the PID controller is as significant as that by the I controller.
Compared to the PI controller for 𝑘𝑝 = 100.0 and 𝑘𝑖 = 1.0, and 𝑘𝑝 = 100.0 and 𝑘𝑖 = 5.0, the overshoot by the PID
controller is relatively large.
_____________________________________________________________________________________
Fig. 7 PWM control signal vs. time (second) by P controller for 𝑘𝑝 = 1.0, 𝑘𝑝 = 5.0 and 𝑘𝑝 = 100.
_____________________________________________________________________________________
Fig. 9 PWM control signal vs. time (second) by PD controller for 𝑘𝑝 = 5.0, 𝑘𝑑 = 1.0 and 𝑘𝑝 = 5.0, 𝑘𝑑 = 5.0.
_____________________________________________________________________________________
Fig. 11 PWM control signal vs. time (second) by PI controller for 𝑘𝑝 = 100.0 and 𝑘𝑖 = 0.8, 𝑘𝑝 = 100.0 and 𝑘𝑖 = 1.0,
and 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0.
_____________________________________________________________________________________
Fig. 13 PWM control signal vs. time (second) by I controller for 𝑘𝑖 = 0.5, 𝑘𝑖 = 1.0 and 𝑘𝑖 = 5.0.
_____________________________________________________________________________________
Fig. 15 PWM control signal vs. time (second) by PID controller for 𝑘𝑝 = 30.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, 𝑘𝑝 = 70.0,
𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, and 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0.
To reduce the overshoot and the settling time in Fig. 14 by the PID controller, this paper presents the Arduino
program of Fig. 16, compared to the program in Fig. 5, the bold italic typeface lines of Fig.16 are newly inserted for
the I controller in the PID controller. That is, the I controller in the PID controller operates within the deviation ± 3
(℃). If the absolute value of the deviation exceeds 3 (℃), the PD controller works. Taking into consideration the
feasible transient features of Fig. 8 for the rise time, settling time, and delay time by the PD controller, this operation
is introduced. Villasante-Muñoz suggests this idea associated with the I controller. Fig. 17 illustrates the temperature
_____________________________________________________________________________________
void loop() {
analogWrite(9,co);
for(int i=0; i<1000; i++){
d+=analogRead(A0);
}
d=d/1000;
dt=(micros()-pretime)/1000000;
//Serial.print("dt=");
//Serial.println(dt);
pretime=micros();
_____________________________________________________________________________________
Fig. 16 PID control program with I controller working within deviation ± 3 (℃).
_____________________________________________________________________________________
Fig. 18 PWM control signal vs. time (second) by PID controller for 𝑘𝑝 = 30.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, 𝑘𝑝 = 70.0,
𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, and 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0 with the I controller working within deviation ± 3
(℃).
_____________________________________________________________________________________
Fig. 19 shows the pulse width modulated waveform of the AC voltage, by the zero-cross SSR for the PWM value
128. The voltages in Fig. 19 display the 1/10 values of the effective or root-mean-square (RMS) values and the peak-
to-peak values of the AC voltages measured through the probes of channels 1 and 2.
IV. CONCLUSION
This paper has proposed the constant control technique of the temperature using Arduino in a closed space of the
EPS box by adjustments of the temperature at the IC thermal sensor by the incandescent lamp. For the constant
temperature control with Arduino, the PWM technique is applied to the AC voltage by using the NPN transistor,
solid-state relay semiconductor kit as the zero cross-type SSR, etc. The P, PD, PI, I and PID controllers adjust the
constant temperature, respectively. For the desired temperatures 40 [ ℃], as time progresses, the controlled
temperature converges to the desired temperature for the PI, I, and PID controllers, including the I controller. For P
and PD controllers, the steady-state deviation remains. Fig. 17 illustrates the temperature vs. time (second) by the
PID controller for 𝑘𝑝 = 30.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, 𝑘𝑝 = 70.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, and 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0
and 𝑘𝑑 = 5.0 with the I controller working within the deviation ± 3 (℃). The overshoot and the settling time are
achievable in the order 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, and 𝑘𝑝 = 70.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0. For PID settings
𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, and 𝑘𝑝 = 70.0, 𝑘𝑖 = 5.0 and 𝑘𝑑 = 5.0, after about 200 (second), the steady-
state deviation converges to zero. The best PID parameters are 𝑘𝑝 = 100.0, 𝑘𝑖 = 5.0, and 𝑘𝑑 = 5.0 with the I
controller working within the deviation ± 3 ( ℃ ). PWM control signal varies stochastically as seen from the
experiments in Section 3.
Learning about the constant value control of temperature in closed space could be helpful for the students of high
school or university to understand the PID control concept with the inexpensive experimental device in this paper.
REFERENCES
[1] Ibrahim, D., Microcontroller Based Temperature Monitoring and Control. Elsevier Science & Technology
Books, 2002.
[2] Hebel, M. and W. Devenport, “Industrial Control - Student Guide, Version 1.1.” Parallax Inc. [Online].
Available: http://mega-
avr.net/file/LITERATURA/PROGRAM/MK/Industrial%20Control%20(Students%20guide,%201999,%20%20v1.
1%20).pdf
_____________________________________________________________________________________
[4] Ogata, K., Modern Control Engineering, 5th ed. Prentice Hall, 2010.
[5] Ogata, K., Discrete-Time Control Systems, 2nd ed. Prentice-Hall, 1995.
[6] “PID temperature control learning device, KENTAC 3522-S.” Syouwa Dengyou Inc. [Online]. Available:
https://www.k-sd.co.jp/kentac3522s/
[7] Nakamori, S. and T. Sonoda, “Constant illumination control of filament lamp by phase delay of AC voltage,”
Natural Science, Bulletin of the Faculty of Education, Kagoshima University, vol. 65, pp. 23–34, pp. 23–34,
2014.
[8] “Electronic work 31, Control of Triac by PIC, -PIC Controlled Dimmer, PICBasic Pro-.” [Online]. Available:
http://electroprojsk.fan.coocan.jp/eproj31.htm
[9] Nakamori, S., Akashi, M., Tsurudome, K. and T. Okugawa, in Microcontroller-based Integral Control of
Temperature by Phase Delay of AC Voltage. Horizons in Computer Science Research, vol. 12, NOVA Science
Publishers, 2015, pp. 65–80.
[10] Nakamori, S., “Arduino-Based Integral Control of Temperature in a Closed Space by Applying PWM
Technique to AC Voltage,” in Horizons in Computer Science Research., vol. 15, NOVA Science Publishers,
2017, pp. 209–222. [Online]. Available: https://novapublishers.com/shop/horizons-in-computer-science-
research-volume-15/
[12] Silva, G. J., Datta A. and S. P. Bhattacharyya, PID Controllers for Time-Delay Systems. Birkhauser, 1973.
[13] Zheng, F., Wang, Q.-G. and T. H. Lee, “On the design of multivariable PID controllers via LMI approach,”
Automatica, vol. 38, pp. 517–526, 2002.
[14] He, Y. and Q. G. Wang, “An improved ILMI method for static output feedback control with application to
multivariable PID control,” IEEETransactionsonAutomaticControl, vol. 51, no. 10, pp. 1678–1683, 2006.
[15] Shimizu, K., “Dynamic output feedback control and dynamic PID control for linear MIMO systems via LMI,”
2016 IEEE Conference on Control Applications (CCA), 2016, doi: 10.1109/CCA.2016.7587940.
[17] Goyal, J. K., Aggarwal, S., Sahoo, P. R., Ghosh, S. and S. Kamal, “Design of robust PID controller using static
output feedback framework,” IFAC PapersOnLine, vol. 53–1, pp. 13–18, 2020, doi:
10.1016/j.ifacol.2020.06.00.
[18] Suzuki, M., Arduino Radio Robot Crafts by XBee. Tokyo Denki University Press, 2016.
https://web.tdupress.jp/downloadservice/ISBN978-4-501-33160-3/
Seiichi Nakamori is a Specially Appointed Professor in the Faculty of Education, Kagoshima University, from April, 2017 to date. He
was appointed Professor Emeritus, Kagoshima University, in April 2016. He was a Professor, Department of Technology, Graduate
School of Education, Kagoshima University from April, 1994 to March 2016, Associate Professor, in the Department from April, 1987
to March, 1994 and a lecturer, Interdisciplinary Chair (Applied Mathematics), Faculty of Engineering, Oita University, from April, 1985
to March, 1987.
He received the B.E. degree in Electronic Engineering from Kagoshima University in 1974 and the Dr. Eng. Degree in Applied
Mathematics and Physics from Kyoto University in 1982. He is mainly interested in stochastic signal estimation and image restoration
problems
_____________________________________________________________________________________