temperature measurement for the Arduino sensor serial

Source: Internet
Author: User
Tags network function

The temperature measurement of the Arduino sensor serial Source: http://www.hzhike.com/School/2016/201607/20160711100131.html

The temperature is the physical quantity that we often come into contact with, can be felt by our intuition, for example, the weather is cool need to add clothes, eat food too hot need to blow a blow, also need to accurate temperature measurement, For example, human normal body temperature is 37.5 ℃, the temperature of boiling water at atmospheric pressure is 100 ℃, we need to do experiments to find out the science. Below we will explain in detail several common temperature sensors and use the Arduino to measure temperature, including thermistors, LM35, Ds18b20, DHT11 and thermocouples.

1. Thermistor 1.1 thermistor Introduction

A thermistor is a semiconductor sensor whose resistance value changes with temperature, and its typical characteristic is that the resistance value is very sensitive to temperature, which shows different resistance values at different temperatures, thereby deriving the ambient temperature value from the reversible derivation of the resistance value of the performance. It has the advantages of high sensitivity, small volume, small heat capacity, fast response speed and low price. According to the different temperature coefficient, it can be divided into positive temperature coefficient thermistor (PTC), negative temperature coefficient thermistor (NTC) and critical negative temperature coefficient thermistor (CTR). The higher the temperature of PTC, the greater the resistance value; The lower the NTC's resistance value as the temperature increases; Ctr has the negative resistance mutation characteristic, at a certain temperature, the resistance value decreases with the temperature, and has a large negative temperature coefficient. Because of the different characteristics, the use of thermistors is also different. PTC is generally used as a heating element and thermal protection; NTC is generally applied to temperature measurement and temperature compensation; Ctr is generally used for applications such as temperature control alarms. The NTC's temperature range is -60~+300℃ and the nominal resistance is typically between 1ω to 100mω, and the combination of precision resistors and thermistors expands the linear range of the measurement temperature. The NTC 10d-9 and NTC 5d-7 are shown in Figure 1. NTC is expressed as a negative temperature coefficient of the thermistor, 10d-9 and 5d-7 represent its model, 10d-9 represents a normal temperature (25 degrees Celsius) resistance 10 ohm, 9 mm diameter, 5d-7 represents the normal temperature (25 degrees Celsius) resistance 5 ohm, diameter 7 mm. In addition to the shapes shown in Figure 1, the probes made of thermistors are bead-shaped, rod-shaped, sheet-shaped and film-like, with casing structures such as glass, nickel and stainless steel tubes, as shown in 2.

Figure 1 NTC Physical diagram

Fig. 2 Various forms of NTC

How to use 1.2 NTC

The NTC's measured temperature and the resistance value shown have a non-linear known relationship, then the measurement of the NTC's resistance value can also be calculated to obtain its measured temperature value. The relationship between the NTC's resistance value and temperature value is as follows:

Rt = R x e^[b x (1/T1-1/T2)]

, Rt is the resistance of the thermistor at T1 temperature, R is the nominal resistance of the thermistor at T2 temperature, the B value is an important parameter of the thermistor, and T1 and T2 refers to the K degree, i.e. Kelvin temperature, K degree =273.15 (absolute temperature) Celsius.

The relationship between the temperature value of the thermistor and the resistance value in reverse calculation is as follows:

t1=1/(ln (RT/R)/b 1/t2)

The measurement of resistance is usually measured by the resistor with known resistance in series and by applying a known-sized voltage, and by measuring the value of the divider on the resistor of the known resistance, the resistance of the measured resistor is calculated, as shown in 3. The applied excitation voltage is EB, the resistance of the thermistor is RT, the series Resistance value is RS, the voltage divider on the series resistor is:

Eout = Eb x rs/(Rt Rs)

In addition to the tandem measurement method, there is a Wheatstone bridge measurement method, shown in 4. The excitation voltage of the bridge is EB, the resistance of the thermistor is RT, the bridge resistance value is R1, R2 and R3, the bridge output voltage is:

out = EB x r3/(rt R3) –eb x r2/(R1 R2) = EB x [r3/(Rt R3) –r2/(R1 R2)]

Fig. 3 Series Measurement method

Fig. 4 Measuring method of bridge

1.3 Usage Examples

(1) Hardware connection

The test of thermistor measurement using the series measurement method is shown in the hardware connection Figure 5, the thermistor is the NTC 10d-9 and the resistance of the series resistor is 100 Ω.

Figure 5 NTC temperature measurement hardware Connection diagram

(2) Program design

The main idea of program design: The Arduino UNO controller measures the voltage value on the series resistor through the analog input port, then calculates the resistance of the thermistor by the principle of equal current, and finally calculates the temperature value using the formula.

#include//contains math library void Setup () {serial.begin (9600);//baud rate set to 9600}void loop () {double digital_value=analogread (0); Read voltage value on series resistor (digital) Double voltage_value= (digital_value/1023) *5.00;//converted to analog voltage value double rt_value= (3.3-voltage_value)/ voltage_value*100; Calculate the thermistor's resistance//calculate the perceived temperature and send serial.println (1/(log (RT_VALUE/10)/3000 1/(25 273.15))-273.15,2); Delay (1000); Refresh once a second}
2 LM35

The LM35 is an analog temperature sensor produced by the United States NS (National Semiconductor) whose output voltage is linearly proportional to the Celsius temperature, 0V at 0 ℃, and a 10mV increase in the output voltage per 1 ℃. Temperature range L? 55 ~ 150? C, accuracy of 0.75 ℃, room temperature accuracy of up to 0.25 ℃. The commonly used TO-92 package is shown in pin arrangement 6, as shown in the typical application circuit 7 within the 2℃~150℃ temperature range.

Figure 6 pin arrangement for the TO-92 package

Fig. 7 Typical circuit diagram of 2℃~150℃

2.3 Usage Examples

(1) Hardware connection

The VS and GND of the LM35 analog temperature sensor are respectively connected to the 5V and GND of the Arduino UNO controller to provide a working power supply to the LM35, and the LM35 vout pin is connected to the Arduinouno controller analog input port a0,8.

Figure 8 LM35 temperature measurement Hardware Connection diagram

2) Program Design

The main idea of program design: The Arduino UNO controller measures the voltage value of the LM35 output via the analog input port, and calculates the temperature value by the 10mv/℃ ratio factor. At the same time, at 100 ℃, the LM35 output voltage value is 1000mV, within the internal reference voltage range of the Arduino Uno controller, so a 1.1V internal reference voltage is used.

int digital_value=0;float temp_value=0;void setup () {serial.begin (9600);//baud rate is set to 9600//due to the temperature range of 0~100℃, the output voltage is 0~1v, With internal 1.1V reference voltage analogreference (INTERNAL);} void Loop () {digital_value=analogread (A0);//Read voltage value (digital) temp_value= (float) digital_value/1023*110.00;//conversion to Celsius temperature Serial.print (' Temperature for LM35 is: '); Serial.println (temp_value,2); Send temperature data delay (1000)//one Second refresh}

(3) Experimental demonstration

The actual experimental hardware connection is shown in Figure 9, and the serial port receives the temperature data 10 shown.

Figure 9 Experimental hardware connection diagram

Figure 10 temperature data received at the serial port

3 ds18b203.1 Ds18b20 Introduction

DS18B20 is the digital single-bus intelligent temperature sensor of Dallas Semiconductor Corporation, which can read the measured temperature directly compared with the traditional thermistor, and can realize the digital value reading of 9~12 bit by simple programming according to the actual requirement. Reading or writing information from DS18B20 requires only one line (single bus) to read and write, and the bus itself can power the attached device without additional power.

The performance characteristics of DS18B20 are as follows:

(1) Single-wire interface to achieve two-way communication;

(2) Supply voltage range: 3.0v~ 5.5V, available data line power supply;

(3) Temperature range: -55~ 125 ℃, natural temperature measurement resolution of 0.5 ℃;

(4) The digital reading mode of 9~12 bit can be realized by programming;

(5) Support multi-point network function, multiple DS18B20 can be paralleled in the only single bus, to achieve multi-point temperature measurement.

The shape of the ds18b20 and the pin arrangement of 11, the DS18B20 Pin definition: (1) DQ for the digital signal input/output, (2) GND is the power source, (3) VDD is the external power supply input terminal (when the parasitic power wiring mode grounding).

Figure One DS18B20 package diagram

3.2 Ds18b20 Programming and library usage

Arduino to implement the operation of the Ds18b20, need to OneWire and Dallas temperature control two library files, respectively: http://playground.arduino.cc/Learning/ OneWire and Https://github.com/milesburton/Arduino-Temperature-Control-Library. Dallas Temperature Control Library is based on OneWire function library to develop, more convenient to use, the following explains the function and usage of the main function.

(1) void Begin (void): initialization, no input parameters, no return parameters.

(2) Getdevicecount (void): Gets the total number of connected devices on a single bus with no input parameters and returns the number of devices.

(3) validaddress (uint8_t*): Verifies that the device of the specified address is present, the input parameter is the device address, and the return parameter is Boolean.

(4) getaddress (uint8_t*, const uint8_t): Verifies that the address of the device matches the index value, the input parameter is the device address and the index value, and the return parameter is Boolean.

(5) Getresolution (uint8_t*): Gets the precision of the specified device, the input parameter is the device address, and the return parameter is the number of precision digits.

(6) Setresolution (uint8_t*,uint8_t): Sets the accuracy of the device, the input parameter is the device address and the number of precision digits, no return parameters. The number of precision bits is 9,10,11 and 12 is available for selection.

(7) requesttemperatures (void): A request to send a temperature conversion to all devices on a single bus, no input parameters, no return parameters.

(8) requesttemperaturesbyaddress (uint8_t*): Sends a temperature conversion request to the device specified on the single bus, the input parameter is the device address, and no return parameters.

(9) Requesttemperaturesbyindex (uint8_t): A request to send a temperature conversion to a device with a specified index value on a single bus, the input parameter is the device index value, and no return parameter.

GETTEMPC (uint8_t*): The temperature of Celsius is obtained through the device address, the input parameter is the device address, and the return parameter is Celsius.

(one) Gettempf (uint8_t*): Through the device address to obtain the Fahrenheit temperature, the input parameter is the device address, the return parameter is Fahrenheit temperature.

Gettempcbyindex (uint8_t): The index value to obtain the Celsius temperature, the input parameter is the device index value, the return parameter is Celsius temperature.

Gettempfbyindex (uint8_t): Obtains the Fahrenheit temperature through the device index value, the input parameter is the device index value, the return parameter is the Fahrenheit temperature.

3.3 Usage Examples

Because the single bus can connect multiple ds18b20, and not occupy the IO port of the Arduino controller, so it is easy to realize multi-point temperature measurement, the following two examples are used to illustrate the use of Ds18b20 and Arduino.

3.3.1 Road Temperature measurement

(1) Hardware connection

The VCC and gnd of the DS18B20 temperature sensor are connected to the 5V and GND of the Arduino UNO controller respectively to provide power to the DS18B20, DS18B20 the DQ pin to the Arduinouno controller digital pin D2, And the pull-up resistor of the parallel 4.7kω is shown in 12.

Figure 121 Road Temperature measurement hardware Connection diagram

(2) The main idea of programming design: Arduino UNO controller through the Dallastemperature function library to achieve the start of a single bus, the request to send measurement temperature, read the No. 0 sensor temperature, finally sent out through the serial port.

#include #include #define One_wire_bus 2//define the port of the single bus connection OneWire OneWire (one_wire_bus);D allastemperature Sensors (& OneWire); void setup (void) {serial.begin (9600); Serial.println (' Dallas temperature IC Control Library Demo '); Sensors.begin (); Start single bus}void loop (void) {Serial.print (' requesting temperatures ... '); Sensors.requesttemperatures ();//Send temperature measurement request command Serial.println (' done '); Serial.print (' temperature for the device 1 (index 0) is: '); Serial.print (Sensors.gettempcbyindex (0)); Get NO. 0 sensor temperature data and send Serial.println (' ℃ '); Delay (1000); Refresh once a second}
3.3.2 multi-channel temperature measurement

(1) Hardware connection

The VCC and GND of the two DS18B20 temperature sensors are connected to the 5V and GND of the Arduino UNO controller respectively to provide power to two ds18b20, two Ds18b20 dq pins to the Arduinouno controller digital pin D2, And the pull-up resistor of the parallel 4.7kω is shown in 13.

Figure 13 Multi-channel temperature measurement hardware connection diagram

(2) Program design

The main idea of the program design: Arduino UNO controller through the Dallastemperature function library to achieve the start of a single bus, the request to send a measurement temperature, read the No. 0 sensor temperature and the serial port sent out, read the 1th sensor temperature and the serial port sent out.

#include #include #define One_wire_bus 2//define single bus connection port OneWire OneWire (one_wire_bus);D allastemperature Sensors (& OneWire); void setup (void) {Serial.begin (9600) serial.println (' Dallas temperature IC Control Library Demo '); Sensors.begin (); Start single bus}void loop (void) {Serial.print (' requesting temperatures ... '); Sensors.requesttemperatures ();//Send temperature measurement request command Serial.println (' done '); Serial.print (' temperature for the device 1 (index 0) is: '); Serial.println (Sensors.gettempcbyindex (0)); Obtain the No. 0 sensor temperature data and send serial.print (' temperature for the device 2 (index 0) is: '); Serial.println (Sensors.gettempcbyindex (1)); Get sensor temperature data 1th and send}
3.3.2 Experiment Demo

The actual single-channel experimental hardware connection shown in Figure 14, the single-and two-way experiment in the serial port received temperature data are shown in 15 and 16 respectively.

Figure 14 Single-channel experimental hardware connection diagram

Figure 15 temperature data received from a single serial port

Figure 162 serial port reception temperature data

4 DHT114.1 DHT11 Introduction

The DHT11 is a temperature and humidity composite sensor with calibrated coefficients for digital signal output, with dedicated digital module acquisition technology and temperature and humidity sensing technology, with high reliability and excellent long-term stability, including a resistive wetted element and an NTC temperature measurement element. The DHT11 sensors are laboratory calibrated and the calibration coefficients are stored in OTP memory in the form of a program, which calls these calibration coefficients during the processing of the heartbeat and uses a single-wire serial interface to make system integration easy and quick. Ultra-small volume, very low power consumption, signal transmission distance of up to 20 meters. The DHT11 digital temperature and humidity sensor is shown in Figure 17.

Figure DHT11 Temperature and humidity sensor

The pin description of the DHT11 is shown in table 1, the supply voltage is 3.3~5v, the measuring range is humidity 20~90%rh, the temperature 0~50℃, the measurement accuracy is humidity ±5%rh, the temperature ±2℃, the measurement resolution is humidity 1%RH, temperature 1 ℃.

4.2 DH11 Programming and library usage

DHT11 's Arduino library file: Https://github.com/markruys/arduino-DHT. The DHT11 library file has the following functions: Dht.setup (int Pin), dht.gethumidity (), Dht.gettemperature ().

Dht.setup (int Pin): Sets the connection pin number of the DHT11 bus, the input parameter is the PIN number of the connection, no return parameters.

Dht.gethumidity (): Gets the humidity value of the DHT11, no input parameters, the return value is the humidity value, the double type.

Dht.gettemperature (): Gets the temperature value of the DHT11, no input parameters, the return value is the temperature value, the double type.

4.3 Usage examples

The following DHT11 module to achieve temperature and humidity measurement, and through the serial output. (1) The hardware connection will DHT11 the temperature and humidity sensor VCC, GND respectively connected to the Arduino uno controller 5V, GND, to provide power to DHT11, DHT11 module dout PIN to Arduinouno controller digital pin D2, And the pull-up resistor of the parallel 5kω, the NC pin of the DHT11 module is also connected to the gnd,18 as shown.

Figure DHT11 Temperature and humidity measurement hardware connection diagram

(2) The main idea of programming design: Arduino UNO controller obtains the humidity and temperature data through the DHT11 function library, and sends out through the serial port.

#include ' DHT.h ' DHT dht;void setup () {serial.begin (9600); Dht.setup (2);//Data pin 2 delay (1000);} void Loop () {Float temperature = dht.gettemperature (); Float humidity = dht.gethumidity (); Serial.print (' temperature is '); Serial.print (temperature, 1); Serial.println (' C '); Serial.print (' humidity is '); Serial.print (humidity, 1); Serial.println ('% '); Delay (3000);}

(3) Experimental demonstration of the actual experimental hardware connection shown in Figure 19, the experimental serial port received temperature and humidity data 20 is shown.

Figure 19 Experimental hardware connection diagram

Fig. 20 temperature and humidity data received by serial port

5 thermocouple 5.1 thermocouple and MAX6675 Introduction

The conductors of two different materials or semiconductors A and B are welded together to form a closed loop, and when there is a temperature difference between the two connection points 1 and 2 of the conductors A and B, the electromotive force is generated between them, thus forming a loop current in the circuit. This phenomenon is called thermoelectric effect, and this electromotive force is called thermoelectric potential. The thermoelectric schematic is shown in Figure 21.

Figure 21 Thermoelectric schematic diagram

Thermocouples are the use of thermoelectric principle for temperature measurement, wherein the directly used as the measurement medium temperature of the end is called the working end (also known as the measuring end), the other end is called Cold Junction (also known as the Compensating end). is actually an energy converter that converts heat energy into electrical energy and uses the resulting thermoelectric potential to measure temperature. Commonly used type K thermocouple physical 22, can be directly measured in a variety of production from 0 ℃ to 1300 ℃ range of liquid vapor and gas media and the surface temperature of solids. The utility model has the advantages of good linearity, large thermoelectric dynamic potential, high sensitivity, good stability and uniformity, strong antioxidant performance and low price.

Figure K Type Thermocouple Physical map

According to the principle of thermocouple temperature measurement, the output thermoelectric potential of type K thermocouple is related not only to the temperature of the measuring end, but also to the temperature of the cold end, the temperature compensation circuit (23 is compensated) and the voltage and temperature of the thermocouple are nonlinear, and the MAX6675 module can amplify the K-type thermocouple, Cold-junction compensation and nonlinear correction. The MAX6675 has a simple 3-bit serial SPI interface, which converts the temperature signal to 12-bit digital, temperature resolution up to 0.25 ℃, and a thermocouple break detection circuit. The temperature range of the cold junction compensation is -20℃~80℃, which can measure the temperature of 0℃~1023.75℃, and meet the needs of industrial temperature measurement basically.

5.2 MAX6675 Programming and library usage

MAX6675 's Arduino library file: https://github.com/aguegu/ardulibs/tree/master/max6675. The MAX6675 library file has the following functions: Getcelsius (), Getfahrenheit (), Getkelvin (), and setoffset (int offset).

Getcelsius (): Get Celsius temperature, no input parameter, return value is Celsius temperature, float type. Getfahrenheit (): Get Fahrenheit temperature, no input parameters, return value is Fahrenheit temperature, float type. Getkelvin (): Get Kelvin temperature, no input parameters, return value is Kelvin temperature, float type. SetOffset (int offset): Sets the temperature offset, the input parameter is the offset value, the int type, the minimum unit is 0.25 ℃, no return value.

5.3 Usage Examples

The following is a type K thermocouple and MAX6675 module to achieve high temperature measurement, and through the serial port output.

(1) Hardware connection

The VCC and GND of the MAX6675 module are respectively connected to the 5V and GND of the Arduino UNO controller to provide power to the MAX6675, and the MAX6675 module's signal pins So, CS, and CSK are connected to the digital pins 5, 6, The positive and negative poles of the type 7,k thermocouple are respectively connected to the T and t-,24 of the MAX6675 module.

Figure 24 Thermocouple temperature measurement Hardware Connection diagram

(2) Program design

The main idea of program design: Arduino UNO controller obtains the temperature value measured by the thermocouple through the MAX6675 function library, completes the signal amplification of the thermocouple output voltage, the cold end compensation and the non-linearity processing, finally through the serial port output.

#include ' Max6675.h ' Max6675 ts (5, 6, 7); Define so, CS, CSK the PIN number that is connected by void Setup () {ts.setoffset (0);//Set the temperature offset serial.begin (9600);} void Loop () {Serial.print (' temperature is '); Serial.println (Ts.getcelsius (), 2); Get the Celsius temperature and send delay (1000) via serial port; Refresh once a second}

(3) Experimental demonstration

The actual experimental hardware connection shown in Figure 25 shows that the serial port received the temperature data 26 shown in the experiment.

Figure 25 Experimental hardware connection diagram

Figure 26 temperature data received at the serial port

6. Summary

In this paper, several common sensors for temperature measurement are introduced, which are introduced in detail from the principle of thermometry, the characteristics of devices and the programming and use in Arduino. To summarize this article, there are the following points:

1, NTC thermistor low price, but want to get very high measurement accuracy, need to do a lot of optimization work, difficult.

2, LM35 direct output analog voltage, the use of more convenient, high precision, suitable for thermocouple cold-junction compensation in the ambient temperature measurement.

3, Ds18b20 is a single bus digital temperature sensor, cost-effective, high measurement accuracy, and can be a single bus to hang multiple sensors.

4, DHT11 is a temperature and humidity sensor, single bus, do not occupy too much I/O port, and can output humidity data at the same time, suitable for the application of temperature and humidity data.

5, Thermocouple and MAX6675 with the use, suitable for high temperature measurement, eliminating the thermocouple cold-junction compensation, Linearization and analog-to-digital conversion work, the use of more aspects, high precision, the data for two times to fit the calibration, you can get higher measurement accuracy.

Finally, compared to the Thermocouple MAX6675 module and the response speed of the DS18B20, 27 is based on the Arduino and LabVIEW experimental platform to collect the thermocouple in the hot water in the data changes, it can be seen that the maximum temperature of about 60 ℃, the thermocouple response curve is relatively straight, Rise faster. 28 shown in the experiment platform based on Arduino and LabVIEW to collect the response curve of ds18b20 for hot and cold change, it can be seen that the maximum temperature exceeds the 80℃,DS18B20 response curves more gently, with the reduction of temperature difference, the response rate is more slow.

Fig. 27 Curve of thermocouple temperature change response

Figure Ds18b20 Temperature Change response curve

temperature measurement for the Arduino sensor serial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.