Humidity + Servo + Arduino

9,745

36

10

Introduction: 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 appytechie.at@gmail.com.

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.

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"

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

Participated in the
Makerspace Contest 2017

Be the First to Share

    Recommendations

    • Make it Real Student Design Challenge #3

      Make it Real Student Design Challenge #3
    • Toys & Games Contest

      Toys & Games Contest
    • Box Challenge

      Box Challenge

    10 Comments

    1
    outsolutions
    outsolutions

    1 year ago

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

    0
    Badr-eddineT
    Badr-eddineT

    Reply 1 year 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 !

    0
    TheNewNerd
    TheNewNerd

    Reply 4 months ago

    could you send me the code to pls

    0
    saurus2
    saurus2

    Reply 6 months ago

    Could you send me the code please?

    0
    TheNewNerd
    TheNewNerd

    Question 4 months ago on Step 4

    hi! sorry to disturb but at the second #include there is no file comming after so the compiler gives me this error:

    Arduino: 1.8.12 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

    humidity_sensor:3:10: error: #include expects "FILENAME" or <FILENAME>

    #include

    ^

    exit status 1
    #include expects "FILENAME" or <FILENAME>

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    0
    nlinhtoon
    nlinhtoon

    1 year ago on Step 4

    I have error when comply " SimpleDHT11" does not name a type " please help.

    0
    sriram yashwanth
    sriram yashwanth

    3 years 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.

    3
    purushottamd3
    purushottamd3

    Reply 2 years ago

    separately download the library of DHT.h

    0
    hsuu
    hsuu

    2 years 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?

    0
    sriram yashwanth
    sriram yashwanth

    3 years ago

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