DHT22 working example with HTCC-AB02

Hello, complete noob here but I have some background in coding. I’m trying to connect my HTCC-AB02 to a DHT22 sensor, but with no result until now.

My DHT is a 3 pins board version, I connect it via Vcc, GPIO5 and GND, I’ve tried different libraries but all I got until now is NaN results.

May someone provide me with a simple working example ? -> Thanks !

The examples in the libraries will be working examples, show you code here?

Hi,

Did you manage to get it working? I´m searching for a working example with DTH22 and HTCC-AB02A but without success.

Regards,

Eduardo Bastos

I was struggling, too. I got the DHT22 readings working using the Adafruit DHT Sensor Library and the following code. Note the Pin definition uses “GPIO5” instead of “5” - this did the trick for me.

Also, If you do single readings using sleep functions and your code doesn’t use the loop function, be aware that the sensor needs some time to get valid data in the reading. therefore you need to add a delay after the dht.begin() statement. some sources on the net say 2 seconds, I have got resonable values back after one second. below 700 milliseconds I got “nan” values.

Edit: I need to mention that I am using a HTCC-AB01 CubeCell Development board…

******* CODE START <<<<<<
#include “DHT.h”

#define DHTPIN GPIO5 // the pin the DHT is connected to
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {

dht.begin();

}

void loop() {

float temperature = dht.readTemperature();
float humidity = dht.readHumidity();

}

********* CODE END <<<<<<

Hi,

I had the same issue (Nan) using the DHTtester from the example library to work with the cubecell using the DTH11 and DTH22.

It works with ESP32 but it does not with the cubecell.

I was mentioned before, I changed the GPIO declaration to try to debug but it didn’t.

Code:

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

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include “DHT.h”

#define DHTPIN GPIO2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 –
// Pin 15 can work but DHT must be disconnected during program upload.

// 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 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)
// 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.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
dht.begin();
Serial.println(F(“DHTxx test!”));

}

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

// 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)) {
Serial.println(F(“Failed to read from DHT sensor!”));
return;
}
*/
// 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);

Serial.print(F("Humidity: “));
Serial.print(h);
Serial.print(F(”% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F(“°F”));
}

The ground pin was not well welded. It works now.

I have the same problem, I have no sensor reading with the cubecell AB01. Any help?

The code I use is the following, but I have no sensor reading, I need help.

#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN GPIO5 // the pin the DHT is connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
delay(2000); // Please do not alter these. these delays will make sure your arduino will run properly
Serial.begin(9600);
delay(2000);
dht.begin();
}

void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
Serial.print(temperature);
Serial.println();
}

I’m writing to those who are struggling to get readings…
the code above works, im using GPIO4 in my code
also, I was not able to get a reading because one of the DHT22 sensors was defective. you should try another sensor if you are getting no readings.

//Libraries

#include <DHT.h>

//Constants

#define DHTPIN GPIO4 // what pin we’re connected to

#define DHTTYPE DHT22 // DHT22

DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino

//Variables

float hum; //Stores humidity value

float temp; //Stores temperature value

void setup()

{

//Initialize serial port

Serial.begin(115200);

Serial.println(“DHT22 sensor testing”);

//Initialize the DHT sensor

dht.begin();

//delay(2000);

}

void loop()

{

float converted = 0.00;



//Read data and store it to variables hum and temp

hum = dht.readHumidity();

temp= dht.readTemperature();

Serial.print("Celsius = ");

Serial.print(temp);

Serial.println("C");

//Fahrenheit

//T(°F) = T(°C) × 9/5 + 32

converted = ( temp * 1.8 ) + 32;

Serial.print("Fahrenheit = ");

Serial.print(converted);

Serial.println("F");

Serial.print("Humidity =");

Serial.println(hum);

//2000mS delay between reads

delay(2000);

}