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. Show Thông số kỹ thuật:
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 connecteddht 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. SuppliesTo replicate my example you will need...
Step 1: Sensor Datasheet ComparisonThe 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 ExperimentFor 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 & TestBefore 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: ResultsI 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,
Thermal Zeroed I formatted the results so that they all started at 0C, then plotted the change from original start point over the test period. This filters out the actual temperature in the room and instead highlights the change measured by the sensors.
Humidity Raw The Humidity results were very consistent with all 3 sensors able of measure having identical shapes over the 3-hour test period.
I would have expected the BME680 to outperform the DHT22 here due to it using a MEMS sensor system, but the resistive moisture sensor in the DHT22 works impressively well. Obviously, all these results have to be taken with a large pinch of salt, none of these devices have been calibrated so we can only compare them to one another. Based on these results I would likely recommend the BME680 if the best resolution is required, but the DHT11 is surprisingly good considering it's so cheap! Step 5: ConclusionsDHT11 - This is the cheap and cheerful option. Simple to setup & use, cheap and quite accurate DHT22 - This is a beefed-up version of the DHT11 improved accuracy while still being simple to use at the cost of an increased price BME680 - The most feature rich option with excellent resolution and accuracy at the cost of a more complex communication setup and price DS18B20 - The industrial/extreme environment option, while the accuracy of this sensor for its price is not that impressive, it trades that off with the ability to stack multiple sensors on a 1-Wire signal line and the closed enclosure of the DS18B20 makes it ideal for harsh environments or outside use. Step 6: Thanks for ReadingI hope this short guide has been helpful, if you have any questions please leave a comment or direct message me! |