Click here to Skip to main content
15,880,543 members
Articles / Internet of Things / Arduino

Heat The Box - Temperature Control with Arduino Nano

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
7 Aug 2018CPOL7 min read 26.2K   424   9   7
This article describes one of my experiments: a temperature control system for a cartoon box.

Article presentation image

Picture 1 - The Temperature Control program running. In the background, the rather crowded cartoon box

Introduction

This article describes one of my experiments: a temperature control system for a cartoon box.

The 'system' features:

  • Four independent temperature measure points
  • One two-stages heater
  • A cooling fan
  • The Arduino Nano

Background

In order to fully understand the experiment, just elementary maths, physics and electronic knowledge is required.

The fun, on the other hand, was building up the thingie; if you really (do you?) wish to build up a similar system by yourself, then you have to make your hands a little dirty: cutting wires, soldering and the like.

The Idea

The idea behind this experiment is using the Arduino Nano analog and digital features to both monitor and change (increase) the temperature in a suitable environment.

Functional description of the system

Picture 2 - Simple functional description of the system

To detail, our Nano is in charge of the functional blocks shown in the above picture:

  • Temperature sensors, used for monitoring both the closed system and the external environment temperature.
  • A heater. It could be switched ON in order to produce, well, some heat.
  • A fan, used to spread the produced heat and thus speeding up the thermalisation process.

How It Works (or Doesn't)

The 'Suitable Environment'

The suitable environment

Picture 3 - The experiment 'suitable environment' (i.e. the carton box enclosure of the canakit, gently provided by CodeProject :-) )

A right environment is the fundamental prerequisite for temperature control: we have to inject heat (i.e., energy) in the system in order to increase its temperature.

Large systems need great amounts of energy. Arbitrary large systems need arbitrary amounts of energy. Simply put, I just can afford heating the cartoon box shown in Picture 2. The box, as a bonus, provides some thermal insulation.

Temperature Monitoring

Monitoring is achieved using four glorious (that is cheap) temperature analog sensors, namely Microchip MCP9700A sensors.

The analog tempearture sensor MCP9700A

Picture 4 - The analog temperature sensor MCP9700A, VOUT(T) is shown.

While the complete sensor datasheet is available here, is it enough to say the MCP9700 outputs a voltage proportional to the measured temperature, following the formula:

C++
vout(t) = (0.5 + 0.010 t/°C) V

For instance, at 30 °C (86 °F), it outputs 0.8 V.

The sensors are placed strategically and named accordingly:

Name Position
NEAR on the internal box side, near the heater, lateral to the air
FAR on the box internal side, far from the heater, facing the air flow
HEATER on the (internal, again) box floor, close to the heater
EXTERNAL outside the box, for monitoring the environment temperature

A 0.33 µF ceramic capacitor connects VOUT and GND of every sensor.

Heating

The heat is produced, by the joule effect of quite a large current flowing in three 1 Ω cement power resistors (5 W).

The heater: three cemeent resistors

Picture 5 - First heater version, with 4 Cement resistors. Eventually one resistor was discarded in the definitive prototype (see Griff's remark at the bottom of the page).

Arduino can neither provide, nor handle such large currents, so both an external power supply and a relay board is necessary.

I have used my laboratory DC power supply, able to provide up to 3 A current and another 'glorious' piece of hardware, the cheap 8 relays board you had already admired in picture 1.

The two-stages heating is achieved using, with the same supply voltage, 5 V, alternatively with the series of the 3 resistors (stage 1), or the series of two resistors (stage 2).

Stage 1 provides a total power of...

P<sub>1 </sub>= V*V/R = 5*5/3 W ≅ 8.3 W

...while stage 2 provides:

P<sub>2</sub>= 5*5/2 = 12.5 W

It is worth nothing that, in stage 2 configuration, the power exceeds the nominal one of the resistors.

Spreading the Heat

A 5 V suction fan, borrowed from one of my Raspberry Pi's enclosures, is used to spread the heat, with the air flow directed as shown in the functional block (picture 2).

The suction fan

Picture 6 - The 5 V suction fan

Like the heater, the fan requires a fair amount of current (about 200 mA) and Arduino cannot directly provide it. Once again, the relay board comes to the rescue.

Putting All Together

The picture below shows the complete electric circuit.

The electric circuit schematic

Picture 7 - The electric circuit schematic

Note the two power supply sources:

  • The external, high current one is explicitly marked (see also the schematic fragments, pictures 8, 9), it provides current to the relay board, the resistors, the fan.
  • The low current one, coming from the Arduino USB port, powering the Nano and the analog circuit.

Fragment of the schematic showing analog connections

Picture 8 - Fragment of the schematic showing the analog connections

The picture above shows the connections of the analog sensors: VDD comes from Arduino + 5 V pin, VOUT goes to the A0, A1, A2, A3 analog pins of the Arduino board, GND is common with the high power digital part of the circuit,

On the other hand, the picture 9 below reveals how the two-stage heater works.

The relay 1 is the heater ON/OFF: while ON it provides 5 V to relay 2.

Relay 2, in turn, diverts the voltage either on the series {R1, R2, R3} (OFF position) or on the series {R2, R3} (ON position).

Fragment of the schematic showing the connections of the realys with the resistors

Picture 9 - Fragment of the schematic showing the connections of the relays with the resistors

The net effect of the relay 1, 2 states on the heater is summarized by the below table:

RELAY 1 RELAY 2 effect on heater
OFF OFF switched OFF
OFF ON switched OFF
ON OFF switched ON, normal power (8.3 W)
ON ON switched ON, high power (12.5 W)

By contrast, the fan acts independently, controlled by the relay 3.

The Code

Compared to the hardware assembling effort, the code is really simple stuff and the Arduino <ocde>IDE makes it even simpler.

In the Setup function, the serial port is initialized, the digital pin controlling the relays configured as OUTPUT and set to HIGH logical level in order to start with a clean 'do nothing' state (since the logic driving the relay is inverted: Arduino pin LOW drives the relay ON).

In the never-ending Loop function (welcome in the microcontroller world!), the available characters are read from the serial port, then, using a simple switch statement recognized elementary single-character commands executed:

  • '0' - toggles the relay 1 state
  • '1' - toggles the relay 2 state
  • '2' - toggles the relay 3 state
  • 'v' - toggles the verbose reporting mode

Then sensor values are read and memorized for reporting.

Reading analog values with Arduino is trivial, a simple call to analogRead, thanks to underlying libraries, does the job. Transforming ADC raw measures in temperature values is also pretty simple, the following code snippet computes the integer and fractional (tenths of degrees) part of the temperature without using unneeded floating point variables.

C
int millivolt = map(adc, 0, 1023, 0, 5000);
int degree = (millivolt - 500) / 10;
int fracdegree = (millivolt - 500) - (degree * 10);

Finally, the measures are reported, together with the current state of the relays. There are two report modes: default and verbose.

Both modes report the same independent information, however while the verbose mode is suitable for direct human interpretation, the default mode is raw CSV-like, aimed at automatic data acquisition.

The following text copied from serial terminal shows both modes: iteration 22 is reported verbose, while iterations 23..32 are reported in default mode.

...
ITERATION 22
HEATER is OFF
HEATMAX is OFF
FAN is OFF
NEAR sensor value is adc = 168, V = 821 mV, temp = 32.1 Celsius
FAR sensor value is adc = 170, V = 830 mV, temp = 33.0 Celsius
HEATHER sensor value is adc = 166, V = 811 mV, temp = 31.1 Celsius
EXTERNAL sensor value is adc = 168, V = 821 mV, temp = 32.1 Celsius
************************************************
23;0;0;0;167;169;167;168
24;0;0;0;167;171;168;168
25;0;0;0;166;169;167;168
26;0;0;0;167;169;167;167
27;0;0;0;168;168;167;168
28;0;0;0;167;168;167;170
29;0;0;0;167;169;168;170
30;0;0;0;167;169;166;169
31;0;0;0;169;169;169;169
32;0;0;0;167;169;167;169
...

First Test Run

This test was performed on Aug 6th, in the late evening.

Test schedule was:

Step Minutes Heater state Fan state
1 10 OFF OFF
2 10 ON STANDARD OFF
3 10 ON HIGH POWER OFF
4 30 ON STANDARD ON
5 30 OFF ON

That is: start sly, all OFF, then heat without fan action, then heat wildly keeping the fan OFF.

Eventually start the fan, first with standard heating and then without heater action.

The result of the test is depicted in the chart below:

First test run chart

Picture 10 - First test run chart

Apparently, the heater works (more than expected: it becomes very hot). The high-power heating is somewhat overestimated in the chart, possibly because the heater sensor is close to one of the 'overdriven' resistor. The fan action is rather impressive. Sensors NEAR and FAR fairly agree on the value of the temperature inside the box, that, not surprising, is well above the external environment one.

Points of Interest

  • Soldering, cutting wires, assembling is hard work for the software people. On the other hand, a working piece of do-it-yourself hardware gives some satisfaction and fun.
  • Building a prototype with Arduino is extremely fast and pleasant. Nevertheless, a quick prototype is possibly not the state of the art. In my opinion, temperature monitoring accuracy can (and should) be improved.
  • Just a test run is actually a poor means of validation. But, as Lou Reed once used to sing: "There is no time", really.
  • More fun is waiting: now we have the data, now we could implement automatic temperature control with PID or fuzzy logic.

History

  • 8th August, 2018 - 02:05: 50 CET: First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Biotecnica Instruments S.p.A.
Italy Italy




Debugging? Klingons do not debug. Our software does not coddle the weak. Bugs are good for building character in the user.
-- The Klingon programmer



Beelzebub for his friends [^].





Comments and Discussions

 
PraisePID Pin
SteveHolle8-Aug-18 6:20
SteveHolle8-Aug-18 6:20 
GeneralRe: PID Pin
CPallini26-Aug-18 8:49
mveCPallini26-Aug-18 8:49 
GeneralRe: PID Pin
SteveHolle7-Sep-18 12:31
SteveHolle7-Sep-18 12:31 
GeneralRe: PID Pin
CPallini9-Sep-18 4:45
mveCPallini9-Sep-18 4:45 
QuestionMinor counting problem Pin
OriginalGriff7-Aug-18 19:31
mveOriginalGriff7-Aug-18 19:31 
AnswerRe: Minor counting problem Pin
CPallini7-Aug-18 21:07
mveCPallini7-Aug-18 21:07 
GeneralRe: Minor counting problem Pin
OriginalGriff7-Aug-18 21:40
mveOriginalGriff7-Aug-18 21:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.