1

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));
  }
}
5
  • You are using the UNO's internal serial transceiver, right?
    – timemage
    Commented Mar 8 at 16:27
  • @timemage I guess yes, in this moment I don't know communication variants except default
    – Mik
    Commented Mar 8 at 17:38
  • That really sounds like either a bad cable or a bad USB port on the PC. The Arduino itself isn't aware of the difference whether it is 2.0 or 3.0. When you change from 2.0 to 3.0 are you using the same cable just in a different port on the PC?
    – Delta_G
    Commented Mar 8 at 18:26
  • @Delta_G yes I'm using the same cable. USB 3.0 is on a PCI-E extension board but other devices (BT & WiFi dongles, flash cards) work correctly with this cable, this port and its neighbours. Much better than with built-in 2.0 ports of motherboard.
    – Mik
    Commented Mar 8 at 19:32
  • I still think the issue is going to be on the PC end of the connection somewhere.
    – Delta_G
    Commented Mar 8 at 20:13

1 Answer 1

-1

Please check if there is any baud rate mismatch. I mean, you have defined serial.begin(9600) in your code. Open the serial monitor selecting the same baud rate please. If that is not the problem, please check the cable. If you have any other operating system, like windows, please check your whole setup with that too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.