Humidity + Servo + Arduino




About: I am an electronic hobbyist on Arduino, Photon, Raspberry Pi and common electronics.A passionate cook.Any assistance in electronics and web development feel free to contact me at

Hey, guys!!I'm Sridhar Janardhan back with another tutorial.In today's tutorials, i am going to teach you how to control a servo with the data thrown by the humidity sensor.

Objectives: To know how the valve of a door is opened is to water the land when the soil has less moisture content. To know about this you must be familiar with the DTH-11 sensor which is a humidity sensor for the electronics hobbyist.The DTH-11 sensor is a device designed to measure the humidity of it's surrounding. Now let's start to gather the components required for this project.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components Required:

The Components required for this projects are:

  • Arduino Uno
  • DTH-11 sensor
  • Jumper wire
  • Servo Motor
  • Breadboard

Now let's get into the interfacing part of the Arduino.

Step 2: Interfacing the DTH-11 Sensor:

As I explained in the initial part of the Ibles. DTH-11 is a humidity sensor that measures the humidity content around it's surrounding.This sensor throws a data at a regular ping.These data are used by the hobbyist to implement their action as here I have used these data to control the movement of the servo.

Key features of the DTH11 sensor:-

  • Operating Voltage: +5 Volts (Can be powered by Arduino)
  • the range of temperature: 0 t0 50 °C (error of ± 2 °C)
  • Humidity percentage: 20 to 90% RH ± 5% RH error
  • Interfacing Medium: Digital

The three pins of the DTH11 sensor are:

  • VCC pin: The power supply pin needed to operate
  • GND pin: The ground pin needed to ground the components in the circuit
  • Signal pin: The pin that sends the data to the Arduino

The connection of the sensor is as follows:

  • VCC Pin: The power supply is connected to the positive railing of the breadboard.
  • GND Pin: This pin is connected to the negative railing of the breadboard.
  • Signal Pin: This pin is connected to the Digital pin 3 of the Arduino.

Now let's start interfacing the Servo motor.

Step 3: Servo Motor Interface:

The servo motor is a specially designed motor whose speed and acceleration can be controlled in both the direction.This speed finds its application in the major physical mechanism.

The pin description of the servo motor are:

  • Red wire: The VCC pin of the servo.
  • maroon wire: The GND pin of the servo.
  • Orange wire: The Signal wire.

The Servo connection is as follows:

  • Red wire: The VCC pin is connected to the positive railing of breadboard.
  • Maroon wire: The GND pin is connected to the negative railing of the breadboard.
  • Orange wire: The signal pin is connected to the digital pin 5 of Arduino.

Step 4: Coding

#include "DHT.h"

Servo myservo; 
int pinDHT11 = 2;
 SimpleDHT11 dht11; 
void setup() { 
 Serial.begin(115200); }
 void loop() { 
Serial.println("Sample DHT11..."); 
byte temperature = 0;
 byte humidity = 0; 
if (, &temperature, &humidity, NULL)) {
 Serial.print("Read DHT11 failed."); 
 Serial.print("Sample OK: "); 
Serial.print(" *C, "); 
 Serial.println(" %"); 
if (humidity <= 50) {
for (pos = 0; pos <= 180; pos += 1) { 
 else {
for (pos = 180; pos >= 0; pos -= 1) {
Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

Be the First to Share


    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    6 Discussions


    6 weeks ago

    Please could you check the code as it appears to have many errors

    1 reply

    Reply 8 days ago

    Actually the code itself is full of errors , since the value declaration are not part of the library I will update a new clean code , that work !

    sriram yashwanth

    1 year ago

    error message be like

    Arduino: 1.8.4 (Windows 8.1), Board: "Arduino/Genuino Uno"

    C:\Users\user\Documents\Arduino\humidity_servo\humidity_servo.ino:1:17: fatal error: DHT.h: No such file or directory

    #include "DHT.h"


    compilation terminated.

    exit status 1

    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with

    "Show verbose output during compilation"

    option enabled in File -> Preferences.

    1 reply

    1 year ago

    hey! I'm new to this so i know almost nothing. i have learned a little but in school and wanted to do this for my project. i just want to ask to be sure if i dont need a resistor or anything like that?

    sriram yashwanth

    1 year ago

    There is some error in your code plz do some corrections in your code