0% found this document useful (0 votes)
6 views

Part 1-Simulation of the Arduino based Temperature Controller

The document outlines the design and implementation of an Arduino-based On/Off temperature controller using MATLAB Simulink, aimed at helping students apply theoretical knowledge to practical applications. It details the components involved, including MOSFETs for switching, a voltage regulator, and the programming process necessary to maintain a specified temperature. Additionally, it provides step-by-step instructions for installing MATLAB extensions and building the control circuit in Simulink to simulate the temperature control system.

Uploaded by

nkosimandla1606
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Part 1-Simulation of the Arduino based Temperature Controller

The document outlines the design and implementation of an Arduino-based On/Off temperature controller using MATLAB Simulink, aimed at helping students apply theoretical knowledge to practical applications. It details the components involved, including MOSFETs for switching, a voltage regulator, and the programming process necessary to maintain a specified temperature. Additionally, it provides step-by-step instructions for installing MATLAB extensions and building the control circuit in Simulink to simulate the temperature control system.

Uploaded by

nkosimandla1606
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Arduino based ON/OFF Temperature Controller Simulation

using MATLAB Simulink

by

The Controls Team

at the Cape Peninsula University of Technology

Technician: Mr B. Williams

Bellville Campus

CPUT copyright information


Project may not be published either in part (in scholarly, scientific or technical journals), or as a whole (as a
monograph), unless permission has been obtained from the University.
Introduction
The design and implementation of the Arduino based temperature controller was based on
students who struggle to understand and integrate the theory taught during class into a real-life
application. This temperature controller was designed and implemented by the Control’s Team at
Cape Peninsula University of Technology under the guidance of Mr B. Williams and Mrs
Tshemese.

The On/Off Temperature Controller


The purpose of an On/Off temperature controller is maintaining a given temperature using a
control system. A control system consists of various components working together to achieve a
common objective. The objective of this control system was to maintain a given temperature by
programming a basic on/off control circuit in MATLAB, Simulink. The program was downloaded to
a physical On/Off temperature controller. In order to program the control circuit, the physical circuit
must be understood. A picture of the temperature controller can be seen in Figure 1. This
controller consists of various components. One of the main components being a power resister.
The power resistors represent the heaters of the circuit.

Figure 1: Arduino Based Temperature Controller.

Figure 1: Arduino Based Temperature Controller.


A 12V fan was implemented to reduce the overshoot of the heaters when the set point was
reached. The heaters and fans can be seen in Figure 2.

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 3: Arduino based Temperature Controller focusing on the MOSFETS.


To power the Arduino a voltage regulator was implemented to step down the 12V supply to 9V.
The jack connected to the regulator can be seen in Figure 4. Lastly, the Arduino Uno was utilized
as the programmable controller.

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.

Step 1: MATLAB Installation


Ensure that the MATLAB program has been installed on the device required for programming. An
icon, as seen in Figure 5, should be on the desktop screen. Double click on this icon to open the
program.

Figure 5: MATLAB Desktop Icon.


Step 2: MATLAB Extensions
The program should open the home page as seen in Figure 6. At the top of the home screen, just
below the home tab, the tool strip can be found.

Figure 6: MATLAB Home page.

The icon required to add the extension packages is called Add-Ons and can be seen
highlighted in Figure 7.

Figure 7: Add-Ons Icon.


Click on the Add-Ons icon. A drop-down menu will appear. Select the option “Get Hardware
Support Packages” as seen in Figure 8.

Figure 8: MATLAB Get Hardware Support Packages.

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 9: Add-Ons Hardware Support Package start page.


To add the Arduino extension/ support packages, type in the name of the required extension in the
search tab seen in Figure 10. A list of the support packages required for this practical can be seen
in Table 1 with their corresponding pictures.

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.

Title of Support Package Picture of Support Package

MATLAB Support Package for Arduino


Hardware

Simulink Package for Arduino Hardware


How to interface Arduino with matlab using
simulink

Legacy MATLAB and Simulink Support for


Arduino

Simulink Real-Time

Simulink Desktop Real-Time

Instrument Control Toolbox


Model Predictive Control and Estimation with
Arduino.

Table 1: Table of extension packages required for the Temperature Controller.


In Figure 11, “MATLAB Support Package for Arduino Hardware” was selected. The extension
package will open on the desktop. On the right-hand side, two options can be seen: Learn More
and Install.

Figure 11: MATLAB Support Package for Arduino Hardware.

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.

Figure 13: MATLAB Verification Login Window.


Accept the Mathworks Auxiliary Software License Agreement as seen in Figure 14.

Figure 14: Mathworks Auxiliary Software License Agreement.

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.

Figure 15: Third Party Software.


The device will download the extension with all the required licenses. This may take a short period
of time. When the download is complete, a window will pop up stating “Installation Complete”. The
bottom right corner of the window provides two options: Setup Now and Setup Later. Select the
Setup Now option as seen in Figure 16.

Figure 16: Installation Complete: Setup Now.

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.

Figure 18: Windows Security to allow Arduino USB driver installation.


Figure 19: Arduino Hardware Setup.

Figure 20: Arduino Connection Type.


Figure 21: Upload Arduino Server.

Figure 22: Test Arduino Connection.


Figure 23: Arduino Hardware Setup Completion.
The examples window will automatically open and show various examples using the specific
extension. The installation of an extension is complete. This process must be repeated for each
extension in Table 1.
Normally, after installing one extension, the user will only have to add extensions instead of
installing thus instead of clicking the install option, click the add option followed by the add to
MATLAB as seen in Figure 24. This will automatically download and save the extension with
required licenses.

Figure 24: Add on instead of installation of extension.


Figure 25: Addition of extension to MATLAB by adding option.

Step 3: Opening Simulink and checking the libraries.


On the left-hand side of the home page, create a new folder as seen in Figure 25 Double click on
the folder to the MATLAB home screen corresponds to Figure 26.

Figure 26: Creating Folder for Temperature Control Project.


The Simulink icon can be found in the tool strip as highlighted in Figure 26. Click this icon to open
the program. Once open, various options are provided. Select blank model. Save the model as
seen in Figure 27.

Figure 27: Selecting Blank Model for Temperature Controller.

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.

Figure 28: Library Icon.


Figure 29: Confirmation of correct libraries and libraries available.

Step 4: Building the ON/OFF 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 30: Pulse Generator Selection from Library.

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.

Figure 32: Summing Junction Selection.

Figure 33: Summing Junction Insertion into Simulink Blank Model.


:

Figure 34: Summing junction connection and parameter adjustment.


Select a constant block and place it to the left of the summing junction as seen in Figure 35. The
purpose of the constant block is to input the set point into the system. Double click on the constant
block to change the parameter to the temperature provided in the problem statement. Connect the
constant block to the positive of the summing junction. The parameter adjustment and connection
of the constant block to the summing junction can be seen in Figure 36

Figure 35: Constant Block Selection and insertion.


.

Figure 36: Constant Block Connection and Parameter Adjustment.


The output of the summing junction has to be connected to a relay to switch the heaters on and off
through the MOSFET. This relay can be found in the Discontinuities Library Click and drag the
relay to the right of the summing junction as seen in Figure 37.

Figure 37: Relay Selection from Discontinuous Library.


Double click on the relay to change the parameters. The first parameter is the switch on point.
This function switches the output on or off depending the on the values typed into the switch on
point and switch off point. The switch on point is the value at which the output will switch on. This
limit works with the “output when on” parameter. When a value is sent into the input of the relay,
the value is read and compared to the switch on and switch off points. If the value is equal to or
greater than the switch on, the output will turn on and the output when on value will be sent on the
output of the relay to the next “block.” If the value is equal to or less than the switch off point, the
relay will “switch off” the output to the value typed in the “output when off” box as seen in Figure 38

Figure 38: Relay Insertion and Parameter Adjustment.

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 40: Scope Connections and Labelling.


Select the Interval Test Dynamic function to control the speed of the fan. The purpose of the fans
are to assist in maintaining the temperature when the set point has been reached. The greater the
deviation from the set point the greater the fans speeds to cool the heaters down to the required
temperature. The closer the temperature to the set point, the more the fans will switch on and off
in an attempt to ensure the set point is reached and maintained with minimal oscillations. The
Interval Test Dynamic Function reads the input signal and compares that value to the upper and
lower limits. If the value exceeds the lower limit, the Interval Test Dynamic Function will output a
1(true). If the value is lower than the lower limit or higher than the upper limit the Interval Test
Dynamic Function will output a 0 (false). This function block can be found in the Logic and Bit
Operations library. Select and drag the interval test function and place it above the second
summing junction as seen in Figure 41.

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.

Figure 42: Interval Test Dynamic Connections and Parameter Adjustment.


To the right of the Interval Test Dynamic Function add another gain function. Connect the output of
the Interval Test Dynamic Function to the input of the gain function. Change the gain parameters
to 255. The selection and connections can be seen in Figures 43 and 44.

Figure 43: Gain Selection and Insertion.

Figure 44: Gain Connection and Parameter Adjustment.


Since the Interval Test Dynamic function produces a true or false output and the Arduino PWM Pin
requires a value from 0 𝑡𝑡𝑡𝑡 255, the gain must be set to 255 to ensure a 5𝑉𝑉 is sent from the Arduino
pin to the MOSFET controlling the fan. Select the scope from the Sinks Library as seen in Figure
45. Connect the output of the gain function to a scope to simulate the signal from 0 𝑡𝑡𝑡𝑡 255 going
to the Arduino PWM Pin. Change the name of the fan to “To Fan”. The connections and labelling
can be seen in Figure 46.

Figure 45: Scope Selection for Fan.

Figure 46: Scope Connection and Labelling.


In order to see the responses of each component in the control system, multiple scopes are
required. Open the library browser and select the scope function in the Sinks library as seen in
Figure 45. The first response required is the current temperature. Click and drag the scope to the
right of the pulse generator. Connect the input of the scope to the output of the pulse generator as
seen in Figure 47.

Figure 47: Scope Connection and Labelling.

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.

Figure 49: Adjust Simulation Parameters and Run Simulation.


Step 5: Results
Once the previous steps have been completed and the code is running, the program with the
scopes showing the responses should correspond to Figure 50.

Figure 50: Expected Results on Scopes.

You might also like