I have directly connected a DHT22 to my Arduino M0 Pro. I have put a 10k Resistor across the Data & V+ of the sensor pinout. The data is connected to pin 5 and I have it connected to 3.3V output of Arduino.

I am just trying to see some readings from the sensor via the SerialUSB console. I have downloaded and unpacked the DHT libraries that I got on the Adafruit website/GitHub. As far as I know I have these libraries in the right directory - C:\Program Files (x86)\Arduino\libraries\DHT... I also have installed the Adafruit Unified Sensor library on the IDE.

I am trying to use the Tester program that is provided, this compiles ok but the SerialUSB printout prints:

Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!

And so on...

I have tried another DHT22 sensor to no avail.

The only part of the code I have changed is the pin number and changed from Serial to SerialUSB.

Not sure if I have to change anything else? Or am I doing something really silly!

Here is the code:

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 5     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.

void setup() {
  SerialUSB.println("DHTxx test!");


void loop() {
  // Wait a few seconds between measurements.

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    SerialUSB.println("Failed to read from DHT sensor!");

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  SerialUSB.print("Humidity: ");
  SerialUSB.print(" %\t");
  SerialUSB.print("Temperature: ");
  SerialUSB.print(" *C ");
  SerialUSB.print(" *F\t");
  SerialUSB.print("Heat index: ");
  SerialUSB.print(" *C ");
  SerialUSB.println(" *F");
  • 1
    Unrelated to your problem, but FYI C:\Program Files (x86)\Arduino\libraries\DHT is not the correct place to install libraries. It does work but the problem is any time you update to a new version of the Arduino IDE everything you install to C:\Program Files (x86)\Arduino will be lost. This is why you should always install libraries to the libraries subfolder of your sketchbook folder. See arduino.cc/en/Guide/Libraries.
    – per1234
    Nov 4, 2017 at 7:12
  • Thanks, yeah I had to figure that one out the hard way, thanks again though. Nov 8, 2017 at 21:10

1 Answer 1


Found what the fault was, it was a solder short between pins on a custom PCB that was sitting on top of the Arduino board. My bad! At least I have it working now!

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.