Here is another simplified project to measure the humidity and temperature. It is a cheap module around $4 and can be found easily online. So lets get started without any delay.
How does the DHT11 or Humidity Sensor Work?
The humidity sensing component of the DHT11 is a moisture holding substrate with the electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes while lower relative humidity increases the resistance between the electrodes.
How does the DHT11 work with Arduino?
The DHT11 converts the resistance measurement to relative humidity on an chip mounted to the back of the unit and transmits the humidity and temperature readings directly to the Arduino Uno from an Analog Pin.
Things Needed
- DHT11 Sensor (Humidity Sensor)
- Arduino Uno
- Jumper Cables
- Breadboard
- Arduino IDE on your computer / smartphone.
- Power Supply or 9V battery
DHT Module Pin Diagram
- Vcc pin supplies power for the sensor. Connected to 5V on the Arduino.
- Data pin is used to communicate between the Arduino and the sensor
- NC is Not Connected
- GND is the ground pin. Common grounded with the arduino.
Circuit Diagram
Connect the following circuit as shown in the diagram. Next step would be programming the arduino to read the values from the DHT sensor.
Code
Since DHT sensors have their own protocol of communication. We will use a library called DHT.
Click here to download the library : https://github.com/rolan37/DHT-11-Sensor
Use the code below and watch the serial monitor give the output…..Ahhh its hot!.(I live in Goa….)
#include <dht.h> // inlcude the library of DHT11
#define dht_apin A0 // define the analog pin that we need to connect
dht DHT; // giving out dht sensor a name
void setup() {
Serial.begin(9600); //baud rate at which we want to communicate (slower the better)
delay(500); //time to reboot the system
Serial.println("DHT11 Humidity & temperature Sensor - Test\n\n");
delay(1000); // small delay for the sensor to start functioning
}
void loop() {
//Start of Program
DHT.read11(dht_apin); //function to read the values from the pin A0
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000); //Use a delay before taking another set,(always try to use a delay greater than 2 secs)
Once you open the Serial Monitor you will see the output.
Enjoy the project. Love learning through videos? watch the below video and follow the steps. This video contains the code explanation too for the humidity sensor. Happy Learning!