Is it possible to control the servo motor by the DHT11 sensor??

Hello good day! :slight_smile:
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();
  }
}

Have you tried a sketch with only the sensor, to verify that it is working properly in the first place?

Yes, I tried it. If only the dht11 is connected to arduino board, the reading is constant.. if i connect servo motor, it rises-falls-rises..it is not constant..

It's a fairly good bet that you are powering the servo from the Arduino and, because it draws too much current, it is affecting the voltage and hence the temperature readings. Servos should have their own power supply and only the ground and signal pins should be connected to the Arduino.

...R

How is the servo powered ?
Direct from the Arduino 5V and GND pins, which is the wrong way, or from an external power source with a common GND, which is the right way.

Please post a diagram of your complete circuit.

Is there a required voltage for servo motor sir? I have power supply here: 3V, 4.5V, 6V, 9V and 12V..what supply should i use?

Most servos are 4.8 to 6V, and you should allow 1A per servo current. Check the datasheet for you make and model.

The attached pic (thanks to zoomkat) shows the connections.

servo-wire.jpg

Thank you very much sir. I will try first your advice.