Sample Format
Sample Format
Sample Format
DHT11 is a Humidity and Temperature Sensor, which generates calibrated digital output. DHT11 can be
interface with any microcontroller like Arduino, Raspberry Pi, etc. and get instantaneous results. DHT11
is a low cost humidity and temperature sensor which provides high reliability and long term stability.
In this project, we will build a small circuit to interface Arduino with DHT11 Temperature and Humidity
Sensor. One of the main applications of connecting DTH11 sensor with Arduino is weather monitoring.
We have already seen about humidity, relative humidity, humidity sensors and their types in this article.
Table of Contents
1. Circuit Diagram
2. Components Required
3. Circuit Description
4. Component Description
5. DHT11 Temperature and Humidity Sensor
5.1. Example
5.2. Working of the Project
5.2. CODE
6. Applications
7. Construction and Output Video
Circuit Diagram
The following circuit diagram shows all the necessary connections required to implement this project.
Components Required
Arduino UNO
DHT11 Temperature and Humidity Sensor
Breadboard (or perfboard)
Power supply
16 x 2 LCD Display
10K Ohm Potentiometer
5K Ohm Resistor (1/4 W)
Connecting wires
Circuit Description
We will see the circuit design of DHT11 interfacing with Arduino. The DHT11 Humidity and Temperature
sensor comes in two variants: just the sensor or a module.
The main difference is that the module consists of the pull – up resistor and may also include a power on
LED. We have used a module in this project and if you wish to use the sensor itself, you need to connect
a 5K Ω pull – up resistor additionally.
Coming to the design, the data pin of the DHT11 Sensor is connected to the Pin 11 of Arduino. A 16 x 2
LCD display is used to display the results. The control pins of LCD i.e. RS and E (Pins 4 and 6 on LCD) are
connected to pins 4 and 5 of Arduino. The data pins of LCD i.e. D4 to D7 (pins 11 to 14 on LCD) are
connected to pins 0 to 3 on LCD.
NOTE: For ease of connection, we have connected the DHT11 Sensor Module at the ICSP pins of the
Arduino as it provides adjacent VCC, DATA and GND pins. This type of connection is not necessary and
you can connect the data pin of sensor to normal Digital I/O pins.
Component Description
This digital signal can be read by any microcontroller or microprocessor for further analysis.
DHT11 Humidity Sensor consists of 4 pins: VCC, Data Out, Not Connected (NC) and GND. The range of
voltage for VCC pin is 3.5V to 5.5V. A 5V supply would do fine. The data from the Data Out pin is a serial
digital data.
The following image shows a typical application circuit for DHT11 Humidity and Temperature Sensor.
DHT11 Sensor can measure a humidity value in the range of 20 – 90% of Relative Humidity (RH) and a
temperature in the range of 0 – 500C. The sampling period of the sensor is 1 second i.e.
All the DHT11 Sensors are accurately calibrated in the laboratory and the results are stored in the
memory. A single wire communication can be established between any microcontroller like Arduino and
the DHT11 Sensor.
Also, the length of the cable can be as long as 20 meters. The data from the sensor consists of integral
and decimal parts for both Relative Humidity (RH) and temperature.
The data from the DHT11 sensor consists of 40 – bits and the format is as follows:
8 – Bit data for integral RH value, 8 – Bit data for decimal RH value, 8 – Bit data for integral Temperature
value, 8 – Bit data for integral Temperature value and 8 – Bit data for checksum.
Example
This data can be separated based on the above mentioned structure as follows
In order to check whether the received data is correct or not, we need to perform a small calculation.
Add all the integral and decimals values of RH and Temperature and check whether the sum is equal to
the checksum value i.e. the last 8 – bit data.
This value is same as checksum and hence the received data is valid. Now to get the RH and
Temperature values, just convert the binary data to decimal data.
After making the connections, we need not do anything as the program will take care of everything.
Although there is a special library for the DHT11 module called “DHT”, we didn’t use it. If you want to
use this library, you need to download this library separately and add it to the existing libraries of
Arduino.
The program written is based on the data timing diagrams provided in the datasheet. The program will
make the Arduino to automatically read the data from the sensor and display it as Humidity and
Temperature on the LCD Display.
CODE
#include <LiquidCrystal.h>
byte degree_symbol[8] =
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
int gate=11;
volatile unsigned long duration=0;
unsigned answer=0;
int z=0;
int b=1;
void setup()
lcd.begin(16, 2);
lcd.print("Temp = ");
lcd.setCursor(0,1);
lcd.print("Humidity = ");
lcd.createChar(1, degree_symbol);
lcd.setCursor(9,0);
lcd.write(1);
lcd.print("C");
lcd.setCursor(13,1);
lcd.print("%");
void loop()
{
delay(1000);
while(1)
delay(1000);
pinMode(gate,OUTPUT);
digitalWrite(gate,LOW);
delay(20);
digitalWrite(gate,HIGH);
// delayMicroseconds(40);
duration=pulseIn(gate, LOW);
while(1)
duration=pulseIn(gate, HIGH);
value=0;}
value=1;}
else if(z==40){
break;}
i[z/8]|=value<<(7- (z%8));
j[z]=value;
z++;
answer=i[0]+i[1]+i[2]+i[3];
lcd.setCursor(7,0);
lcd.print(i[2]);
lcd.setCursor(11,1);
lcd.print(i[0]);
z=0;
i[0]=i[1]=i[2]=i[3]=i[4]=0;
Applications
DHT11 Relative Humidity and Temperature Sensor can be used in many applications like:
Weather Stations
Recommended read:
Arduino is a microcontroller based prototyping board that runs on small DC power. A Relay is a device
that helps microcontrollers (or microcontroller based boards) like Arduino to switch on or off different
household appliances like motors, lights, water heaters, television and fans etc.
Today, Arduino is being used for a wide range of applications like controlling LEDs, monitoring
temperature, logging data and turning on motors etc. Another important task that can be accomplished
by the Arduino is controlling a 5V Relay to operate high voltage AC appliances and devices.
Arduino family of microcontrollers, like UNO, Nano and Mega etc. can be programmed to control a
simple 5V relay i.e. switch it on or off on the event of pushing a button, reading the value of
temperature from a thermistor or just by setting up a predefined timer.
In this project, we will see a simple circuit where an Arduino UNO will control a 5V relay, which in turn
will a lamp.
Note: We have used Arduino UNO in this project as it is more popular than other Arduino boards and
beginners in electronics can easily use it. If you have any other board like Arduino Nano or Arduino
Mega, you can use it without any hassle.
Caution: We are going to connect 240V Mains supply (or 110V depending on where you live) to the 5V
relay module to turn on a lamp. You should be very careful and cautious when using mains supply. If you
have even the smallest doubt about wiring it up, don’t hesitate to take help from a professional.
Table of Contents
1. Circuit Diagram
2. Required Components
3. Circuit Description
4. Component Description
4.1. Relay
5. Working of the Project
6. Advantages and Disadvantages
7. Applications
8. Construction and Output Video
Circuit Diagram
Let us see the circuit diagram for the project. Even though we have used a 5V Relay Module, the
connections in this circuit diagram will be describe the complete setup.
Required Components
Circuit Description
Let us now see how the circuit is designed. First thing is we used a 5V relay in this project. This makes it
easy as Arduino can power up the relay directly. If you used a 12V relay like we used in this project
Arduino Relay Control, you need to use a separate power supply for relay.
Coming to the design of the circuit, it is very simple as we used a 5V relay module and not the individual
components. Although the circuit diagram explains the detailed connections, practically we didn’t need
to make all the connections.
Most relay modules (whether 5V or 12V) will come with the aforementioned connection and hence all
you need is to give power supply to the relay module i.e. 5V and GND and connect the control signal
from Arduino to control pin on the relay board.
Coming to the load part i.e. the lamp, hot wire from the mains supply is connected to one terminal of
the lamp. Other terminal of the lamp is connected to Normally Open (NO) contact of the 5V Relay.
Finally, the neutral wire from the mains is connected to the Common (COMM) contact of the relay.
A small light sensor in the form of LDR (Light Dependent Resistor) is used to switch on or off the light
automatically. The output of the LDR sensor is given to the Analog Input pin A0.
Component Description
Relay
The advantage of using a 5V relay in this project is that the power supply for the relay can be directly
given from the Arduino UNO board itself. Let us now see some basics of a relay. A relay is a type of a
switch that acts as an interface between microcontrollers and AC Loads.
A simple Single Pole – Single Throw (SPST) relay, like the one used in this project consists of 5 Terminals:
5V, GND, Normally Open (NO), Normally Close (NC) and Common (COMM). Since we need to control this
relay with the help of Arduino, a transistor is used with an additional pin called Control Pin on the Relay
Module.
Working of the Project
A simple project, in which Arduino UNO controls a 5V relay is explained here. The working of the project
is based on the functioning of the Relay and the ability of Arduino to control the relay. Let us discuss the
working of the project.
As mentioned earlier, by interfacing Arduino with 5V relay module, we intend to operate an AC load like
lamp. Instead of using it directly, we designed a small application where an LDR is used to detect the
light intensity and automatically turn on or off the relay.
Under normal lighting conditions, the output from the LDR will be in the range of 80 – 90 (range is 0 –
255). When the lighting conditions go dark (can be done by covering the LDR with hand), the output
from the LDR will jump to 130 – 140. This condition can be used to trigger the 5V Relay and turn on the
light.
Advantages: The main and important advantage of connecting a 5V relay with Arduino is that it can be
powered by Arduino itself.
Disadvantages: A transistor based relay might not be ideal for long time use as there will always be noise
in the relay coil. A suitable option will be using additional isolation like an opto-isolator or completely
eliminating the electromechanical relay and replacing it with solid state relay.
Applications
Interfacing a 5V Relay with Arduino opens up the door to a huge number of applications. Although the
main task of the relay is to control a load, how that relay is being operated by the Arduino makes it an
interesting project.
Some of the techniques and methods using which we can control the relay are: Bluetooth, Infrared (IR)
remote, RF Transmitter – Receiver Pair or even using Internet.
Arduino based Home Automation requires the combination of Arduino and many relay module
(depending on the number of loads).
Construction and Output Video
Recommended read: