XIAO ESP32C3 and DHT22 Sensor

I am working with a group of high school engineering students who are building an automated Compost Barrel. We are in the prototype stage right now and trying to develop the code to read temperature, humidity and soil/compost moisture content. The idea being to rotate the barrel based on these measurements. We have chosen the XIAO ESP32C3 because of its size and wifi capability. We have one ESP set up to rotate the barrel using a web interface. That is working fine. However, when we try to interface the DHT 22 and read the temperature all we get is nan.

Here is what we have tried.

  1. Different sensor
  2. Different ESP32
  3. Different ports on the ESP32
  4. Checked voltages from 5V and 3.3V ESP32 pins.
  5. Recoded so we only test the basic functionality of reading and displaying temp via Serial port.

Nothing we have tried works. If anyone has any suggestions I would appreciate some ideas. I have seen this seems to be a common problem, or at least others have had similiar issues. But none of those solutions have worked?

Thank you.

I can post code if needed later today.

Please post schematics and code.

I suggest you teach your students the language of electronics and generate an annotated schematic showing exactly how you have wired your project. Without the ability to read and understand them there electronics career is limited. Frizzes do not count as schematics, they are wiring diagram. Post links to the technical information on the hardware items you are using. FYI I found that the ESP32-C3 has five variations.
Doing this will help answer @Railroader request.

Do you have a pull-up resistor connected to the data pin?

gilshultz,

Thanks, but these are high school kids just getting started in engineering. They have no engineering background and know nothing about electronics. This is a one semester project, the objective of which is to encourage high school students to consider an engineer/science career. So teaching them something like Kicad is really out of the question right now. I have a difficult enough time showing/explaining the principles of electronics without the complications of teaching them a design program. We have a schematic (drawing) of the pinouts for this project and I will post it this afternoon when I get back to my lab. I will also post the code. As for the tech specs, all I have been able to find is the C3 designation. This is a Seeed XIAO ESP32C3 chip that we are using.

No, no pullup resistor. In by own defense I have not seen any examples that use one, but I will give that a try later today. Thanks for the suggestion.

RAilroader,

I will post them later today when I get back to my lab.

If you have the module with 4 pins then you must have a pull-up resistor, 4.7K is good.
If you have the one that is on a little PCB with only 3 pins then a pull-up is already on the PCB.

You may want to consider the BME280 sensor, it is better in high humidity environments and is generally more reliable.

We have the 3 pin module. I am including the code for this project:

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-dht22
 */

#include "DHT.h"
#define DHT22_PIN 10

DHT dht22(DHT22_PIN, DHT22);

void setup() {
  Serial.begin(9600);
  dht22.begin(); // initialize the DHT22 sensor
}

void loop() {
  // wait a few seconds between measurements.
  delay(2000);
  Serial.println("hello world");

  // read humidity
  float humi  = dht22.readHumidity();
  // read temperature as Celsius
  float tempC = dht22.readTemperature();
  // read temperature as Fahrenheit
  float tempF = dht22.readTemperature(true);

  // check if any reads failed
  if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
    Serial.println("Failed to read from DHT22 sensor!");
  } else {
    Serial.print("DHT22# Humidity: ");
    Serial.print(humi);
    Serial.print("%");

    Serial.print("  |  "); 

    Serial.print("Temperature: ");
    Serial.print(tempC);
    Serial.print("°C ~ ");
    Serial.print(tempF);
    Serial.println("°F");
  }

Simple code for testing purposes. I have used it on other projects with Arduino and Micro-Bit.
Here is a diagram of the configuration.

I think the three pin module has a built in pull up to Vcc. You are powering it with 5v and it may be putting 5v on pin 10 and may have damaged it.

Try powering the module with 3.3v and connecting the data out to a different pin incase 10 is damaged.

Cattledog,

Thanks. I tried it with 3.3V and that didn’t work either. I have tested it on every port on the board and no luck. I checked the voltage on the data pin and it reads 3.3V. I have tried two different processors and both react the same way. I saw one post that suggested using a pure power supply to power it since the computer usb may not have enough power from the bus, especially if there are multiple devices attached. So first step was to disconnect all the usb devices and try. Nothing. Connecting to a pure power source will not help since I then have no way to know what is happening since the serial monitor will not work. I could use some code to send it out on my wifi net and may try that as a last resort later today.

In Tools, do you have USB CDC On Boot: "Enabled"?

More precise;
Did you upload the code with CDC on Boot Enabled.

I learned electronic drafting in the 1950s while in high school. We did everything by hand, there was no KiCad. Schematics are the language of electronics, we used pencil and paper. We learned using switches and lamps; there were no computers available.

Hopefully the students learn the following:

  • The difference between voltage and current
  • Why resistors matter
  • Why pull-ups exist
  • Why 3.3V logic levels matter
  • Why short circuits are dangerous
  • What a microcontroller actually is

If they leave the semester understanding that a GPIO pin is not a power source, it is a controlled switch, then you have succeeded.

Update,

I wrote some code to read the voltages on all the pins. Except for pins 1,2,3,and 4 they all read 0? So something not right someplace..

These kids are lucky to take math classes. The education system today is a lot different than when you and I went to school. I took a semester of mechanical drawing with paper and pencil. I enjoyed it. Today everything has to be done with computers. I doubt there is anyone who can teach electronics at the high school level. So all I can do is hope to give them a taste of what engineering is all about and maybe one of them will decide to take some engineering/science classes in college. But I agree with you. If you don’t understand the fundamentals then you’ll never get the who picture. My field is Aeronautical Engineering and Information Technology. But I have a solid math and engineering background so circuit design isn’t that much different. I have designed several PCBs for projects I have developed.

Not really sure. I’ll have to look into it and get it enabled. In the mean time I have taken the rest of the day off, only so much head banging I can do in one day.

Useless excersize.
Digital sensors output a very short pulse train after given a pulse train command.
0volt on all pins could be normal.
Leo..

OK, checked and it is on. I have one more thing to try. I need to confirm I have the correct library loaded.