I Description
This blog introduces a temperature acquisition and alarm system based on AT89S52 microcontroller and DS18B20 temperature sensor.
Here, we have described the following in detail: scheme design, component selection, hardware structure and software design, etc.
Catalog
II Introduction
2.1 Introduction to temperature measurement system
Temperature measurement systems are widely used in the following fields:
- grain storage;
- medical care;
- transportation;
- smart homes and greenhouses;
- power telecommunication systems;
- …
Moreover, the system with an alarm function can also reduce the risk of temperature accidents.
At present, the temperature values collected by the temperature measuring device are still mainly analog signals. However, the microprocessor can only process digital signals, and A/D conversion is required first. This makes the device structure complex and low precision. However, the emergence of digital temperature sensors can solve this problem.
2.2 Introduction to DS18B20
The new digital temperature sensor represented by DS18B20 integrates temperature acquisition and A/D conversion directly outputs digital signals and has a simple interface circuit with the single-chip microcomputer.
DS18B20 has the features of a single bus, small size, high resolution, strong anti-interference, etc. It has applications in the measurement of highway subgrade temperature field and bearing temperature detection in frozen soil areas.
Moreover, the sensor has a unique 64-bit serial number, and multiple devices can be connected to a single signal line to achieve long-distance, multi-point distributed temperature measurement.
2.3 DS18B20 Temperature measurement system
This blog uses 51 single-chip microcomputers as the processing core, uses DS18B20 to form a temperature measurement module, plus a button module, a display module, and an alarm module, etc., to design a digital temperature collection alarm system suitable for multiple occasions. It is designed to realize multiple functions of synchronous collection, display, alarm, and control of specified temperature. The temperature measurement alarm system has passed the simulation test of the PROTUS simulation platform and successfully verified its function with the circuit board. The device runs stably, with a good temperature measurement effect and small error.
III System scheme structure design
The system includes the following parts:
- The core AT89S52 microcontroller and its peripheral circuits;
- Temperature measurement module (DS18B20 digital temperature sensor);
- Power module;
- Display module (drive circuit, multi-digit LED digital tube);
- Button module;
- Alarm module (buzzer; LED light-emitting diode).
We can take a look at details shown in Figure 1.
Figure 1. Block Diagram of temperature measurement system
When we use the DS18B20 intelligent temperature sensor, it outputs digital signals without processing and conversion. As long as the read and write a sequence of DS18B20 is strictly followed, the real-time temperature can be accurately read.
Even though the system has high precision and relatively complicated procedures, the circuit is simple and small, which is conducive to the intelligentization and lightweight of the system. With multiple DS18B20s connected to a single bus, the microcomputer can communicate with multiple DS18B20s with only one data line. In this way, it can also meet the requirements of multi-point temperature measurement.
IV Selection of main components
4.1 Processor
The system processor uses an AT89S52 single-chip microcomputer. AT89S52 is a high-performance, low-power 8-bit CMOS microprocessor from At-mel. Its 8K system programmable FLASH memory makes its download circuit simple and can realize online programming in serial and parallel mode.
There are 3 16-bit timer/counters inside the AT89S52 chip, 1 full-duplex serial port, 4 I/O ports, and 256bytes RAM, which is convenient for program debugging.
4.2 Digital temperature sensor DS18B20
The DS18B20 temperature sensor is a one-line smart digital temperature sensor produced by DALLAS Semiconductor. In addition, DS18B20 is also the world's first temperature sensor supporting a "single-wire bus" interface. It has the characteristics of long transmission distance, small size, and simple interface.
The DS18B20 is mainly composed of the following components:
- Temperature sensor, configuration register;
- 64-bit ROM;
- High and low alarm triggers TH and TL.
Among them, lithography ROM is the key to realizing multi-point temperature measurement.
After the temperature measurement is converted, it is output in the form of 16-bit sign-extended two's complement and stored in the DS18B202 8-bit RAMs.
V System hardware design
The hardware circuit of the system is mainly composed of the following 5 modules:
Temperature measurement module, power supply module, display module, alarm module and button module. The overall circuit schematic diagram is shown as in Fig. 2.
AT89S52 single-chip microcomputer is connected to a 11.0592MHz crystal oscillator circuit to provide an external clock, and the reset terminal RESET is connected to the watchdog circuit to form a minimal single-chip system.
The system can achieve the following functions:
- DS18B20 collects temperature, and the microcontroller is responsible for the communication and control of the sensor;
- The display module displays the processed temperature value in real time;
- The alarm module monitors the temperature range. When the temperature exceeds the upper and lower limits, LED diodes and buzzers are used to generate alarm signals to remind users to take measures;
- The button module sets the alarm value as required to improve the practicality.
5.1 Power module
The circuit uses +5V working voltage to supply power for the single-chip, acquisition, and alarm circuits. In addition, an independent power module needs to be added during hardware production.
5.2 Temperature acquisition module
DS18B20 utilizes the characteristic of a single bus line, connects the temperature output end DQ and P0.3 mouth through a 4.7kΩ pull-up resistor. The single-chip microcomputer initializes the sensor and completes the temperature collection through the wire. The GND of the sensor is grounded, and VDD can be powered by a data line or an external power supply. In order to improve the anti-interference ability, this design uses an external power supply mode.
Figure 2. Hardware circuit structure
5.3 Display module
In order to save the hardware interface, a dynamic scanning display scheme is adopted. Dynamic scanning is a cyclic shift method that uses the persistence of the human eye to achieve the effect of continuous display.
This design uses a 6-digit 8-segment common cathode digital tube with a decimal point to display the temperature value. Among them, the first digit is the positive and negative sign digit, the second, third, fourth, and fifth digits respectively display the hundreds, tens, ones and decimal places of the temperature, and the last digit displays the temperature unit ℃.
The P2 port of the single-chip microcomputer (P2.0 ~ P2.7 total 8 bits corresponding to 8 fields) is connected with the segment selection common signal line of the nixie tube through the driver chip 74LS245. P3. 0~P3.5 of P3 port are connected with the bit selection signal line of the digital tube to realize bit selection control.
5.4 Alarm module
In order to increase the safety factor, the alarm circuit adopts an alarm method with sound and light double guarantee. This includes a buzzer and 2 LEDs of different colors.
The collected temperature is constantly compared with the set temperature threshold:
When the temperature is higher than the upper limit threshold, the buzzer of port P3.7 sends out a high-frequency alarm signal, and the red LED light of port P0.6 is lit at the same time to give high temperature alarm.
When the temperature is lower than the lower limit threshold, the buzzer sends out a low-frequency alarm signal, and at the same time lights up the blue LED light of port P0.7 to give a low-temperature alarm.
We can realize human-computer interaction through buttons, adjust the temperature threshold, and make the system suitable for more occasions. This module is composed of two parts, one part is the control button (K1~K4), the other part is the indicator light, which occupies the port P1.0~P1.5 of the single-chip microcomputer. For details, we can see Figure 3 below.
When K1 is pressed, the red light is on, indicating that the upper limit setting state is entered, and the temperature is adjusted through the buttons K2 (+) and K3 (-). At the same time, the display module displays the temperature value setting synchronously. After the adjustment is completed, press K1 again to exit.
The lower limit temperature value adjustment (K4) process is consistent with the upper limit.
VI System software design
The DS18B20 hardware circuit is simple, and relatively complicated software design must be used to provide reasonable logic timing to ensure reliable and accurate work. DS18B20 mainly includes 3 kinds of operations: initialization, bus read, and bus write. These three operations must strictly follow the timing requirements. In the following, we will conduct an in-depth analysis of these three aspects.
6.1 Instructions
According to the communication protocol of DS18B20, the sensor must use the ROM instruction and memory RAM instruction provided by it to operate. And these two kinds of instructions appear in the program in the hexadecimal form of 8bit word length. Commonly used codes and specific meanings are shown in Table 1 and Table 2.
Each temperature conversion generally goes through three steps: reset operation, send ROM command, send RAM command, and then read the temperature.
6.2 Initialization sequence
Initialization is one of the basic operations at the bottom of the DS18B20, which is equivalent to establishing a communication bridge between the microcontroller and the sensor to prepare for the subsequent operations. The initialization pulse includes the reset pulse sent by the CPU and the response pulse sent by the sensor. The initialization pulse sequence is shown in Figure 3.
Figure 3. DS18B20 initialization sequence
The host first sends out a reset pulse (low-level signal) of 480-960μs and then releases the bus to enter the receiving mode (RX). When DS18B20 detects the rising edge when the bus is released, it waits for 15-60μs, and then sends out a low-level response pulse with a delay of 60-240μs. At this time, the DQ of the sensor is set to 1, and the host is also set to 1, and the initialization process is completed. At this time, the sensor is in a state where it can be read and written
6.3 Bus write timing
Writing data to DS18B20 is the basic operation of sending instructions and data. The right shift operation is used to realize bit-by-bit writing with low bit in front and high bit in back. It mainly includes two timings: writing "0" and writing "1".
The write sequence starts when the host pulls down the bus for more than 1μs, and sends the signal to be sent to the DQ within 15μs, waiting for the sensor to sample it, and the sensor completes the data collection within 45μs.
During data collection, if the bus is high, write logic "1"; otherwise, write logic "0".
It can be seen from the write sequence in Figure 4 that one write cycle requires at least 60 μs, and there must be an interval greater than 1 μs between two write cycles.
Figure 4. Write time sequence of DS18B20
6.4 Bus write timing
Writing data to DS18B20 is the basic operation of sending instructions and data. The right shift operation is used to realize bit-by-bit writing with low bit in front and high bit in back. It mainly includes two timings: writing "0" and writing "1".
The write sequence starts when the host pulls down the bus for more than 1μs, and sends the signal to be sent to the DQ within 15μs, waiting for the sensor to sample it, and the sensor completes the data collection within 45μs. During data collection, if the bus is high, write logic "1"; otherwise, write logic "0".
It can be seen from the write sequence in Figure 4 that one write cycle requires at least 60 μs, and there must be an interval greater than 1 μs between two write cycles.
Figure 5. Read time sequence of DS18B20
6.5 Temperature acquisition program
Take the temperature acquisition program as an example to briefly explain the source code:
Void Convert_18B20(Void)
{RST_18B20();
WR_18B20(0xcc);
WR_18B20(0x44);}
Int Read_18B20(Void)
{RST_18B20();
WR_18B20(0xcc);
WR_18B20(0xbe);
Temp_8[0]= RD_18B20;
Temp_8[1]= RD_18B20;
return(Temp_8);}
VII Experimental test
The test temperature value is shown in Table 3.
The system error is less than 0.5, and the test results show that the system has high accuracy and strong practicability.
VIII Conclusion
This article designs a temperature acquisition alarm system based on AT89S52 single-chip microcomputer and DS18B20 digital temperature sensor, and details the software and hardware design. The design has the advantages of simple structure, high precision and good stability, and is suitable for the following fields: granary, electric machine room, bearing, air conditioner, refrigerator, industry and agriculture, etc.
The DS18B20 single bus and multi-point temperature measurement feature strengthens its scalability and has a broad market prospect.
FAQ
- What is DS18B20 temperature sensor?
The DS18B20 is a 1-wire programmable temperature sensor from maxim integrated. It is widely used to measure temperature in hard environments like in chemical solutions, mines or soil etc. The constriction of the sensor is rugged and also can be purchased with a waterproof option making the mounting process easy.
|
- How does the DS18B20 work?
It works on the principle of direct conversion of temperature into a digital value.
|
A thermistor is a thermal resistor - a resistor that changes its resistance with temperature. ... Thermistors have some benefits over other kinds of temperature sensors such as analog output chips (LM35/TMP36 ) or digital temperature sensor chips (DS18B20) or thermocouples.
|
The DS18B20 reads with an accuracy of ±0.5°C from -10°C to +85°C and ±2°C accuracy from -55°C to +125°C.
|
The DS18B20 is one type of temperature sensor and it supplies 9-bit to 12-bit readings of temperature. ... The communication of this sensor can be done through a one-wire bus protocol which uses one data line to communicate with an inner microprocessor.
|
- How do I connect my DS18B20 to my Raspberry Pi?
Once you've connected the DS18B20, power up your Pi and log in, then follow these steps to enable the One-Wire interface: 1.At the command prompt, enter sudo nano /boot/config.txt , then add this to the bottom of the file: 2.dtoverlay=w1-gpio. 3.Exit Nano, and reboot the Pi with sudo reboot.
|
- What is the working principle of DS18B20?
The DS18B20 Digital Thermometer provides 9 to 12-bit (configurable) temperature readings which indicate the temperature of the device. It communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition it can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. The core functionality of the DS18B20 is its direct-to-digital temperature sensor. The resolution of the temperature sensor is user-configurable to 9, 10, 11, or 12 bits, corresponding to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default resolution at power-up is 12-bit.
|
- Where to use DS18B20 Sensor?
The DS18B20 is a 1-wire programmable Temperature sensor from maxim integrated. It is widely used to measure temperature in hard environments like in chemical solutions, mines or soil etc. The constriction of the sensor is rugged and also can be purchased with a waterproof option making the mounting process easy. It can measure a wide range of temperature from -55°C to +125° with a decent accuracy of ±5°C. Each sensor has a unique address and requires only one pin of the MCU to transfer data so it a very good choice for measuring temperature at multiple points without compromising much of your digital pins on the microcontroller.
|
- How connect DS18B20 to Arduino?
First plug the sensor on the breadboard the connect its pins to the Arduino using the jumpers in the following order: pin 1 to GND; pin 2 to any digital pin (pin 2 in our case); pin 3 to +5V or +3.3V, at the end put the pull-up resistor.
|
- On an ATMega328P, why is a DS18B20 temperature sensor returning incorrect temperature values?
Several possibilities: 1. If it is just reading a little high, it might be caused by “self heating”. Add a heat sink and/or make measurements less frequently. 2. Especially if the values are really whacky, it might be code with errors or mis-wiring. Use a published sketch to check operation. 3. The DS18B20 might be defective. Try another. 4. It’s accurate to 0.5ºC.
Are you expecting it to be more accurate (like down to the LSB of the read value)?
|