This is only a preview of the April 2020 issue of Practical Electronics. You can view 0 of the 80 pages in the full issue. Articles in this series:
|
Visual programming with XOD
By Julian Edgar
Fan Speed Controller
H
ow many times have you
been working with fan-cooled
equipment and then the fan
suddenly trips, coming on at full power
and disturbing all your concentration?
My bench-top power supply is terrible
for that – and worse still, when the
power supply is running a large load,
the fan constantly cycles on-off, onoff. It drives me mad! Or what about
a powerful fan-cooled audio amplifier? In quieter spots in the music, the
sound of a fan is likely to intrude.
Of course, at times you will need the
fan working hard, but often when the
fan is blasting at full speed, it really
only needs to be ticking over – and
catching the temperature rise before
it goes too far.
That’s where this little project comes
in. It is based on an Arduino Uno
and a small, inexpensive MOSFET
PWM control module. The Uno is
available from numerous suppliers,
and you can find the MOSFET module by searching on eBay for ‘3-20V
MOSFET MOS Transistor Trigger
Switch Driver Board PWM Control
Module’. For example, at the time of
writing item 303491652040 is just
£2.80 delivered. However, any similar PWM-controllable MOSFET board
will also work fine.
I used a Microchip MCP9700 temperature sensor, but any sensor that
can be easily configured to give a
temperature reading in degrees Celsius can be used. (The MCP9700 has
Fig.1. The fan speed controller uses an Arduino Uno board, MOSFET module and
temperature sensor. The use of XOD visual programming software allows easy changes
to be made to the controller’s operation. The temperature sensor is in the foreground. A
much more powerful fan than the one shown here can be used if required.
62
the advantage of being able to read
temperatures of less than zero with
a normal 5V supply, making this a
controller useful for a wide range of
applications.) In many uses, the temperature sensor will be attached to a
heatsink (eg, by a clamp), but it can
also be used to measure the temperature in free air.
Controlling the fan
The Arduino program (‘sketch’) is
written in Xod (pronounced ‘Zod’),
a free visual programming software
that is easy to follow – and very easy
to edit. In fact, to achieve the fan behaviour we want, we will change
the values in the program – so you
can think of this project as a PC-programmable fan controller. (For an
introduction to XOD, see the March
2020 issue of PE.)
So what parameters can be changed?
There are five settings:
Period over which temperature
reading is averaged
Temperature at which the fan starts
Temperature at which the fan reaches maximum speed
Minimum duty cycle at which the
fan can run (note that duty cycle
controls fan speed)
Hysteresis (the difference between
the fan switch-on and switch-off
temperatures).
Being able to alter all of these is important if the controller is to best suit
a specific application. For example,
to control the fan in a bench-top power supply, you might set the period
over which the temperature is averaged to two seconds, the temperature
Practical Electronics | April | 2020
temperature and hysteresis are added together, so the actual starting temp in this example will be 28°C.)
And the minimum duty cycle? That depends on the fan
– some will run down to 25% duty cycle, others not below 40%. Being able to set this minimum means the fan
is never fed (say) a 15% duty cycle, which would be an
average voltage too low to turn it.
Note that the fan that is used can be quite powerful: the
cited MOSFET module can run a continuous 5A at 12V –
60W. And, if an even more powerful fan is required, you
can simply specify a module with a higher current rating or add a heatsink to the shown module (in this form
it should be good for 10A).
Wiring
The MCP9700 temperature sensor has three connections:
+5V, ground and signal. Refer to Fig.3. Make these connections via header pins to the Arduino, using port A0
for the signal.
The MOSFET module has connections for PWM and
ground. Connect Port 9 to the ‘PWM’ terminal on the module, and the corresponding ground terminal to a ground
pin on the Arduino. The fan connects to the Out (+) and
(−) terminals and power to the DC (+) and (−) terminals.
Depending on the fan voltage (5 or 12V) you can run the
entire system on either of these voltages. Refer to Fig.3
for these connections.
Fig.2. The fan speed controller installed in a bench power supply.
The new boards are near the front – from left, voltage regulator
for the Arduino (needed here because of the 24V internal supply
of the bench supply), Arduino Uno and MOSFET module. The
temperature sensor is placed on the heatsink near the rear of
the power supply, adjacent to the fan.
at which the fan starts at 25°C, and the temperature at
which the fan is running at full power at 50°C. The hysteresis might be set to 3°C. (Note: in operation, the starting
Program
After you have installed XOD on your PC (see https://
xod.io/downloads/), you can download the fan controller program from the April 2020 page of the PE website
and then upload it to the Arduino. But the real beauty of
XOD is it’s easy to see how the program works, so let’s
turn to Fig.4. Don’t be daunted – I’ll break it down into
its parts. The circled numbers are matched on the XOD
diagram in Fig.4
G N D
P W M
+ 1 2 V
G N D
D 9
+
7
6
5
4
3
2
1
0
SCL
SDA
AREF
GND
13
12
11
10
9
8
–
DIGITAL
UNO
F an
M C P 9 7 0 0
M C P 9 7 0 0
V DD
V OUT
A0
A1
A2
A3
A4
A5
ANALOG IN
5V
RES
3.3V
5V
GND
GND
VIN
POWER
G N D
Practical Electronics | April | 2020
Fig.3. Connections to the Arduino Uno MOSFET
module and temperature sensor. The Uno can
be powered via its USB connection (5V), or up
to 12V via the VIN and GND terminals.
63
~
u
v
w
~
w
~
}
~
x
y
}
~
}
z
Fig.4. The program used in the Arduino,
written in the free visual software XOD.
See opposite for a description of how the
program works.
}
The five values down the right-hand side
(tagged ‘10’) can be altered to fine-tune
the action of the controller, with the revised
program then uploaded to the board.
When the software is uploaded in ‘debug’
mode, live readings can be seen in the five
boxes down the left-hand side (tagged ‘9’).
64
{
}
|
Practical Electronics | April | 2020
Temperature input
uStarting at the top, the temperature
input is continuously watched (ie,
looping) at Port A0.
Averaging
vThe next box averages the value. (A
higher number equals a longer averaging period.)
Scaling
wNext, we scale the reading so that
it is in degrees Celsius. (The second
scaling box can be used to tweak the
temperature sensor offset for highest
accuracy; 50 is the nominal value.)
Decision
xAfter that, there’s the first of the program’s decisions to be made – is the
measured temperature over 25°C? If
it is greater than 25 (ie, True), the ‘ifelse’ box passes the signal on; if not
(ie, False), it is replaced with a zero.
Hysteresis
yThe hysteresis box follows next.
This sets the difference between the
switch-on and switch-off temperatures. Here it has been set at 3°C. If the
temperature is not within this range
of the set point (ie, the fan is permitted to run), the ‘if-else’ box passes
that information on to the ‘map’ box.
Mapping
zThe ‘map’ box is a scaling device.
It takes an input value range (here set
from 25 to 50) and converts that into
a 0 to 1 output. (The PWM generator
– I’ll get to in a minute – requires an
input range of 0-1.)
Duty cycle decision
{Another ‘if-else’ box follows – this
allows the signal to pass only if it is
above 0.45 (ie, 45% duty cycle). If it
is below that, the signal is again replaced by a zero.
PWM generator
|The final box is a PWM generator.
It uses port D9 – and that’s where we
connected our PWM MOSFET module. This box outputs 100% duty
cycle when fed a 1, and 0% duty
cycle when fed 0. (Incidentally, the
output frequency is about 400Hz.)
Real-time watching
}Note the ‘watch’ boxes down the
left-hand side. If you upload the
program in debug mode (press the
bug-shaped icon at the bottom right of
the XOD screen to do this) the numerical values and logic (ie, true/false) at
each step of the program will be visible, ‘live’ in these boxes. By applying
heat (eg, with a soldering iron) to the
temperature sensor, you can watch the
program working.
System tuning
~This is also the time to fine-tune
those values – use the boxes down
the right-hand side of the program to
do that. Click on each and you can
change the value in the left-hand ‘Inspector’ column of the XOD software
before uploading the tuned program
to the Arduino board.
Conclusion
In this article the project has been
used to control fan speed in electronic equipment, but its range of
adjustments, capacity (using a suitable MOSFET module) to drive high
current loads and ability to read a
wide range of temperatures, means
the controller is suitable for many
applications. For example, it could
also be used to control pump speed
in a water-cooled PC, ventilate a garden hothouse, or control the speed of
a car radiator fan.
XOD files
The XOD file discussed in this article
can be downloaded from the April
2020 page of the PE website.
Teach-In 8 CD-ROM
Exploring the Arduino
This CD-ROM version of the exciting and popular Teach-In 8 series
has been designed for electronics enthusiasts who want to get to
grips with the inexpensive, immensely popular Arduino microcontroller,
as well as coding enthusiasts who want to explore hardware and
interfacing. Teach-In 8 provides a one-stop source of ideas and
practical information.
The Arduino offers a remarkably effective platform for developing a
huge variety of projects; from operating a set of Christmas tree lights
to remotely controlling a robotic vehicle wirelessly or via the Internet.
Teach-In 8 is based around a series of practical projects with plenty of
information for customisation. The projects can be combined together
in many different ways in order to build more complex systems that can
be used to solve a wide variety of home automation and environmental
monitoring problems. The series includes topics such as RF technology,
wireless networking and remote web access.
PLUS: PICs and the PICkit 3 – A beginners guide
The CD-ROM also includes a bonus – an extra 12-part series based around the popular
PIC microcontroller, explaining how to build PIC-based systems.
EE
FR -ROM
CD
ELECTRONICS
TEACH-IN 8
£8.99
FREE
CD-ROM
SOFTWARE
FOR
THE TEACH-IN
8
SERIES
FROM THE PUBLISHERS OF
INTRODUCING THE ARDUINO
• Hardware – learn about components and circuits
• Programming – powerful integrated development system
• Microcontrollers – understand control operations
• Communications – connect to PCs and other Arduinos
PLUS...
PIC n’MIX
PICs and the PICkit 3 - A beginners
guide. The why and how to build
PIC-based projects
Teach In 8 Cover.indd 1
04/04/2017 12:24
PRICE
£8.99
Includes P&P to UK if
ordered direct from us
SOFTWARE
The CD-ROM contains the software for both the Teach-In 8 and PICkit 3 series.
ORDER YOUR COPY TODAY!
JUST CALL 01202 880299 OR VISIT www.epemag.com
Practical Electronics | April | 2020
65
|