Computers and modern gadgets

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

We have already mentioned (cf. chapter 18) that AVR controllers include a 10-bit multi-channel ADC. On Arduino boards, its pins are specifically marked as analog inputs (letter A with numbers from zero to five). Note that they can also be used as ordinary digital ones with numbers from 14 to 18, and we will still use them as such. 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 need:

□ Arduino Uno board (any other is fine);

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

□ "Amperke" B57164-K 103-J with a nominal resistance of 10 kOhm at 25 ° C - it is its characteristics that are given in chapter 13 as an illustration of the properties of thermistors;

□ Variable resistor 10 kOhm, fixed resistor 620 Ohm;

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

On sale there are modules based on 5-volt electromagnetic relays, specially adapted for control from the Arduino outputs. Electromagnetic relays themselves require a rather large control current (and the more powerful the relay, the more powerful it is - only the most low-power reed relays can work directly from the logic), therefore, all such relay modules must have a transistor amplifying switch. For example, Amperka sells such a module based on the HLS8L‑DC5V‑S‑C relay. If you are not satisfied with the electromagnetic relay, and you are striving for the utmost simplicity of the circuit, then you can look for solid-state relays - suitable, for example, CX240D5R from Crydom or similar ones with a response voltage of 3-15 V. They have a control current of about 15 mA at 5 volts per input, which is acceptable for AVR, because their control input can be connected to the Arduino digital pin directly. True, at a voltage of 220 volts, the CX240D5R cannot switch a load with a power of more than a kilowatt, but we don’t need more in this task.

The thermostat circuit on the Arduino Uno is shown in fig. 21.2.

Rice. 21.2. Thermostat circuit on Arduino Uno

In the diagram, the relay winding K1 (with normally open contacts) is conditionally connected directly to the digital output of the Arduino - it is understood that it is either the previously mentioned solid state relay with the desired characteristics, or simply the control input of the finished relay module board. To control 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 matched to the specified B57164-K thermistor, rated at 10 kΩ at 25 °C (103-J). In accordance with the program, the relay will operate near the value at the ADC output, equal to 500. This is approximately the middle of the 10‑bit range (the entire scale is 1024 gradations), i.e., this value will be set 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).

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

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

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

Automatic fan Arduino, which turns on itself when the temperature in the room reaches a certain value.

In this tutorial, you will learn about Arduino temperature controlled fans using the DHT22 sensor and relay. We will use the DHT22 sensor to get the temperature value and display this temperature value on the LCD. Then we will check if the temperature value is greater than 35 or not, if the temperature is greater than 35, then the relay will be activated and the fan will start to rotate.

Accessories

We will need the following details for our project:

Schematic diagram of the Arduino fan

The circuit diagram of our fan looks like this:

Let's deal with the connection of all the details. First of all, connect the LCD to the Arduino as follows:

  • Connect the VSS pin on the LCD to Arduino ground.
  • Connect the VDD pin to the Arduino's 5V.
  • Connect the V0 pin to the center pin of the 10K potentiometer. Connect the other two pins of the potentiometer to 5V and to ground.
  • Connect the RS pin to Arduino pin 2.
  • Connect the R/W pin to Arduino ground. This will put the LCD in read mode.
  • Connect pin E (Enable) to pin 3 of the Arduino.
  • Connect pins D4-D7 to pin 4, 5, 6, 7 of Arduino.
  • Connect pin 15, which is the positive output of the LED backlight, to the 5 pin pin through a 220 ohm resistor.
  • Connect pin 16, which is the negative backlight of the LED, to Arduino ground.

Then connect the relay module to the Arduino. On the input side of the relay module, make the connections as follows:

  • Connect the VCC pin of the relay module to the Arduino's 5V pin.
  • Connect the IN pin of the relay module to pin 9 of the Arduino.
  • Connect the GND pin of the relay module to the GND of the Arduino.

On the output side of the relay module, connect the minus 9V battery to the common (C) relay module and connect the NC of the relay module to the fan minus. Then connect the plus of the batteries to the plus of the fan.

Finally, make connections for the temperature and humidity sensor DHT22.

  • Connect pin 1 of DHT22, which is the VCC pin, to Arduino's 5V.
  • Connect pin 2 of the DHT22, which is the data pin, to pin 8 of the Arduino.
  • Connect pin 4 from the DHT22, which is the ground pin, to Arduino ground.

Sketch for Arduino

Below you can copy and upload the code to your Arduino Uno.

#include "DHT.h" #include "LiquidCrystal.h" LiquidCrystal lcd(7, 8, 9, 10, 11 ,12); #define DHTPIN 6 #define DHTTYPE DHT22 DHT sensor(DHTPIN, DHTTYPE); int relay_pin = 9; void setup() ( lcd.begin(16,2); sensor.begin(); pinMode(relay_pin, OUTPUT); digitalWrite(relay_pin, HIGH); ) void loop() ( lcd.clear(); float t = sensor .readTemperature(); //Read the temperature from the sensor // Check if the sensor is sending values ​​or not if (isnan(t)) ( lcd.print("Failed"); delay(1000); return; ) lcd.setCursor( 0,0); lcd.print("Temp: "); lcd.print(t); lcd.print(" C"); if (t > 35)( digitalWrite(relay_pin, LOW); lcd.setCursor(0 ,1); lcd.print("Fan is ON "); delay(10); ) else( digitalWrite(relay_pin, HIGH); lcd.setCursor(0,1); lcd.print("Fan is OFF "); ) delay(2000); )

Code Explanation

First of all, we have included the libraries for the DHT22 sensor and for the LCD. Libraries help make code simpler.

You can download all the necessary libraries for your projects on our website in the - section.

#include "DHT.h" #include "LiquidCrystal.h"

Then we initialized the pins to which we connected the LCD and the DHT22 sensor. After that, we determined the type of DHT sensor that is being used. There are many other types of DHT sensors, such as the DHT11, so it's important to identify the type here.

LiquidCrystal lcd(2, 3, 4, 5, 6, 7); #define DHTPIN 8 #define DHTTYPE DHT22 DHT sensor(DHTPIN, DHTTYPE);

In the setup function, we commanded the DHT22 and the LCD to start communicating with the Arduino. We then declared the relay pin as an output pin because we will supply voltage from the Arduino to the relay to activate the relay. The relay works in reverse (High means Low for a relay).

Lcd.begin(16,2); sensor.begin(); pinMode(relay_pin, OUTPUT); digitalWrite(relay_pin, HIGH);

In the loop function, we clear the LCD screen and then read the temperature value from the sensor.

lcd.clear(); float t = sensor.readTemperature(); if (isnan(t)) ( lcd.print("Failed"); delay(1000); return; )

Then we print the temperature value on the LCD and if the temperature value is greater than 35 then the relay will be activated and the fan will start to rotate.

lcd.setCursor(0,0); lcd.print("Temp: "); lcd print(t); lcd.print("C"); if (t > 35)( digitalWrite(relay_pin, LOW); lcd.setCursor(0,1); lcd.print("Fan is ON "); delay(10); )

That's all. Good projects to you!

He will share with you the experience of creating a smart fan rotation controller, with the participation of a temperature sensor, an LCD display and, of course, an 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 the board attracted me, first of all, by its relative ease of development. Having messed around with LEDs and "Hello world"s, I wanted to do something practical, at the same time get to know the Arduino capabilities in more detail. Bearing in mind the abnormally hot summer of 2010, the idea arose to assemble a cooler speed controller depending on temperature with the display of all related characteristics 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 need:

  • The board itself Arduino or equivalent;
  • Bread board for assembling circuit components;
  • WH1601A-NGG-CT display with trimmer on 20 kOhm or similar;
  • Resistors - 220 ohm, 10 kOhm, 4.7 kOhm;
  • bipolar transistor SS8050D or similar to it;
  • Digital temperature sensor DS18B20 ;
  • Diode 1N4148 or equivalent;
  • Fan axial three-wire (for 12V), for example - computer;
  • socket 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, 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 the 6 Arduino digital outputs can work in PWM mode (they are marked on the board itself with white squares, or with the letters PWM), so we can regulate the signal from the board to the relay that will be responsible for changing voltage supplied to the fan.

We will receive information about the revolutions from the third wire from the tachometer, using a modified method based on the implementation interrupts, which on most Arduinos can be sent 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 we need to place digital temperature sensor, whose data we will use to regulate the voltage supplied to the PWM digital output, 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 to the arduino-0018/libraries/ directory.

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

//Include the library for the thermal sensor#include //Include the library for LCD#include #define Power Pin 9 // pin to control 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 the temperature typedef struct( // Introducing a new variable type 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 on every 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 apply anymore - we take a 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 ); // Set 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 temperature temp(); // Calculate the applied voltage to the PWM analogWrite(PowerPin, fadeValue); // Feed it NbTopsFan = 0; // Zero out the variable containing the revolutions delay(1000); //Wait 1 second Calc = ((NbTopsFan * 60)/fanspace.fandiv); //Calculate RPM per 60 seconds divided by 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 the next boiler, the next house, but this is only partly true - in the article I do not want to concentrate on the device itself - there are indeed plenty of them (articles). Undoubtedly, I will describe the thermostat, but I would like to talk more about how I connected the microcontroller itself to the boiler. So if anyone is 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 MK in general) was back in high school, when I wanted to know how this mysterious thing still works. I read several articles and since then I have only fragments in my memory that could be described with just two words - DDR and PORT - this is where my knowledge ended. Then there was the university, the 5th course - "Programming of microcontrollers" where we all got acquainted with the MSC51 in a virtual environment. There were already interrupts, and timers, and everything else. Well, with such a baggage of knowledge, I came to the problem. Let's end on this autobiographical note and move on to the more interesting part.

So, in fact, how did the creation of the thermostat begin - after installing autonomous heating with a gas boiler, I, like many, faced 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, 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 the door, and the door was propped up by a microwave oven, on which there was a pile of rubbish. Well, you understand - 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 temperature of the coolant 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 hope - the connection of an external temperature sensor is not provided for in this model. All? All. And now, probably, it could be finished, but in the summer in the boiler during a thunderstorm the control board burns out in a way that is still incomprehensible to me, and 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 were connecting using external thermostats. It stuck in my memory, but I didn’t really concentrate on it until the onset of cold weather, and then the same problem.

Leafing through the same service manual, but in order to see how the thermostat is connected, I noticed that the “OpenTherm regulator” is connected to the same terminals. Then I realized - here it is! A Google search for "OpenTherm Arduino" upset me again - nothing particularly sensible. There was a message monitor, but that’s not it - I don’t even have to listen, there’s nothing to do - I need a thermostat.

If you notice an error, select a piece of text and press Ctrl + Enter
SHARE:
Computers and modern gadgets