I tested DHT11 + Arduino Uno with a very basic example sketch. The Arduino board was connected to USB 3.0 and sometimes I saw incorrect symbols in the serial monitor, e. g. "Humidit?: _7%" instead of "Humidity: 37%". This strange effect disappears when I connected the board to USB 2.0. Baudrate in code was always same as baudrate in the terminal settings.
When I increase baudrate I see less bad symbols but they not disappear while Arduino connected to USB 3.0.
The OS is Ubuntu 20, this was the first time I connect the board to USB 3.0. Is this behavior normal?
The sketch:
/**
* DHT11 Sensor Reader
* This sketch reads temperature and humidity data from the DHT11 sensor and prints the values to the serial port.
* It also handles potential error states that might occur during reading.
*
* Author: Dhruba Saha
* Version: 2.1.0
* License: MIT
*/
// Include the DHT11 library for interfacing with the sensor.
#include <DHT11.h>
// Create an instance of the DHT11 class.
// - For Arduino: Connect the sensor to Digital I/O Pin 2.
// - For ESP32: Connect the sensor to pin GPIO2 or P2.
// - For ESP8266: Connect the sensor to GPIO2 or D4.
DHT11 dht11(4);
void setup() {
// Initialize serial communication to allow debugging and data readout.
// Using a baud rate of 9600 bps.
Serial.begin(9600);
// Uncomment the line below to set a custom delay between sensor readings (in milliseconds).
// dht11.setDelay(1500); // Set this to the desired delay. Default is 500ms.
}
void loop() {
int temperature = 0;
int humidity = 0;
// Attempt to read the temperature and humidity values from the DHT11 sensor.
int result = dht11.readTemperatureHumidity(temperature, humidity);
// Check the results of the readings.
// If the reading is successful, print the temperature and humidity values.
// If there are errors, print the appropriate error messages.
if (result == 0) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C\tHumidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
// Print error message based on the error code.
Serial.println(DHT11::getErrorString(result));
}
}