OLED display problems using the "if" statement

I'm a newb and am having issues with an "if" statement.

I believe I have the programming correct. When I upload the sketch to the OLED it hangs up on the first IF statement and will not move on. If I take the IF questions out of the upload everything else displays properly. I do not have the WIF or FP sensors hooked up to the Uno, so there is no input, but that shouldn't matter, right?

I have read a the post that says- "Fill the data buffer with 0's prior to the read, or set the data[readlength] = 0; after the read." But, I have no idea what that means or how to do that.

Will one of you kind people please look at my sketch to make sure it is correct and tell me what I can do to fix the display issue.

Thanks,
Craig

#include "DHT.h"
#include <Adafruit_CharacterOLED.h>
Adafruit_CharacterOLED lcd(OLED_V2, 6, 7, 8, 9, 10, 11, 12);

const int WIFsensor = A4; // pin that the sensor is attached to
const int WIFledPin = 2; // pin that the LED is attached to
const int WIFthreshold = 1; // an arbitrary threshold level that's in the range of the analog input

const int FPsensor = A1; // pin that the sensor is attached to
const int FPledPin = 1; // pin that the LED is attached to
const int FPthreshold = 500; // an arbitrary threshold level that's in the range of the analog input

#define DHTPIN A3
#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
pinMode(WIFledPin, OUTPUT);
pinMode(FPledPin, OUTPUT);

lcd.begin(16, 2);

dht.begin();
}

void loop() {

int h = dht.readHumidity();
// Read temperature as Celsius (the default)
int t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
int f = dht.readTemperature(true);

if (isnan(h) || isnan(t) || isnan(f)) {
return;
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

//-----------------------------------------------------WIF
lcd.setCursor(0, 0);
lcd.print("H20 In Fuel? ");

// read the value of the WIF Sensor:
int WIFsensorValue = analogRead(WIFsensor);
//
// if the analog value is high enough, turn on the LED:

if (WIFsensorValue > WIFsensor) {
digitalWrite(WIFledPin, HIGH);
lcd.print ("YES");
} else {
digitalWrite(WIFledPin, LOW);
lcd.print ("NO");

delay(5000);
lcd.clear();
//-----------------------------------------------------Fuel Pressure
// read the value of the fuel pressure Sensor:
int FPsensorValue = analogRead(FPsensor);

if the analog value is high enough, turn on the LED:
if (FPsensorValue > FPsensor) {
digitalWrite(FPledPin, HIGH);
lcd.print ("YES");
} else {
digitalWrite(FPledPin, LOW);
lcd.print ("NO");

//----------------------------------------------------------------LCD print Humidity
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %\t");

//-----------------------------------------------------------------LCD print temperature
lcd.setCursor(0, 1);
lcd.print("Cab Temp: ");
lcd.print(f);
lcd.print(" F");
delay(5000);
lcd.clear();
//-----------------------------------------------------------------LCD print heat index
lcd.setCursor(0, 0);
lcd.print("Heat index:");
lcd.print(hif, 0);
lcd.print(" F");

//-----------------------------------------------------------------LCD print fuel pressure
lcd.setCursor(0, 1);
lcd.print("Fuel PSI:");
// lcd.print(hif,0);
delay(5000);
lcd.clear();
}

Air_Temp.ino.ino (3.03 KB)

Thanks for the quick reply.

I made the following changes for the DHT-

if ( !( h == h ) || !( t == t ) || !( f == f )) {
lcd.print( "input error" );
return;

But, the same thing is still happening.

Do you have any other ideas that might help?

I tried taking out the code all together and I kept getting error messages during compile that there was no "F" declared...or something like that so I put it back it.

Should I just re-write the DHT code without checking for the status of the sensors inside the DHT? I used that code because I knew that it worked by itself.

This is the 3rd time I have sketched something and I can't get anything to work like it should...frustrating.

I tried taking out the code all together

What code?

and I kept getting error messages during compile that there was no "F" declared...or something like that

Nonsense. The compiler told you EXACTLY what was wrong, on exactly while line, at exactly which position. It did NOT say:

AirTemp.ino.cpp: somewhere around line 43: column 14 (or thereabouts): F not declared in this scope, or something like that

Can you even compile the code? Forget uploading it, just get it to compile?

I tried and get several errors some end braces are missing from if's

no comment for the line

"if the analog value is high enough, turn on the LED:"

Once fixed i can get it to compile.