OC
OceanRemote
Low-code IoT platform
Back to Troubleshooting Hub

DHT22 Reading Failed

Your DHT22 sensor returns -999C error code instead of actual temperature. The Serial Monitor shows "DHT22 read failed" or "nan" values. This guide covers timing violations, pull-up resistor issues, signal integrity problems, and sensor recovery methods for ESP32, ESP8266, and Pico W.

Last updated: April 22, 2026 | 10 min read

Symptoms

  • Serial Monitor shows "[SENSOR] DHT22 read failed - sending error code -999"
  • Dashboard displays -999C for temperature
  • Readings return to normal after device reboot but fail again
  • Sensor works for a while then starts failing intermittently
  • Humidity also shows -999%
  • DHT22 works with simple sketch but fails in OceanRemote firmware
  • Error occurs more frequently when WiFi is active

Common Causes

  1. Timing Violation Most common cause. DHT22 requires minimum 2 seconds between read attempts
  2. Missing or Weak Pull-up Resistor 10k resistor required; 4.7k may work but 10k is standard
  3. Signal Interference from WiFi ESP32/ESP8266 WiFi transmission creates noise on DATA line
  4. Long DATA Wire Signal degradation causes communication failure
  5. Power Supply Noise Voltage fluctuations during WiFi transmission affect DHT22
  6. Sensor in Recovery Mode DHT22 enters recovery state after read failure; needs 2-3 seconds to recover
  7. Faulty DHT22 Sensor Sensor damaged by moisture or over-voltage

DHT22 Communication Protocol

DHT22 Read Cycle :

1. MCU pulls DATA LOW for 1-10ms (start signal)
2. MCU releases DATA  for 20-40s
3. DHT22 responds with 80s LOW then 80s HIGH 
4. DHT22 sends 40 bits:
   - Each bit starts with 50s LOW
   - Bit 0: 26-28s HIGH
   - Bit 1: 70s HIGH
5. Total read time: ~4ms
6. CRITICAL: DHT22 needs 2 seconds recovery before next read

 Reading faster than 2 seconds causes:
   - Failed reads 
   - Corrupted data
   - Sensor lockup requiring power cycle

Step-by-Step Fixes

1. Ensure 2-Second Read Interval

DHT22 requires minimum 2 seconds between reads:

//  WRONG - Reading too fast 
void loop() {
  float temp = dht.readTemperature();
  delay;  // 1 second - TOO FAST!
}

//  CORRECT - 2 seconds between reads
void loop() {
  float temp = dht.readTemperature();
  delay;  // 2 seconds minimum
}

// OceanRemote firmware uses 2-second read interval
// Check Serial Monitor: "[SENSOR] DHT22 - Temp: XX.XC"
// Should appear every 2 seconds, not more frequently

2. Add Proper Pull-up Resistor

DHT22 needs 10k pull-up between DATA and VCC:

  • Connect 10k resistor between DATA pin and VCC
  • Without pull-up, signal is weak and reads fail
  • 4.7k may work but 10k is standard and recommended
  • Place resistor as close to DHT22 as possible
  • Use 1% or 5% tolerance resistor

3. Reduce WiFi Interference

WiFi transmission creates noise on DATA line:

  • Add 100nF capacitor between DATA and GND near DHT22
  • Use shielded cable for DATA wire
  • Keep DATA wire away from power wires and antenna
  • Reduce WiFi TX power: esp_wifi_set_max_tx_power;
  • Take DHT22 reading before WiFi transmission when possible

4. Add Recovery Logic for Failed Reads

Retry failed reads with proper delay:

// OceanRemote firmware includes this recovery logic
// Custom code should implement similar retry mechanism

float readDHT22WithRetry {
  for  {
    float temp = dht.readTemperature();
    if ) {
      return temp;  // Success
    }
    delay;  // Wait 100ms before retry
  }
  return -999;  // All retries failed
}

// After failed read, DHT22 needs 2 seconds to recover
// OceanRemote firmware handles this automatically

5. Check Power Supply Stability

Voltage fluctuations during WiFi cause read failures:

  • Measure voltage at DHT22 VCC pin during WiFi transmission
  • Should stay stable within 3.0V-3.3V
  • Add 100F capacitor between VCC and GND near DHT22
  • Use separate 3.3V regulator for DHT22 if possible
  • Ensure power supply can handle ESP32/ESP8266 peaks

6. Shorten DATA Wire

Long wires degrade signal quality:

  • Keep DATA wire under 5 meters
  • For longer runs, use shielded twisted pair cable
  • Reduce wire length to 1-2 meters for testing
  • Use thicker wire for long runs
  • Avoid running DATA wire parallel to AC power lines

7. Power Cycle the DHT22

Sensor may be locked in error state:

// Power cycle procedure:
// 1. Disconnect power from DHT22 completely
// 2. Wait 5 seconds
// 3. Reconnect power
// 4. Wait 2 seconds for sensor to stabilize
// 5. Attempt reading again

// For software power cycle :
// GPIO can control DHT22 power
pinMode;
digitalWrite;  // Power OFF
delay;
digitalWrite; // Power ON
delay;  // Wait for sensor to stabilize

DHT22 Error Codes in OceanRemote

Error Code Meaning Solution
-999C () Read failed Check pull-up resistor, 2-second delay, wiring
-998C () Sensor not responding (no start signal ack) Check power, wiring, pull-up resistor
-997C () CRC checksum failed Check signal integrity, add capacitor, shorten wire
isnan() () Library returned NaN Same as -999, timing or pull-up issue

OceanRemote firmware uses -999 for all read failures.

Prevention Tips

  • Always use 10k pull-up resistor between DATA and VCC (critical!)
  • Maintain minimum 2 seconds between read attempts
  • Keep DATA wire short and away from power lines
  • Add 100nF capacitor between DATA and GND for noise filtering
  • Use stable 3.3V power for ESP32/ESP8266 compatibility
  • Add power-on delay before first DHT22 read
  • If using deep sleep, ensure 2-second gap between wake and read

Related Issues

Frequently Asked Questions

Q: Why does my DHT22 work in a simple sketch but fail in OceanRemote firmware?

A: OceanRemote firmware does other tasks that can interfere with DHT22 timing. The 2-second read interval is still respected. Try adding a 100nF capacitor between DATA and GND to filter WiFi noise.

Q: I see intermittent -999 errors. Is my sensor failing?

A: Intermittent errors are usually caused by timing violations or noise, not sensor failure. Check that reads are exactly 2 seconds apart. Add pull-up resistor if missing. Add 100nF capacitor for noise. If errors persist after these fixes, sensor may be damaged.

Q: How do I know if my DHT22 is permanently damaged?

A: Test with minimal sketch that only reads DHT22 every 2 seconds . If it still returns -999, sensor is likely damaged. Common causes: exposure to moisture, voltage above 5.5V, or physical damage.

Still having read failures? Contact Support or return to the Troubleshooting Hub.