DHT sensor not reading values on custom PCB

I have a PCB with a custom ESP32 on it. It is using the ESP32 WROOM 32 Chip. I connected 4 header pins for a DHT22 sensor. The data pin selected was IO14 and it was pulled up to 3.3V using a 10k ohm resistor.
I have the DHT22 sensor module that already has a 10k ohm resistor and a decoupling capacitor. I've tried connecting it to the header pins and even removed the 10k ohm resistor on the PCB. I'm still not getting any readings. The sensor is working though. I've tested it on another board. What could be the issue? My Arduino IDE code also references pin 14 for the data pin of the sensor.


the code i'm using is below:


#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_INA219.h>
#include <DHT.h>
#include <ThingSpeak.h>
Adafruit_INA219 ina219;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

#define DHTPIN 14     // Digital pin connected to the DHT sensor
#define DHTTYPE    DHT22     // DHT 22

DHT dht(DHTPIN, DHTTYPE);

//declaring variables
float t = 0;
float h = 0;
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float power_mW = 0;

//connecting to Thingspeak using WiFi
const char* ssid = "YWCA311";   
const char* pass = "Ywca311#";  
// const char* server = "api.thingspeak.com";

WiFiClient client;

unsigned long myChannelNumber = 1;
const char* myWriteAPIKey = "447LYEUNI1P4M6FR";

// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;

void setup() {
  Serial.begin(115200);

  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
   // Connect or reconnect to WiFi
  if(WiFi.status() != WL_CONNECTED){
      Serial.print("Attempting to connect");
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, pass); 
        delay(5000);     
      } 
      Serial.println("\nConnected.");
  }

  ThingSpeak.begin(client);  // Initialize ThingSpeak

  //initialise DHT sensor
  dht.begin();
  // initialise ina219 with default measurement range of 32V, 10A
  ina219.begin();

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  
  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);
}

void loop() {
  delay(4000);

  //read temperature and humidity
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  }

  if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) { delay(10); }
  }
  // read data from ina219
  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();

  // show data on OLED

  //clear display
  display.clearDisplay();

  // display temperature & humidity
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Temperature: ");
  display.setTextSize(2);
  display.setCursor(0,10);
  display.print(t);
  display.print(" ");
  display.setTextSize(2);
  display.cp437(true);
  display.write(248);
  display.setTextSize(2);
  display.print("C");
  display.setTextSize(1);
  display.setCursor(0, 30);
  display.print("Humidity: ");
  display.setTextSize(2);
  display.setCursor(0, 40);
  display.print(h);
  display.print(" %"); 
  display.display(); 
 

  delay(4000);
  display.clearDisplay();

  // display INA219 voltage values
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Bus Voltage: ");
  display.setTextSize(2);
  display.setCursor(0, 10);
  display.print(busvoltage);
  display.print(" V");
  display.setTextSize(1);
  display.setCursor(0, 30);
  display.print("Shunt Voltage: ");
  display.setTextSize(2);
  display.setCursor(0, 40);
  display.print(shuntvoltage);
  display.print(" mV");
  display.display(); 
 

  delay(5000);
  display.clearDisplay();
  // display INA219 current and power values
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Current: ");
  display.setTextSize(2);
  display.setCursor(0, 10);
  display.print(current_mA);
  display.print(" mA");
  display.setTextSize(1);
  display.setCursor(0, 30);
  display.print("Power: ");
  display.setTextSize(2);
  display.setCursor(0, 40);
  display.print(power_mW);
  display.print(" mW");
  display.display();
  delay(2000);


  //set Thingspeak fields with values
  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2, h);
  ThingSpeak.setField(3, busvoltage);
  ThingSpeak.setField(4, shuntvoltage);
  ThingSpeak.setField(5, current_mA);
  ThingSpeak.setField(6, power_mW);

  // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
  // pieces of information in a channel.  Here, we write to field 1.
  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

  if(x == 200){
    Serial.println("Channel update successful.");
  }
  else{
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }
    lastTime = millis();
  
}

type or paste code here

  1. try changing R5 to 1K
  2. try changing the sensor to IO13

You mean with same wires and same DHT library/code?

How are you trying to get readings?
Have you loaded a simple code that just counts to prove you are programming the ESP32?

Please post images of your PCB pattern.
The CAD that you made the PCB from it should be able to EXPORT a jpg or png image.

Can you post some images of you project so we can see your component layout?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

same code but on a different board. An ESP32 Development Board


I used EasyEDA Software to make the PCB.

Everything else is working. I am able to get data from the INA219 current sensor on the board. The OLED Display is also displaying the current sensor values but not getting any readings from the DHT sensor

Unfortunately, I may need to make another PCB for this.
But based on your suggestion, why do you think pin 14 is not working and why would the 1k resistor work better?

Long wiring?
Measured supply voltage?

Hi, @sherrywere

Thanks for the image of the PCB, can you post the other side?

Have you used a DMM and verified that you have 3V3 at the headers?

Have you checked that the SMPS adjacent to the DHT are not causing interference?

Thanks... Tom.... :smiley: :+1: :coffee: :australia:

This one is just guessing. Randon Nerd Tutorial tells pin 14 sends PWM signal at boot.

This sensor can work from 3 to 5V. "DHT22" can have different sensors. Datasheet for AM2302 says the pullup is 5.1K for single-bus comms. RHT03 sensor requires 1K pullup.

Are you sure GND pin is correct in your PCB?

image

1 Like

Hi, @sherrywere

Tom.... :smiley: :+1: :coffee: :australia:

there is a 4th pin with no connection for the sensor. I am aware of the location of the ground

True, but the 4th pin with no connection is actually the third pin, not the last.

1 Like

I had made a confusion between the sensor module and the sensor itself. In my case, I only have the sensor module with 3 pins, so I have placed the pins accordingly.

This is the back side

Ok. But in this case, the module is supposed to already have a pullup resistor. So you don't need one at the PCB (--> remove R5).

Tom.... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.