Part 1-Simulation of the Arduino based Temperature Controller
Part 1-Simulation of the Arduino based Temperature Controller
by
Technician: Mr B. Williams
Bellville Campus
Figure 2: Arduino based Temperature Controller showing the heaters and fans.
To control the switching of the heaters and fans, each component required a MOSFET hence 2
MOSFETs were implemented to switch the fans and heaters on and off according to the given set
point. The MOSFETS can be seen in Figure 3.
Figure 4: Arduino based Temperature Controller focusing showing the Voltage regulator and jack.
In order to understand the programming for this controller, the operation of the system is required.
Firstly, a set point is required. The Arduino will accept the set point value and make a decision
based on the temperature reading of the sensor. If the temperature reading is lower than the set
point, the Arduino will send the difference between to set point and temperature reading as a 0𝑉𝑉 to
5𝑉𝑉 signal to the MOSFET. The difference between the set point and actual reading is the error
signal. The MOSFET will allow 0𝑉𝑉 or 12𝑉𝑉 through to the heaters causing the heater’s temperature
to increase. When the temperature of the heaters reaches the setpoint, the error signal will reach a
value of approximately zero. The Arduino will send a signal to the MOSFET to turn off the heaters
until the error is no longer zero. Since there is a delay in response time the temperature reading
will increase to above the set point. To ensure the set point is maintained with minimal oscillations
and the system does not become unstable, the Arduino will send a 0𝑉𝑉 𝑡𝑡𝑡𝑡 5𝑉𝑉 signal to the MOSFET
to switch the fans on or off. In the event that the temperature of the heaters exceeds a value close
to the set point, the MOSFET will receive 5V from the Arduino and allow 12V to the fans switching
it on until the temperature has decreased to the set point. This system will run continuously until
the desired response is shown. In order to program the temperature controller various hardware
packages are required to be installed as an add-on to the MATLAB software.
The icon required to add the extension packages is called Add-Ons and can be seen
highlighted in Figure 7.
The “Add-Ons Explorer” window will automatically open showing the various extension packages
that can be added to MATLAB making the software compatible to external hardware such as
Arduino and Raspberry Pi. The window can be seen in Figure 9.
Figure 10: Add-Ons Hardware Support Package showing the search bar.
Multiple extensions will show after searching. Select the extension according to the extensions
provided in Table 1. Once the extension required has been identified using table 1, click on the
extension.
Simulink Real-Time
Click the install option to show the drop-down menu. The drop-down menu consists of install and
download only. Select the install. If the user is not signed in, Mathworks will require the user to
sign in using their details. Sign in using student details. It may request for email verification. Press
Continue followed by accept. The install drop-down menu can be seen in Figure 12 and the login
window in Figure 13.
Figure 12: MATLAB Support Package for Arduino Hardware Installation menu.
A pop up with a heading Third-Party Software will display, ensure the name of the extension
package corresponds to what is shown in the block as seen in Figure 15. If all the information is
correct, click next.
The Support Package Installer window will display asking for Support Package. There should be
only one option: Arduino (MATLAB). Select this option and click next. Ensure the “Enable
Installation of Arduino USB Driver” box is ticked. If not ticked, click on the box to “tick” the box and
click next as seen in Figure 17. The support package has been setup.
Figure 17: Arduino USB Driver Installation.
An external window may pop up requesting to install the device software. Click Install as seen in
Figure 18. Return to the Software Package Installer window and click finish. The extension may
require to setup the connection to the Arduino. Plug the Arduino into the programming device and
continue with the steps as seen in Figure 18,19,20,21,22 and 23.
In the tool strip, there are 4 blocks grouped together as seen in Figure 28 This icon represents the
library browser and where all the function blocks are stored that will be utilized when designing the
temperature control circuit.
The temperature control circuit to implement is a simulation of the actual temperature control
circuit to show the ideal response of the inputs and outputs of the system. The summing junction
subtracts the actual temperature reading from the set point to produce an error signal. The error
signal will be sent into a relay. The relay will switch the heaters on or off depending on the error
signal. Practically, the heaters are connected to a PWM pin on the Arduino. This Arduino requires
a signal from 0 to 255 to send a voltage from 0V to 5V to the PWM pin.
In order for the heaters to raise the temperature to the set point temperature, within a reasonable
amount of time, a maximum voltage of 12V is required. Since the Arduino cannot provide the 12V
directly from the pin an external power supply was implemented. To switch the heaters on and off
external control was added. A MOSFET is connected to the PWM pin. A MOSFET is a high power,
controllable switch. The MOSFET will receive the voltage range of 0V to 5V from the PWM pin and
allow 0V or 12V to be sent through to the heaters.
On the right hand side, a list of various libraries is provided as seen in Figure 29 Scroll through the
list to find the Sources library. Select and insert the Pulse Generator as seen in Figure 31. The
pulse generator represents the change in temperature over time. Double click on the pulse
generator and change the Amplitude to the first temperature provided. Change the Period to 180
and Pulse width to 50. The parameter changes can be seen in Figure 31.
Figure 31: Pulse Generator insertion and parameter change in Simulink Blank Model.
Find the summing junction in the Math Operations library as seen in Figure 32. Click and drag the
summing junction onto the Simulink Blank model and place it just above the pulse generator as
seen in Figure 33. Double click on the summing junction to change the parameter from |++ to |+-
as seen in Figure 34. Connect the output of the pulse generator to the negative input of the
summing junction as seen in Figure 34.
Change the parameter of the “Switch on point” to 0.1 and the “Switch off point” value to 0.0001.
Change the “Output when on” point to 255 and the “Output when off” to 0. The value
250 represents 12𝑉𝑉 and the 0 represents 0𝑉𝑉. These voltages will be sent to the heaters to turn it
on and off. The relay must be connected to a scope. This function can be found in the Sinks folder
in Simulink as seen in Figure 39. Select and drag the Scope function to the right of the relay.
Connect the output of the relay to the scope. Change the name of the scope to “To heaters”. The
scope will display the signal being sent to the heater as the temperature fluctuates. The
connections and name of scope can be seen in Figure 40.
Figure 39: Scope Selection from Library.
Figure 41: Interval test Dynamic Selection and Insertion into Simulink Blank Model.
Connect the set point to the lower limit of the Interval Test Dynamic function. Connect the actual
temperature reading to the middle input and connect a constant block to the upper limit. Change
the parameter of the constant block to 100. The value of 100 represents 100 degrees Celcius. The
connections of the Interval Test Dynamic Function can be seen in Figures 42.
The response from the relay to the heater, output from the interval Test Dynamic, signal to the fan
and error signal are required thus select 2 more scopes and place in the circuit as seen in Figure
48.
Figure 48: Multiple Scope Connection and labelling.
Once the code has been completed as seen in Figure 48, set the Stop time to 1500 then click the
Run button as seen in Figure 49 to run the code. The scopes will automatically open. If the scopes
do not open, double click on each scope to show the responses of the error signal, heaters, fans
and outputs.