DHT22 stops working after unplugging from computer

I am working on a few temperature sensors for my house. Two of the three are working just fine. But for some reason the third is giving me issues. The code for all 3 was downloaded from Sinric Pro using their zero code option. The DHT22 is connected to an ESP-12E and the sensor has a built in resistor.

After uploading the code to the board and it is powered through the USB port on my computer, everything works just fine and return the temperature and humidity. I had this running for a few days to make sure. However, when I unplug and power the board through any other power source, the DHT22 returns 0 for temperature and 1 or 2 for humidity initially and does not update anymore (it's set to update every minute).

When I plug the board back into my laptop, after trying with an external power supply, the DHT22 returns 0 degrees and 1% humidity but doesn't update. If I upload the code to the board again, everything works fine but as soon as I unplug the board and try with an external power source again, the problem returns.

I don't think it is a power supply problem. If it was a power supply problem, the device would function properly if I plugged it back into the computer. But, after removing it from the computer, plugging it into my USB adapter and then back into the computer, it doesn't work.

The power supply/USB adapter I have is 5V, 2.4A and the exact same one is powering the other two sensors just fine. I've tried switching power supplies to the other ones I have with zero success.
CNC Machining Service
I've tried different cables, different power supplies (I bought 3 of everything and the other two function perfectly fine with those plugs) and just can't figure it out. My code is below. Thank you for any insight in advance.

UPDATE: I tried 3 different DHT22s and 2 different ESP-12E boards and the result was the same.

/*

#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif

#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProTemperaturesensor.h"
#include "DHT.h" // GitHub - markruys/arduino-DHT: Efficient DHT library for Arduino · GitHub

#define WIFI_SSID "my wifi"
#define WIFI_PASS "my password"
#define APP_KEY "from sinric pro"
#define APP_SECRET "from sinric pro"
#define TEMP_SENSOR_ID "from sinric pro"
#define BAUD_RATE 115200 // Change baudrate to your need (used for serial monitor)
#define EVENT_WAIT_TIME 60000 // send event every 60 seconds

#define DHT_PIN 14

DHT dht; // DHT sensor

float temperature; // actual temperature
float humidity; // actual humidity
float lastTemperature; // last known temperature (for compare)
float lastHumidity; // last known humidity (for compare)
unsigned long lastEvent = (-EVENT_WAIT_TIME); // last time event has been sent

/* handleTemperatatureSensor()

    • Checks if Temperaturesensor is turned on
    • Checks if time since last event > EVENT_WAIT_TIME to prevent sending too much events
    • Get actual temperature and humidity and check if these values are valid
    • Compares actual temperature and humidity to last known temperature and humidity
    • Send event to SinricPro Server if temperature or humidity changed
      */
      void handleTemperaturesensor() {
      unsigned long actualMillis = millis();
      if (actualMillis - lastEvent < EVENT_WAIT_TIME) return; //only check every EVENT_WAIT_TIME milliseconds

if (SinricPro.isConnected() == false) {
Serial.printf("Not connected to Sinric Pro...!\r\n");
return;
}

// temperature = dht.getTemperature(); // get actual temperature in °C
temperature = dht.getTemperature() * 1.8f + 29.9; // get actual temperature in °F
humidity = dht.getHumidity(); // get actual humidity

if (isnan(temperature) || isnan(humidity)) { // reading failed...
Serial.printf("DHT reading failed!\r\n"); // print error message
return; // try again next time
}

if (temperature == lastTemperature || humidity == lastHumidity) return; // if no values changed do nothing...

SinricProTemperaturesensor &mySensor = SinricPro[TEMP_SENSOR_ID]; // get temperaturesensor device
bool success = mySensor.sendTemperatureEvent(temperature, humidity); // send event
if (success) { // if event was sent successfuly, print temperature and humidity to serial
Serial.printf("Temperature: %2.1f Celsius\tHumidity: %2.1f%%\r\n", temperature, humidity);
} else { // if sending event failed, print error message
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}

lastTemperature = temperature; // save actual temperature for next compare
lastHumidity = humidity; // save actual humidity for next compare
lastEvent = actualMillis; // save actual time for next compare
}

// setup function for WiFi connection
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");

#if defined(ESP8266)
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.setAutoReconnect(true);
#elif defined(ESP32)
WiFi.setSleep(false);
WiFi.setAutoReconnect(true);
#endif

WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
delay(250);
}
IPAddress localIP = WiFi.localIP();
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
}

// setup function for SinricPro
void setupSinricPro() {
// add device to SinricPro
SinricProTemperaturesensor &mySensor = SinricPro[TEMP_SENSOR_ID];

// setup SinricPro
SinricPro.onConnected({ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected({ Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}

// main setup function
void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
dht.setup(DHT_PIN);

setupWiFi();
setupSinricPro();
}

void loop() {
SinricPro.handle();
handleTemperaturesensor();
}

I moved your topic to a more appropriate forum category @picwaeim.

The Nano Family > Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, when creating a topic please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

Can You translate all the words about plugging into schematics showing the different attempts?

Also please use code tags. Don't post code in the novel text format.

A new Fahrenheit formula, where did you get that?

Hi, @picwaeim
Welcome to the forum.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

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

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

If I read your OP correctly you have 3 MCU's (ESP-12E) and 3 DHT22 running the same code. Two work a third does not.

Unless there is a rip in the fabric of reason, either the MCU, DHT22 or PSU is defective. You say you have swapped DHT22 and the problem did NOT move, and also changed the ESP-12E and the problem did not move. That only leaves the PSU.
If swapping the PSU does NOT solve the problem, then as is often the case you are not telling us something. For instance, did you do any soldering?

And please, format your code...