Multichannel thermostat on arduino uno. Fan using Arduino, which depends on temperature. Components of a PID controller

The schematic diagram of a homemade four-channel thermostat with temperature display, built on the basis of Arduino UNO, LM325 and with a 1602A display, allows you to control four separate loads.

Here we describe an upgraded version of the device, which, in addition to passively measuring and indicating temperature, can also control four heaters in order to maintain a set temperature in four different places, where in the first version only temperature measurement was possible.

The operation of a four-channel thermometer and its program is described in great detail in the previous article (L.1), so here we will only talk about changes to implement the operation of a four-channel thermostat.

Schematic diagram

The schematic diagram is shown in Fig. 1.

Rice. 1. Schematic diagram of a thermostat on Arduino UNO, LM325 with 1602A display.

Unlike the first circuit (L.1), here there are four transistor switches loaded on the relay windings K1-K4, which control four different heating devices (H1-H4). Control commands for these keys come from four digital ports D9-D12 of the ARDUINO UNO board.

Program

The program is shown in Table 1.

Table 1.

The first difference is that ports are provided to control the heaters. These are ports D9-D12, they are specified here:

pinMode(12, OUTPUT);

pinMode(11, OUTPUT);

pinMode(10, OUTPUT);

pinMode(9, OUTPUT);

You can select other free digital ports; after connecting the indicator, there are still D8 and D13 left. But the author chose these: D9, D10, D11, D12. The second difference is that the if comparator function is used to control the heaters. In lines:

if(temp< -15)digitalWrite(12, HIGH);

if(temp > -15)digitalWrite(12, LOW);

if(tempi< 1)digitalWrite(11, HIGH);

if(tempi > ​​1)digitalWrite(11, LOW);

if(temp2< 20)digitalWrite(10, HIGH);

if(temp2 > 20)digitalWrite(10, LOW);

if(temp3< 10)digitalWrite(9, HIGH);

if(temp3 > 10)digitalWrite(9, LOW);

These lines indicate at what temperature, what logical level should be on the corresponding port. For example, if the temperature of the first sensor (T1) is below -15°C, there will be a logical one at port D12. When the temperature of the second sensor (T2) is below 1°C, there will be a logical one at port D11.

When the temperature of the third sensor (TZ) is below 20°C, there will be a logical one at port D10. When the temperature of the fourth sensor (T4) is below 10°C, there will be a logical one at port D9. Of course, you can set completely different temperatures - any that are needed for the specific application of this device.

Moreover, already in the finished device, they can be easily changed if necessary. To do this, you need to connect a personal computer to the USB port of the ARDUINO UNO board and load a program with other data on temperature thresholds. In principle, for this you can provide a USB connector on the body of the finished device.

Usually, in a “typical” thermostat there is a hysteresis loop, that is, a circuit that creates a difference between the temperature at which the heater turns on and the temperature at which it turns off. This is necessary so that the heater does not turn on/off very often. This is especially important if the heater is controlled by an electromagnetic relay.

Because the relay contacts are not designed for this mode of operation, and can quickly fail from burning due to sparking. But hysteresis introduces an error into the operation of the thermostat. Here it was decided not to create hysteresis, but to ensure that the relay contacts do not switch too often, simply slow down the operation of the device. To do this in the line:

The display time has been increased to three seconds. As a result, the measurements are repeated with a period of three seconds, and in any case, the relay cannot switch more than once every three seconds.

Details

Any electromagnetic relays K1-K4 can be used with 12V windings and contacts powerful enough to control specific heaters.

Output stages can be made using other circuits, for example, using opto-mistors. In this case, the LEDs of optosimitors or so-called “solid-state relays” are connected to the corresponding ports of the ARDUINO UNO board through current-limiting resistors.

Karavkin V. RK-08-17.

Literature: 1. Karavkin V. - Four-channel thermometer on ARDUINO UNO, RK-06-17.

The main task of the refrigerator controller is to maintain the set temperature in the chamber. The temperature controller will do this by changing the electrical power on the Peltier module.

In the previous lesson we developed a power regulator. The connection between power and temperature regulators looks like this.

  • The temperature controller receives the measured temperature, compares it with the set temperature and calculates the set power value for the power controller.
  • The power regulator generates PWM corresponding to the specified power.

We built the power regulator according to the integral regulation law. To stabilize the temperature, we will use a more complex control algorithm - a proportional-integral-derivative (PID) controller.

PID controller.

In the previous lesson I talked in detail about . He emphasized its advantages and disadvantages.

A regulator operating on this principle has high accuracy. The remaining criteria for the quality of regulation - speed and stability - are not up to par.

In order to achieve high performance for all criteria, it is necessary to use a regulator that combines different regulatory laws.

The proportional-integral-derivative (PID) controller is just such a device. It generates an output signal that is the sum of three components with different transfer characteristics. Thanks to this, the PID controller provides high quality regulation and allows you to optimize management according to individual criteria.

The following are involved in generating the output signal of the PID controller:

  • Proportional component– the value is proportional to the mismatch error (the difference between the specified and real values ​​of the controlled parameter).
  • Integrating component– mismatch error integral.
  • Differentiating component– derivative of the mismatch error.

The mathematical form of writing the PID controller law is:

o(t) = P + I + D = K p e(t) + K i ∫e(t)dt + K d de(t)/dt

  • o(t) – output signal;
  • P – proportional component;
  • I – integrating component;
  • D – differentiating component;
  • Kp, Ki, Kd – coefficients of proportional, integrating, differentiating links;
  • e(t) – mismatch error.

In schematic form, the PID controller can be represented as follows.

The block diagram of the PID voltage regulator U looks like this.

  • The measured voltage Ureal(t) is subtracted from the given Uset.
  • The resulting mismatch error e(t) is fed to the proportional, integrating and differentiating links.
  • As a result of the sum of the components, a control action o(t) is obtained, which is applied to the control element.

When implementing a PID controller in software, calculations of the output signal occur at regular intervals. Those. The controller is discrete in time. Therefore, further I will use expressions: previous signal state, previous value, etc. We are talking about the state of the system at the previous time sampling point.

Components of a PID controller.

Again. The output signal of the PID controller is the sum of three components:

  • proportional;
  • integrating;
  • differentiating.

Proportional component.

P(t) = K p * e(t)

Has no memory, i.e. the value of the output signal does not depend on the previous state of the system. Simply the following error, multiplied by a factor, is transmitted to the output. The output signal compensates for the deviation of the controlled parameter. The larger the mismatch error, the larger the signal. If the error is 0, the output signal is also 0.

The proportional component is not able to compensate for the error completely. This can be seen from the formula. The output signal is Kp times the error. If the mismatch error is 0, then the output signal of the controller is 0. And then there is nothing to compensate with.

Therefore, in proportional controllers there is always a so-called static error. It can be reduced by increasing the Kp coefficient, but this can lead to a decrease in the stability of the system and even to self-oscillations.

The disadvantages of proportional controllers include:

  • presence of static regulation error;
  • low stability with increasing coefficient.

There is a significant advantage:

  • High speed regulation. The response of a proportional controller to a following error is limited only by the sampling time of the system.

Regulators operating only according to the proportional law are rarely used.

The main task of the proportional component in the PID controller is to increase performance.

Integrating component.

I(t) = K i ∫e(t)dt

Proportional to the integral of the mismatch error. Taking into account the time discreteness of the controller, we can write this:

I(t) = I(t -1) + K i * e(t)

  • I(t-1) – value of I at the previous time sampling point.

The mismatch error is multiplied by a coefficient and added to the previous value of the integrating link. Those. the output signal accumulates all the time and increases its impact on the object over time. Thus, the mismatch error is fully compensated even for small values ​​of the error and coefficient Ki. In a steady state, the output signal of the controller is completely provided by the integrating component.

The disadvantages of the integral regulator include:

  • low performance;
  • mediocre stability.

Dignity:

  • Ability to fully compensate for mismatch error at any gain.

In practice, integrating controllers (only integrating component) and proportional-integrating controllers (integrating and proportional components) are often used.

The main task of the integrating link in the PID controller is to compensate for the static error and ensure high control accuracy.

Differentiating component.

D(t) = K d de(t)/dt

Proportional to the rate of change of the following error. A kind of indicator of acceleration of mismatch error. The differentiating component predicts deviations of the controlled parameter in the future and counteracts this deviation. As a rule, it compensates for delays in the influence of the regulator on the object and increases the stability of the system.

Taking into account the time discreteness of the controller, the differentiating component can be calculated as follows:

D(t) = K d * (e(t) - e(t -1))

It shows how much the mismatch error value has changed over one time unit of the controller discreteness.

There are no regulators consisting of a single differentiating link.

The main task of the differentiating link in the PID controller is to increase stability.

Setting up the PID controller.

The quality of control of PID controllers largely depends on how optimally the coefficients are selected. The coefficients of the PID controller are determined in practice in a system with a real object by selection. There are different setup methods. I will only talk about general principles.

The quality of regulation is judged by the transient response of the regulator. Those. according to the graph of changes in the controlled parameter over time.

To the traditional points of the PID controller tuning sequence, I would add that, first of all, it is necessary to decide which control quality criteria are preferable.

In the previous lesson, when designing a power regulator, we were primarily interested in accuracy and stability. And we even artificially reduced the performance. Some regulators operate under conditions of significant noise and stability is more important to them, while others require high performance even at the expense of accuracy. Optimization criteria may vary. In general, PID controllers are configured to ensure all control quality criteria are at a high level.

The components of the PID controller are configured separately.

  • The integrating and differentiating links are turned off and the coefficient of the proportional link is selected. If the controller is proportional-integrating (there is no differentiating link), then a complete absence of oscillations in the transient response is achieved. When setting the controller to high speed, oscillations may remain. The differentiating link will try to compensate for them.
  • The differentiating link is connected. Its coefficient aims to eliminate fluctuations in the control parameter. If this fails, then reduce the proportional coefficient.
  • Due to the integrating link, the residual mismatch error is removed.

Tuning the PID controller is iterative in nature. Those. points for selecting coefficients can be repeated many times until an acceptable result is achieved.

Due to their high performance and versatility, PID controllers are widely used in industrial automation systems.

In the next lesson we will develop a PID temperature controller.

He will share with you his experience of creating a smart fan rotation controller, using a thermal sensor, an LCD display and, of course, Arduino.

A few months ago I read a number of articles about Arduino and became very interested in this device, and soon decided to purchase it. It should be noted that I am far from microelectronics, so I liked the board primarily because of its relative ease of use. Having dabbled with LEDs and “Hello world” systems, I wanted to do something practical, and at the same time become more familiar with the capabilities of Arduino. Keeping in mind the abnormally hot summer of 2010, the idea arose to assemble a cooler speed controller depending on the temperature with all related characteristics displayed on the LCD. I hope that this scheme or its variations will be useful to someone, so I decided to post my sketches.

For this scheme we will need:

  • Actually the board itself Arduino or similar;
  • Bread board for assembling circuit components;
  • Display WH1601A-NGG-CT with trim resistor on 20 kOhm or similar;
  • Resistors – 220 Ohm, 10 kOhm, 4.7 kOhm;
  • Bipolar transistor SS8050D or similar;
  • Digital temperature sensor DS18B20;
  • Diode 1N4148 or equivalent;
  • Fan axial three-wire (12V), for example - computer;
  • Jack connector nutrition 2.1/5.5 mm.

The computer cooler has three wires, two of which - red (+12V) and black (GND) are used for power supply, and the third (yellow) is connected to a tachometer built on a Hall element. Unfortunately, 5V from the board is clearly not enough for us, but 6 Arduino digital outputs can operate in PWM mode (they are marked on the board itself with white squares or the letters PWM), so we can regulate the signal supply from the board to the relay, which will be responsible for the change voltage supplied to the fan.

We will receive information about revolutions from the third wire from the tachometer, using a modified method based on the implementation interrupts, which for most Arduinos can come to digital pins 2 (interrupt 0) and 3 (interrupt 1). By the way, the Arduino Mega has 4 additional pins with the ability to receive interrupts.

Now you need to position digital temperature sensor, the data of which we will use to regulate the voltage supplied to the digital output with PWM, and therefore to “open” the fan voltage channel. Dallas sensors have their own Arduino library - DallasTemperature, which we will later connect in the sketch. The library must be unpacked into the arduino-0018/libraries/ directory.

The last thing left is connect LCD, where we will display all the current information about the temperature and fan speed. Since I used the WH1601A screen for the build, there may be known issues with displaying lines. To eliminate them, we will use the LiquidCrystalRus library, which must also be unpacked into the arduino-0018/libraries/ directory.

//Connect the library for the temperature sensor#include //Connect the library for LCD#include #define PowerPin 9 // pin for controlling fan power#define HallSensor 2 // pin for fan speed sensor (interrupt)#define TempPin 7 // pin for temperature sensor LiquidCrystalRus lcd(12, 11, 10, 6, 5, 4, 3); //Connect LCD DallasTemperature tempSensor; int NbTopsFan, Calc, fadeValue; //integer variables for calculations float temper; //real variable to store temperature typedef struct( // Introduce a new type of variables for fans char fantype; unsigned int fandiv; )fanspec; //Array of new type variables fanspec fanspace=((0,1),(1,2),(2,8)); //Variable responsible for selecting the type of fan sensor (1 – unipolar Hall sensor, 2 – bipolar Hall sensor) char fan = 2; //This function will be called every time we interrupt void rpm() (NbTopsFan++;) // Function for calculating the applied voltage to a digital pin with PWM void temp() ( fadeValue = min(int(temper*7),255); // Multiply the temperature by the coefficient, // take an integer from the product } // Because the maximum PWM value is 255, then it makes no sense to supply more - take the minimum of two void setup() (tempSensor.begin(TempPin); //Start the temperature sensor lcd.begin(16, 2); //Set LCD characteristics lcd.setDRAMModel(LCD_DRAM_WH1601); //And display type pinMode (HallSensor, INPUT ); // Configure pin to receive interrupts attachInterrupt(0, rpm, RISING); //We bind interrupt number 0 to our function, and it will be calculated every time the signal changes) void loop() ( temper = tempSensor.getTemperature(); // Get the temperature temp(); // Calculate the supplied voltage to the PWM analogWrite(PowerPin, fadeValue); // Feed it NbTopsFan = 0; // Reset the variable containing the revolutions to zero delay(1000); //Wait 1 second Calc = ((NbTopsFan * 60)/fanspace.fandiv); //Calculate the speed in 60 seconds divided by the fan multiplier lcd.print(Calc, DEC); //Output the calculated value in decimal form lcd.print(" rpm - " ); lcd.print(temper); //Output temperature lcd.home(); )

Reading the first part of the title, many of you probably thought - another thermostat on the long-suffering Arduino. And... It’s true - yes, this is another thermostat for another boiler, another house, but this is only partly true - in the article I don’t want to concentrate on the device itself - there really are plenty of them (articles). Of course, I will describe the thermostat, but I would like to talk more about how I connected the microcontroller itself to the boiler. So, for those who are interested, please...

How it all began

First of all, I want to say that I am not a programmer at all and have never dealt with a real microcontroller before. My first acquaintance with the AVR MK (and with the MK in general) was back in high school, when I wanted to know how this mysterious thing actually works. I read several articles and since then I have only fragments in my memory that could be described in just two words - DDR and PORT - and that’s where my knowledge ended. Then there was university, 5th year - “Programming of microcontrollers” where we all got acquainted with MSC51 in a virtual environment. There were already interruptions, timers, and everything else. Well, with this amount of knowledge I came to the problem. Let's end on this autobiographical note and move on to the more interesting part.

So, actually, where did the creation of the thermostat begin? After installing an autonomous heating system with a gas boiler, I, like many, encountered the usual problems - the temperature in the house was very dependent on the weather outside - frost - it’s cold in the apartment, you need to increase the temperature of the coolant in batteries, it got warmer - on the contrary. Such dances with a tambourine did not suit me much, because... adjusting the boiler was complicated by the fact that it was installed behind a door, and the door was propped up by a microwave oven, on which lay a bunch of rubbish. Well, you get the idea - a needle in an egg, an egg in a duck, etc.

This problem was solved very simply - with an OTC (Outside Temperature Compensation) sensor, which is connected to the boiler and allows it to automatically adjust the coolant temperature depending on the outside temperature. The problem seemed to be solved, but reading the service manual for the boiler (Ferolli Domiproject C24D) quickly trampled my hopes - connecting an external temperature sensor is not provided for in this model. All? All. And now, probably, we could have finished it, but in the summer, during a thunderstorm, the control board still burns out in the boiler in a way that is still unclear to me, and while talking with the service man (the board was later repaired), I asked if it was possible to connect OTC to my boiler? He replied that they connect using external thermostats. This stuck in my memory, but I didn’t really concentrate on it until the cold weather set in, and then it was still the same problem.

Leafing through the same service instructions, but with the goal of seeing how the thermostat is connected, I noticed that the “OpenTherm regulator” is connected to the same terminals. That’s when I realized – this is IT! A Google search for “OpenTherm Arduino” again disappointed me - nothing particularly sensible. There was a message monitor, but that’s not it – I don’t have anything to listen to – I just need a thermostat.

Let's build something simple on Arduino first. IN chapter 12 we have already invented thermostats using purely analogue components. Now let's see how we can involve digital technology in this useful business.

We have already mentioned (see chapter 18), that AVR controllers include a 10-bit multi-channel ADC. On Arduino boards, its pins are specially marked as analog inputs (with the letter A with numbers from zero to five). Please note that they can also be used as regular digital ones with numbers from 14 to 18, and we will use them in this capacity. We will use one of these inputs to measure temperature, and we will control the load connection from one of the digital outputs.

In total we will need:

□ Arduino Uno board (any other one will do);

I have a thermistor as a temperature sensor. Suitable, for example, existing

□ “Amperke” В57164‑К 103‑J with a nominal resistance of 10 kOhm at 25 °C - its characteristics are given in chapter 13 as an illustration of the properties of thermistors;

□ variable resistor 10 kOhm, constant resistor 620 Ohm;

□ executive relay – electromagnetic (necessarily with an amplifying transistor switch, see below) or solid-state.

Modules based on 5-volt electromagnetic relays, specially tailored for control from Arduino outputs, are available for sale. Electromagnetic relays themselves require a fairly large control current (and the more powerful the relay, the more powerful it is; only the lowest-power reed relays can operate directly from logic), therefore all such relay modules must have a transistor amplifier switch. For example, Amperka sells such a module based on the HLS8L‑DC5V‑S‑C relay. If you are not satisfied with an electromagnetic relay, and you strive for extreme simplicity of the circuit, then you can look for solid-state relays - for example, CX240D5R from Crydom or similar ones with an operating voltage of 3-15 V are suitable. Their control current is about 15 mA at 5 volts at input, which is acceptable for AVRs, because their control input can be connected to the Arduino digital output directly. True, at a voltage of 220 volts, the CX240D5R cannot switch a load with a power of more than a kilowatt, but for this task we don’t need more.

The thermostat circuit on Arduino Uno is shown in Fig. 21.2.

Rice. 21.2. Thermostat diagram on Arduino Uno

In the diagram, relay winding K1 (with normally open contacts) is conventionally connected directly to the digital output of the Arduino - it is assumed that this is either the previously mentioned solid-state relay with the required characteristics, or simply the control input of a finished relay module board. To monitor the state of the circuit, an LED is activated simultaneously with the heater. The thermostat program in accordance with this scheme is extremely simple:

The resistor values ​​are adjusted to the specified thermistor B57164‑K with a nominal resistance of 10 kOhm at 25 °C (103‑J). In accordance with the program, the relay will operate near the ADC output value of 500. This is approximately the middle of the 10-bit range (the entire scale is 1024 gradations), i.e., this value will be established when the upper and lower resistances are approximately equal relative to the AO input (the voltage at this input will then be approximately 2.5 volts).

Please note that both functions if don't end with the usual else. To prevent chatter, hysteresis has been introduced into the program: the relay turns on when the code value exceeds 510, and turns off when it drops to 490. In the meantime, it will maintain the previous state. Twenty units of code (what is in chapter 12 we called dead zone) correspond to approximately 10 millivolts, i.e. hysteresis at a temperature in the range of 30–40 degrees will be slightly less than one tenth of a degree (check it yourself using Table 13.1 from chapter 13).

Setting the response temperature using resistor R2 with these parameters is possible in the range from approximately 22 to 96 °C. Of course, in practice such a wide adjustment range is not required, so it is advisable to reduce the R2 value. The value of R1 is selected so that R1 and the nominal value of R2 add up to the thermistor resistance at the lower value of the desired temperature range (in accordance with Table 13.1). For a more accurate fit, you can calibrate and change the threshold values ​​in the program by measuring the established temperature with a regular thermometer.

If you use other sensors in this circuit, do not forget about the sign of the temperature coefficient. An ordinary diode or transistor in diode connection (as in circuits from chapter 13) also have a negative slope of the characteristic, therefore for them in the program you will only have to change the numerical values ​​of the response threshold. But semiconductor sensors like TMP35 (see. chapter 13) or simply metal resistance thermometers (as in the design made of chapter 17) have a positive temperature coefficient, so the operating conditions will have to be reversed. And not just change “more” to “less” and vice versa, but also change the ratio of the thresholds for hysteresis - in the new situation, the heater will have to turn on if the value is less than the smaller threshold, and turn off if it is more than the larger one.


Top