# DHT11 to motor code help

**URL:** <https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043>\
**Category:** Sensors\
**Created:** [January 6, 2023, 2:18pm UTC](https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043 "2023-01-06T14:18:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timlo151214](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@timlo151214](https://forum.arduino.cc/u/timlo151214)\
**Post date:** [January 6, 2023, 2:18pm UTC](https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043/1 "2023-01-06T14:18:01Z")

</div>

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

```cpp
 #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); }
  }
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 6, 2023, 2:34pm UTC](https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043/2 "2023-01-06T14:34:19Z")

</div>

What do you see when you print tempC ?

---

<div class="post-metadata">

**Author:** ![timlo151214](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@timlo151214](https://forum.arduino.cc/u/timlo151214)\
**Post date:** [January 6, 2023, 2:57pm UTC](https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043/4 "2023-01-06T14:57:20Z")

</div>

i figured out the problem thanks

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 6, 2023, 4:44pm UTC](https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043/5 "2023-01-06T16:44:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 5, 2023, 4:44pm UTC](https://forum.arduino.cc/t/dht11-to-motor-code-help/1074043/6 "2023-07-05T16:44:58Z")

</div>

Closed on July 5, 2023, 4:44pm UTC

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