If statement issue? Fan on/off temp works

'#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

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

//pins
#define DHTPIN 2 // pin connected to DHT11 sensor
#define fanPin 6 //signal pin for fan power
#define fanSig 5 //fan signal from menu system
#define DHTTYPE DHT11

//variables
int fanPwr = 0;
int overTemp = 0;
float tempF;
float tempC;
float humi;

//screen/oled init
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // create SSD1306 display object connected to I2C
DHT dht(DHTPIN, DHTTYPE);

String displayString;

void setup() {
Serial.begin(9600);
pinMode(fanSig,INPUT);
pinMode(fanPin,OUTPUT);

// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}

delay(2000); // wait for initializing
oled.clearDisplay(); // clear display

oled.setTextSize(2); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(0, 10); // position to display

dht.begin(); // initialize DHT11 the temperature and humidity sensor

displayString.reserve(10); // to avoid fragmenting memory when using String
}

void loop() {
delay(350);
float humi = dht.readHumidity(); // read humidity
float tempC = dht.readTemperature(); // read temperature
float tempF = (tempC *= 9)/5 + 32; //convert temp

//temp high/low
if(tempF > 77){
overTemp = 1;
}
if(tempF < 77){
overTemp = 0;
}

//fan signal on (read signal pin for fan)
fanPwr = digitalRead(fanSig);

//fan on (signal)
if(fanPwr == 1){ // works like normal
digitalWrite(fanPin,HIGH);
}

//fan on (temp) ***// not working it says over temp is 1 but it isnt activating the fan
if(overTemp == 1){
digitalWrite(fanPin,HIGH);
}

//temp low AND fan signal off (fan off) ***// same here but it doesnt turn off
if(overTemp == 0 && fanPwr == 0){
digitalWrite(fanPin,LOW);
Serial.println("lol");
}
Serial.println(tempF);
Serial.println(overTemp);

// check if any reads failed
if (isnan(humi) || isnan(tempC)) {
displayString = "Failed";
} else {
displayString = String(tempF, 1); // one decimal places
displayString += "F ";
displayString += String(humi, 1); // one decimal places
displayString += "%";
}

//Serial.println(displayString); // print the temperature in F to Serial Monitor
oledDisplayCenter(displayString); // display temperature and humidity on OLED
}

void oledDisplayCenter(String text) {
int16_t x1;
int16_t y1;
uint16_t width;
uint16_t height;

oled.getTextBounds(text, 0, 0, &x1, &y1, &width, &height);

// display on horizontal and vertical center
oled.clearDisplay(); // clear display
oled.setCursor((SCREEN_WIDTH - width) / 2, (SCREEN_HEIGHT - height) / 2);
oled.println(text); // text to display
oled.display();
}'

See if this helps:

//temp high/low
if(tempF >= 77.0){
overTemp = 1;
}
else if(tempF <=75.0){
overTemp = 0;
}

Please edito your post to add code tags, as described in the "How to get the best out of this forum" post.

Thanks for the comment but the temp is working fine its the fan on and off not working the overTemp will turn to 1 but wont active the if statement to active my fan

Hi @matthew321654 ,
Welcome to the forum..

I put your project into a simmulator, seemed to operate fan like expected??

good luck.. ~q

Board issue okay sweet ill look into it thanks

Metered it and its reading 4.7v on the signal pin for the relay when the temp is too high but the relay doesnt turn on idk

Simulator seems to have a DHT22 threshold of 25c to turn the fan on, or a button override to turn the fan on at lower temperatures.

How do you have the SWITCHED side of the relay wired (not the Vcc/SIG/GND side)? Do you have power to COM and fan on N.O.?

What is this, relay??
pic top down,please.. is it 5vdc??

got a circuit diagram??

probably just a connection issue somewhere..

good luck.. ~q