DHT11 to motor code help

I edited a code and made it whenever it's larger than a certain degree it powers the motor with different speed. Most of the time in my house its 24 degress so it should be powering at 240, but it powers it at 255, can someone check my code and see what i did wrong? ( sorry for bad explination) Thank you so much

 #include <DHT.h>
#include <DHT_U.h>
 
#define DHTPIN A0
#define DHTTYPE DHT11
int led = 9;
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  dht.begin(); 
 
}
 
void loop() {

  delay(2000);
 
  float humi  = dht.readHumidity();
  float tempC = dht.readTemperature();
  float tempF = dht.readTemperature(true);
 
  if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
    Serial.println("Failed to read from DHT sensor!");
  } else {
    Serial.print("Humidity: ");
    Serial.print(humi);
    Serial.print("%");
 
    Serial.print("  |  ");
 
    Serial.print("Temperature: ");
    Serial.print(tempC);
    Serial.print("C ~ ");
    Serial.print(tempF);
    Serial.println("F");

    if(tempC < 18.00) { analogWrite(9, 0); }
    if(tempC > 17.00) { analogWrite(9, 180); }
    if(tempC > 18.00) { analogWrite(9, 190); }
    if(tempC > 19.00) { analogWrite(9, 200); } 
    if(tempC > 20.00) { analogWrite(9, 210); }
    if(tempC > 21.00) { analogWrite(9, 220); }
    if(tempC > 22.00) { analogWrite(9, 230); }
    if(tempC > 23.00) { analogWrite(9, 240); }
    if(tempC > 24.00) { analogWrite(9, 250); }
    if(tempC > 25.00) { analogWrite(9, 255); }
  }
}

What do you see when you print tempC ?

i figured out the problem thanks

For the benefit of future readers of this topic please explain what was wrong and if the sketch has been changed then please post it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.