So sánh cảm biến nhiệt độ ds18b20 với dht22 năm 2024

Là cảm biến đo nhiệt độ và độ ẩm của môi trường, chuyển đổi các giá trị nhiệt độ và độ ẩm sang giá trị số digital, giao tiếp với MCU [vi điều khiển], Arduino, ESP8266, ESP32... qua giao tiếp 1 dây [chân DATA]. Từ đó vi điều khiển đọc và so sánh giá trị thực tế và giá trị đặt trước để xuất lệnh cho các cơ cấu chấp hành thực hiện đúng mục đích.

Thông số kỹ thuật:

  • Nguồn sử dụng: 3~5VDC.
  • Dòng sử dụng: 2.5mA max [khi truyền dữ liệu].
  • Đo tốt ở độ ẩm 0100%RH với sai số 2-5%.
  • Đo tốt ở nhiệt độ -40 to 80°C sai số ±0.5°C.
  • Tần số lấy mẫu tối đa 0.5Hz [2 giây 1 lần]
  • Kích thước 27mm x 59mm x 13.5mm [1.05" x 2.32" x 0.53"]

SƠ ĐỒ KẾT NỐI VỚI ARDUINO VÀ DHT22 [LOẠI 4 PIN]:

SƠ ĐỒ KẾT NỐI VỚI ARDUINO VÀ DHT22 [LOẠI 3 PIN]:

CÀI ĐẶT THƯ VIỆN CHO ARDUINO ĐỂ GIAO TIẾP VỚI DHT22:

CODE THAM KHẢO GIAO TIẾP DHT22 VỚI ARDUINO:

include

define dataPin 8 // Defines pin number to which the sensor is connected

dht DHT; // Creats a DHT object void setup[] { Serial.begin[9600]; } void loop[] { //Uncomment whatever type you're using! int readData = DHT.read22[dataPin]; // DHT22/AM2302 //int readData = DHT.read11[dataPin]; // DHT11 float t = DHT.temperature; // Gets the values of the temperature float h = DHT.humidity; // Gets the values of the humidity // Printing the results on the serial monitor Serial.print["Temperature = "]; Serial.print[t]; Serial.print[" "]; Serial.print[[char]176];//shows degrees character Serial.print["C | "]; Serial.print[[t * 9.0] / 5.0 + 32.0];//print the temperature in Fahrenheit Serial.print[" "]; Serial.print[[char]176];//shows degrees character Serial.println["F "]; Serial.print["Humidity = "]; Serial.print[h]; Serial.println[" % "]; Serial.println[""]; delay[2000]; // Delays 2 secods }

The purpose of this mini project was to compare these popular hobbyest temperature sensors performance side by side in a "Normal" ambient room temperature.

Supplies

To replicate my example you will need...

  1. DHT11
  2. DHT22
  3. BME680
  4. DS18B20
  5. 4.7k Ohms Resistor
  6. Arduino Nano
  7. Breadboard
  8. Jumper Wires
  9. Arduino IDE
  10. Putty [To log results]

Step 1: Sensor Datasheet Comparison

The BME680 sensor is the most feature rich option with the ability to output 4 different data points on each read [Temperature, Humidity, pressure & gas levels] making it a great all in one option for any hobbyist projects, this comes with the trade of being the only sensor requiring more than 1 data line.

All the other options here use a 1-wire comms line, the DHTxx sensors will require a unique line per sensor while the DS18B20 comes with a 64-bit unique ID meaning you can connect multiple DS18B20 sensors to the same 1-Wire data line.

On paper these sensors have similar temperature reading specs. The least appealing option being the DHT11 which has a much tighter temperature range & the worst recorded accuracy at +/-2%.

On paper all of these sensors are likely accurate enough for a hobbyist project but let now find out how they really perform.

Step 2: How to Wire Up Experiment

For this experiment we will be using an Arduino Nano to communicate with all 4 sensors simultaneously to get a real time comparison of the 4.

Follow the Fritzing diagram if you want to duplicate this setup,

BME680 [I2C]

- SCL = A5

- SDA = A4

DHT11

- Sig = D6

DHT22

- Sig = D5

DS18B20

- Sig = D2 [This line is pulled up to supply 5V with a 4.7k Ohms resistor]

Please review the attached DS18B20 pin out diagram to ensure you have connected VDD & GND the correct way around before powering up!

Step 3: Code & Test

Before you can program the attached code, you will first need to install the required Libraries

include "DHT.h"

include

include

include

include

include

include "Adafruit_BME680.h"

To do so open the Library Manager as shown in the attached image & install the libraries listed above,

Once the libraries have been installed you can download the attached "DHT11_DHT22_BME680_DS18B_Demo.ino" and program the Arduino Nano.

Note that the serial port for this code has been configured for BAUD 115200, so ensure that the Arduino serial port has been configured for that as shown in the attached image.

This code has been configured to output all the sensors results in a CSV format so the data can easily be imported into excel for analysis.

I used Putty to open a com port with the Arduino, my putty terminal was configured to save the console into a .log file which effectively works as a log.

Step 4: Results

I left the setup running for 3 hours at my desk logging the results every approximately 1.5 seconds.

Thermal Raw

I was actually quite surprised by how differently they all behaved,

  1. The DHT11 & DHT22 behaved very similar with the same temperature curve over the 3 hours with a minor

Chủ Đề