Error reading DHT11 in Dew Controller project

Hi Folks, forgive me if this has been covered, I searched but couldn't find anything on it.

I have assembled and uploaded the program to the Jaycar Dew Controller (DIY Telescope Dew Heater | Jaycar Electronics).
It would read the temperature and humidity a couple of times early on, but now gives a constant "DHT11 Fault" message.
I have tried running it from a 12V adaptor and a 12V17AH battery (fully charged) without success.
I have written a program to read the DHT11 outputs (without modifying the circuit) and interrogated it successfully using the serial monitor.
I even tried shifting the DHT11 sensor to DI-2 (and modifying the code) in case DI-3 was faulty.
If anyone can provide a suggestion it would be appreciated.

Cheers.

kmachell:
If anyone can provide a suggestion it would be appreciated.

Yes. :grinning:

Read the instructions.

Once you understand how to (point No. 7), post your code!

Here is the code…
I have taken some of the numbers from “const int temps” as it exceeds the 9000 character limit.

//pin for buttons
#define KEYPIN A0
//button constants
#define btnRIGHT 6
#define btnUP 5
#define btnDOWN 4
#define btnLEFT 3
#define btnSELECT 2
#define btnNONE (-1)
#define MOSFETPIN 11 //n-channel- PWM capable
#define THERMPIN A1  //10k thermistor and 10k resistor

#include "idDHT11.h"

int idDHT11pin = 3;       //Digital pin for comunications changed from 3 to 2
int idDHT11intNumber = 1; //interrupt number pins 2&3 use int.1 on uno
void dht11_wrapper();     // must be declared before the lib initialization
idDHT11 DHT11(idDHT11pin, idDHT11intNumber, dht11_wrapper);

void dht11_wrapper()
{
  DHT11.isrCallback();
}

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //for XC4454 LCD Shield LiquidCrystal lcd(RS, E, b4, b5, b6, b7);
//change normal backlight intensity here:
#define BACKLIGHTINTENSITY 40
#define BACKLIGHTPWMPIN 10

#include <avr/pgmspace.h>
// Big lookup Table (approx 750 entries), subtract 238 from ADC reading to start at 0*C. Entries in 10ths of degree i.e. 242 = 24.2*C Covers 0*C to 150*C For 10k resistor/10k thermistor voltage divider w/ therm on the + side.
const int temps[] PROGMEM = {0, 1... ...1480, 1502};

//for saving startup defaults to eeprom
#include <EEPROM.h>
//eeprom addresses for variables
#define OFFSETMODEADDRESS 0
#define TEMPOFFSETADDRESS 1
#define PWMOUTPUTDEFAULTADDRESS 2


byte DHTdat[5];              //data from DHT11 sensor to be stored in 0.1 humidity% 2.3 degrees C
int tempoffset = 5;          //setpoint offset above dewpoint
byte offsetmode = 'D';       //default to dew point offset
int ambtemp, ambhum, dptemp; //all measured in 1/10's
int pwmoutputdefault = 52;   //10%

void setup()
{
  Serial.begin(9600); //if needed for debugging
  lcd.begin(16, 2);
  lcd.clear();
  int value = EEPROM.read(OFFSETMODEADDRESS);
  if ((value == 'D') || (value == 'A'))
  { //valid eeprom values found
    offsetmode = value;
    tempoffset = EEPROM.read(TEMPOFFSETADDRESS);
    pwmoutputdefault = EEPROM.read(PWMOUTPUTDEFAULTADDRESS);
    lcd.setCursor(0, 0);
    lcd.print("Load EEPROM OK  ");
  }
  else
  {
    lcd.setCursor(0, 0);
    lcd.print("Invalid EEPROM  ");
  }
  DHT11.acquire(); //start 1st conversion
  delay(500);      //and wait a bit for conversion to finish
  analogWrite(BACKLIGHTPWMPIN, BACKLIGHTINTENSITY);
  }

void loop()
{
  int teletemp;       //telescope temperature
  int thermerror = 0; // flag for thermistor error
  teletemp = analogRead(THERMPIN);
  if ((teletemp == 0) | (teletemp > 950))
  {
    thermerror = thermerror | 1;
  } //thermistor error detected
  teletemp = teletemp - 238;
  if (teletemp < 0)
  {
    teletemp = 0;
  } //lookup table won't work if index<0
  teletemp = pgm_read_word(&temps[teletemp]);

  if (DHT11.getStatus() == IDDHTLIB_OK)
  {
    ambtemp = DHT11.getCelsius() * 10;
    ambhum = DHT11.getHumidity() * 10;
    dptemp = DHT11.getDewPointSlow() * 10;
  }
  else
  {
    thermerror = thermerror | 2;
  }

  int key;
  key = read_LCD_buttons();
  if (key == btnLEFT)
  {
    offsetmode = 'D';
  } //offset from dewpoint
  if (key == btnRIGHT)
  {
    offsetmode = 'A';
  } //offset from ambient
  if (key == btnUP)
  {
    tempoffset++;
    if (tempoffset > 9)
    {
      tempoffset = 9;
    }
  }
  if (key == btnDOWN)
  {
    tempoffset--;
    if (tempoffset < 0)
    {
      tempoffset = 0;
    }
  }
  if (key == btnSELECT)
  {
    savetoeeprom();
  } //save to eeprom (load happens on boot)

  int temptarget;
  if (offsetmode == 'D')
  {
    temptarget = dptemp + tempoffset * 10;
  }
  else
  {
    temptarget = ambtemp + tempoffset * 10; //default to (higher) ambient temp if anything but 'D'
  }

  int pwmoutput;
  pwmoutput = constrain(map(temptarget - teletemp, -10, 10, 0, 255), 0, 255);
  if (thermerror)
  {
    pwmoutput = pwmoutputdefault;
  }
  analogWrite(MOSFETPIN, pwmoutput);

  lcd.setCursor(0, 0);
  switch (thermerror)
  {
  case 0:
    LCDtopline();
    break;
  case 1:
    lcd.print("Thermistor fault");
    break;
  case 2:
    lcd.print("DHT11 fault     ");  
    break;
  case 3:
    lcd.print("Thrm & DHT11 flt");
    break;
  default:
    lcd.print("Thrm & DHT11 flt");
    break;
  }
  
  lcd.setCursor(0, 1);
  lcd.print("T:");
  if (teletemp > 99)
  {
    lcd.write((teletemp / 100) % 10 + '0');
  }
  else
  {
    lcd.write(' ');
  }
  lcd.write((teletemp / 10) % 10 + '0');
  lcd.print("C H:");
  pwmoutput = (pwmoutput * 39) / 100; //scale to %
  if (pwmoutput > 9)
  {
    lcd.write((pwmoutput / 10) % 10 + '0');
  }
  else
  {
    lcd.write(' ');
  }
  lcd.write((pwmoutput) % 10 + '0');
  lcd.print("% ");
  lcd.write(offsetmode);
  lcd.print("+");
  lcd.write((tempoffset) % 10 + '0');
  lcd.print("C");
  DHT11.acquire(); //start next conversion
  delay(500);
}

int read_LCD_buttons()
{
  int adc_key_in = 0;
  adc_key_in = analogRead(KEYPIN);           // read the value from the sensor
  delay(5);                                  //switch debounce delay. Increase this delay if incorrect switch selections are returned.
  int k = (analogRead(KEYPIN) - adc_key_in); //gives the button a slight range to allow for a little contact resistance noise
  if (5 < abs(k))
    return btnNONE; // double checks the keypress. If the two readings are not equal +/-k value after debounce delay, it tries again.
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000)
    return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in < 50)
    return btnRIGHT;
  if (adc_key_in < 195)
    return btnUP;
  if (adc_key_in < 380)
    return btnDOWN;
  if (adc_key_in < 555)
    return btnLEFT;
  if (adc_key_in < 790)
    return btnSELECT;
  return btnNONE; // when all others fail, return this...
}

void LCDtopline()
{
  lcd.print("A:");
  if (ambtemp > 99)
  {
    lcd.write((ambtemp / 100) % 10 + '0');
  }
  else
  {
    lcd.write(' ');
  }
  lcd.write((ambtemp / 10) % 10 + '0');
  lcd.print("C ");
  if (ambhum > 99)
  {
    lcd.write((ambhum / 100) % 10 + '0');
  }
  else
  {
    lcd.write(' ');
  }
  lcd.write((ambhum / 10) % 10 + '0');
  lcd.print("% DP ");
  if (dptemp > 99)
  {
    lcd.write((dptemp / 100) % 10 + '0');
  }
  else
  {
    lcd.write(' ');
  }
  lcd.write((dptemp / 10) % 10 + '0');
  lcd.print("C ");
}

void savetoeeprom()
{
  int htr = 0;
  int key;
  analogWrite(MOSFETPIN, 0); //shut down heater in case button is stuck
  lcd.setCursor(0, 0);
  lcd.print("Choose value for");
  lcd.setCursor(0, 1);
  lcd.print("Heater backup:");
  while (read_LCD_buttons() == btnSELECT)
  { //cycle while select held down
    htr = htr + 5;
    if (htr > 99)
    {
      htr = 0;
    }
    lcd.setCursor(14, 1);
    if (htr > 9)
    {
      lcd.write((htr / 10) % 10 + '0');
    }
    else
    {
      lcd.write(' ');
    }
    lcd.write((htr) % 10 + '0');
    delay(500);
  }
  lcd.setCursor(0, 0);
  lcd.print("Saving EEPROM...");
  EEPROM.write(OFFSETMODEADDRESS, offsetmode);
  EEPROM.write(TEMPOFFSETADDRESS, tempoffset);
  EEPROM.write(PWMOUTPUTDEFAULTADDRESS, (htr + 1) * 100 / 39);
  delay(500);
}