Hello good day! ![]()
Im working on a project in which the DHT11 sensor will control the servo motor. If the temperature is greater than or equal to 35, the servo motor moves to 180degrees. If temperature is less than or equal to 34, the servo motor moves to 90degrees. I have sample code but the output seems not right. The reading of the dht11 is not constant, I mean, if the first reading of temperature is 30, the second reading rises to 45degrees celcius and falls again ,so on and so forth. So my question is, is it possible to control the servo motor by a DHT11 sensor??
Here's my sketch:
#include <Servo.h>
#include <DHT11.h>
//#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = 4;
int serv =7;
DHT11 dht11(sensorPin);
Servo myservo;
void setup() {
    Serial.begin(9600);
    myservo.attach(serv);
}
void loop() {
 delay(3000);
 int err;
 float temp, humi;
 if((err=dht11.read(humi, temp))==0)
 {
   Serial.print("Temp: ");
   Serial.print(temp);
   Serial.print("RH: ");
   Serial.print(humi);
   Serial.println();
if (temp >35) {
        myservo.write(180);
} if(temp <=34)
    {
        myservo.write(90);
}
 }
 else
 {
  Serial.print("Error");
  Serial.println();
 }
}
