Thermometer for measuring high temperatures on a microcontroller. Two-channel thermometer based on ATmega8 microcontroller and DS18B20 sensors

I would like to immediately note that the printed circuit board and design were designed with the expectation of making a compact device that can be mounted on a wall.

The device is controlled using one button. The program for the microcontroller is written in C, provided with comments, and users can modify it to suit their specific tasks, or expand the functionality. To control the LCD indicator, a ready-made Peter Fleury library is used (the downloadable archive is available in the downloads section). Additionally, data can be displayed in Celsius or Fahrenheit. There are several modes for controlling the indicator backlight.

It is also worth noting another important point: the device can carry out wireless data transmission via the Bluetooth protocol using a special module (optional).

Schematic diagram

From a circuit design point of view, the device is simple, and we will consider the component elements separately.

The power supply of the thermometer is made on the basis of an integrated voltage regulator in standard connection (with appropriate filter capacitors). The 3.3 V AMS1117 voltage regulator is included in the circuit, but can be used if a Bluetooth module is used, because Often the power supply for such modules is 3.3 V.

The indicator used in the device is a standard two-line indicator on the HD44780 controller. The transistor is designed to control the indicator backlight with logical signals from the microcontroller or a PWM signal from the microcontroller. Resistor R3 limits the current through the base of the transistor, resistor R1 pulls the base to zero potential.

The basis of the thermometer is a microcontroller operating at a frequency of 8 MHz and controlling all surrounding peripherals.

The DHT-11 sensor is a low-cost temperature and relative humidity sensor used in the project as an outdoor sensor. It is not characterized by high speed and accuracy, but is used in amateur radio projects due to its low cost. DHT-11 consists of a capacitive humidity sensor and a thermistor. Also, the sensor contains a simple ADC for converting analog values ​​of humidity and temperature.

Main characteristics:

  • low cost;
  • supply voltage 3 V - 5 V;
  • data transmission via 1-Wire bus over distances of up to 20 m;
  • determination of humidity 20-80% with 5% accuracy;
  • maximum current consumption 2.5 mA;
  • temperature determination 0...50° with an accuracy of 2%;
  • polling frequency no more than 1 Hz (no more than once every 1 s);
  • dimensions 15.5 × 12 × 5.5 mm;

It should be noted that you can find a DHT-22 sensor on sale, which has the same interface, but better characteristics.

The sensor is connected to the microcontroller via a 1-Wire bus (connector JP3 in the diagram) using a pull-up resistor on the data line and a blocking capacitor on the power supply.

The internal sensor is the widely used analog temperature sensor LM35 IC5, which is connected to channel 1 of the microcontroller ADC.

Connector J1 of the microcontroller in-circuit programming interface allows you to quickly change the program code or update the software. To connect the thermometer via the UART interface, connector JP1 is used. The SW1 control button is connected to the external interrupt input of the microcontroller; this input is connected to the power supply by the internal resistor of the port.

A Bluetooth module for wireless data transfer, indicated in the diagram as IC3, GP-GC021 also connects to the UART interface of the microcontroller and allows you to transfer data to a PC, mobile phone or web server. The printed circuit board provides space for installing the module. The download section contains a description of the module, interaction process and commands.

The LCD indicator is installed on the front part of the printed circuit board in the connector, thus hiding the components installed on the main board, and we get a compact device. The place for installing the Bluetooth module is on the back side of the printed circuit board (see photo of the board).

Appearance of the finished printed circuit board for a thermometer


PCB drawing in Eagle CAD

Board with installed Bluetooth module

Downloads

Circuit diagram and printed circuit board (Eagle), software (source code, firmware) -
Library for working with the LCD indicator on the HD44780 controller -
Technical description for Bluetooth module GP-GC021 -

Or its analogues. The devices have good accuracy, noise immunity, and, compared to analog solutions, significantly simplify the circuit. The limits of temperatures measured by such sensors are usually limited to the range from -55 to 125 ºС. What to do if you need to measure a temperature above 125 °C? Obviously, you need to use analog sensors, the temperature range of which can reach +300 °C. It should be noted that in this case the measurement accuracy will decrease. But often, when measuring high temperatures, it is not necessary to know the exact value, and an error of several degrees will be acceptable, and when displayed on an analog scale, for example, on a line of LEDs, it will be completely unnoticeable.

For normal operation of the device at a temperature of 0 ... 250 ° C, an analog sensor was selected, the operating range of which is -40 + 300 ° C. Its parameters are ideal for the selected temperature range. The microcontroller (MK) is responsible for data processing. Of course, any other one will do, but the author seems to think this MK is one of the most accessible and popular. Fuse bits are left factory. When solving the problem, the criteria for accurate measurement were put on the back burner. An error within a few degrees was quite satisfactory.

Digital display of measurement results

An LCD display is used for digital display of data. If desired, the device can be upgraded by modifying the program code. There are enough free I/O ports for this. The LCD display is connected via a 4-bit bus (Figure 1). The high-order digits of the indicator D4 - D7 are connected to the low-order digits D0 - D4 of the microcontroller. Since there are no precise timings in this device, there is no need for an external master quartz resonator. The display control pins are connected to ports PB6 and PB7. As you can see, all display control lines exit from one side of the MK case, which simplifies the tracing of the printed circuit board.

Calculation of temperature value

From Figure 1 it can be seen that the analog temperature sensor is connected directly to the ADC input of the microcontroller. If an operational amplifier was used, the measurement error would be smaller. The voltage is supplied to the ADC through a divider formed by a thermistor and a variable resistor. For better tuning accuracy, the variable resistor is selected to be multi-turn.

Table 1. Dependence of resistance on temperature.

Temperature ºС

Resistance Ω

By constructing a graph in Mathcad based on Table 1 (Figure 2), you can see the dependence of the resistance of the analog sensor on the applied temperature. The source data of the table is taken from the technical description of KTY84_130. The function is almost linear, with only a slight deviation at high temperatures.

At a measured temperature of 0 ºС, the resistance of the thermistor is 498 Ohms. The voltage at the divider output is

  • U D - voltage at the temperature sensor relative to ground,
  • U PIT - supply voltage,
  • R D - temperature sensor resistance,
  • R 1 - set resistance of the variable resistor.

At a temperature of 0 ºС, the voltage at the ADC input should be 0.6 V. To calculate the temperature value, the author used the following formula:


  • ADC - 10-bit digital ADC code taken from the sensor,
  • U OTC - cut-off value (60), equal to 0.6 V at 0 ºС.

The range of measured temperatures from 0 ºС to 250 ºС corresponds to the ADC input voltages coming from the divider from 0.6 to 1.8 V. The reference voltage of the ADC is 5 V, therefore, with the indicated values, the digital code will be in the range from 123 to 368. This number is placed in the register and converted to three digit ASCII code. Since the KTY84_130 sensor is designed for a maximum temperature of 300 ºС, it is better to leave a small margin and limit it to 250 ºС.

Figure 5 shows the device assembled on a breadboard. The program code is open, and anyone can easily modify it to suit their own needs.

MK software and virtual model Proteus for LCD 16×2 -

MK software and virtual model Proteus for LCD 8×2 -

Description of the thermometer operation

The purpose of this thermometer is simply to show the temperature. Small differences from other similar schemes are only in the format of temperature output on the LED indicator, which is a 4-digit super-bright CA04-41SRWA. DS18B20 is used as a temperature sensor in a normal connection with a separate power wire.

The circuit is designed to be powered by batteries, so when the power is turned on, the indicator does not show anything. The thermometer program undergoes initialization and immediately goes into sleep mode. Sleep mode of the microcontroller allows you to save energy from the power supply. When you press the button connected to PORTB0, the indication turns on.
The indicator displays a hint:



Then the temperature readings themselves are displayed on the indicator.



The type of reading output is as follows:






The output shape differs only for low positive temperatures. When indicating such a temperature, the sign “C” is added to the “degree” symbol. That is, degrees Celsius. The “degree” symbol is present on the indicator at any measured temperature.

The DS18B20 temperature sensor measures temperature with a resolution of 0.0625 degrees Celsius. The thermometer reads the readings from the sensor and rounds them to the nearest tenth of a degree. Tenths of a degree are displayed in all display modes, except for temperatures lower than -10 degrees Celsius. This is done so that readings of negative temperatures always have a minus sign.

The readings are present on the indicator for 30 seconds. Then the device goes into sleep mode again and the indicator turns off.


Modeling a thermometer in Proteus


The Proteus model made it possible to work out the software part of the thermometer without assembling the device itself in hardware. All modes have been tested. There are no simulation failures in the program.



The model itself can be downloaded from the link: termo_i_v2.DSN

Schematic diagram of a thermometer


The circuit is drawn based on the design of the printed circuit board. First, the wiring of the printed circuit board was done so that the length of the conductors and the location of the parts were optimal, and only after the PIC16F628A microcontroller ports on the printed circuit board corresponded to the pins of the CA04-41SRWA indicator, an exact circuit diagram was drawn up.


Thermometer circuit board


Good day, dear readers. As the title of the article suggests, we will talk about a thermometer assembled on a PIC. So. Why and how did it all start?!
I needed a diagram of a simple thermometer for the garage basement. I started looking for a suitable scheme on the Internet. An important criterion was the use of a minimum number of elements in the circuit. I’ll say right away that there are a ton of such thermometer circuits online. But! Most often they are made on AVRs with which, to my deepest regret, I am not friends. So I started looking for a PIC circuit. But even here I was disappointed. There are schematics for PIC thermometers. But they use either transistors for indicators, or external quartz, or something else that complicated the circuit and was unacceptable in my case. Finally, after a long search, a scheme that suited me was found here:

http://www.labkit.ru/html/show_meter?id=38
And it was successfully repeated several times. Everything works great. (on the website of the author of this circuit there is both firmware and a printed circuit board for replicating this thermometer). As time went. And one fine time, the shortcomings of this circuit first became clear and I also needed to use an indicator with a Common Cathode (on the author’s website the firmware was only for the Common Anode). Now about the shortcoming of the scheme in the original source. Initially, the author’s circuit does not have a pull-up resistor for the temperature sensor. That is, there is no 4.7K resistor in the circuit. Yes, indeed, with this design of the circuit, the thermometer can work, but only if the temperature sensor is soldered directly into the board, or the length of the wire on which the sensor is located should not exceed a wire length of a meter, one and a half meters. No more. Otherwise, the indicator begins to show some nonsense, not temperature.
This turn of events did not make me happy at all. Because I needed the length of the wire with the sensor to be at least 10 meters.
This problem was solved very simply and quickly, namely by installing a 4.7K pull-up resistor on the sensor. After which the sensor began to work stably for any length of wire. But what if I only have indicators with a common cathode! And the firmware was made for the anode... This is where Stanislav Dmitriev helped me. For which I thank him so much. He not only wrote the firmware for the common anode. But also for a common cathode and for different types of temperature sensors (DS18S20 or DS18B20). This made it possible to further unify this scheme. And recommend it for repetition. It is also possible to use in the circuit both four-bit seven-segment and three-bit seven-segment devices. Which is not a big thing, but still a plus.
Now the circuit itself

As you can see, the diagram is no different from the one presented on the website http://www.labkit.ru
This is how it was originally intended. The only change in the circuit is the installation of an additional resistor. I did not redraw the diagram from scratch. I just added the missing element of the circuit. Essentially, if you want to simplify the circuit even more and you have a stable 5V power source, then you can exclude the linear stabilizer from the circuit. And power the MK directly from 5V.
Now let's talk a little about how to customize the firmware yourself for the indicator or sensor you need. Everything is simple here.

Having loaded the firmware file into the programmer, you yourself: based on what you need and looking at this screenshot, write the parameters you need into the firmware file in the EPROM section. After which you can flash the controller.

In my version of the printed circuit board, the board provides space not only for a linear stabilizer, but also for a diode bridge (which will allow the circuit to be powered with voltage from 7.5V to 12V. The board also provides space for installing a terminal block, which allows you to not solder in a temperature sensor into the board, and clamp it with clamps. This is convenient when changing the sensor, or when installing the sensor on a long wire. Allows you to quickly change the wire.

Board drawing

As you can see, the thermometer is assembled on two boards. One is equipped with a seven-segment indicator (three or four digits). All other elements of the circuit are installed on the second board. The boards are connected to each other using a comb, or, in my case, by wires..
At the end is a photo of my finished thermometer.

A digital thermometer, assembled yourself from scratch, will not only serve you for its intended purpose, but, like everything that is made with your own hands, it will increase your self-esteem (and maybe in a few years it will become valuable as a memory).

Without a doubt, a digital thermometer in the household is a useful thing, but not very functional: apart from measuring temperature, it is not oriented towards anything else. In this regard, a thermometer on a microcontroller will be more useful, since it has the ability to turn on and off any load depending on temperature changes.

However, if you want to do something worthwhile with your own hands, then, as a first step, such a design is fully justified - the experience you gain is priceless.

So, to begin with, let’s choose the simplest thermometer circuit built on a PIC16F84A microcontroller, a DS18B20 digital temperature sensor with a measurement accuracy of up to 0.5 degrees, and a four-digit LED indicator with a common anode. In my case, the FYQ-3641BG-21E display was used.

The advantage of the circuit is its simplicity - from discrete elements we will need a dozen resistors, several capacitors and a 4 MHz quartz resonator. The main disadvantage is that, like all electronic devices, the thermostat requires a power source.

The use of batteries makes the device mobile, but the operating life of one set of batteries can be only 1-2 weeks. Powering the thermometer from the mains power supply “ties” it to any outlet, which is not always convenient.

I will add that the diagram does not show the power connection to the microcontroller - the plus power is supplied to pin 14, and the minus power is supplied to pin 5 of the microcircuit.