Trying out the DHT11 Wheater Sensor using the ESP32 and Arduino IDE

Hello, again!

So last time, I wrote about trying out the Touch Sensor feature on an ESP32 Development Kit using the Arduino IDE. Today I am trying out the weather sensor feature that is provided by the DHT11. The DHT11 and also DHT22 sensors are used to measure temperature and relative humidity. 


Now let's get started!

Step 1: Hardware Requirement


Credits: https://randomnerdtutorials.com/

Everything you will need is:
  • 1 Laptop/PC
  • 1 ESP32 Development Board
  • 3 Male-Female Jumper Wire
  • 1 Male-Male Jumper Wire
  • 1 Resistor
  • 1 Bread Board
  • 1 MicroUSB cable
  • DHT11 or DHT22 sensor

Step 2: Software Requirement

Basically, every software requirement needed is just the same as in the "Blinking program" I wrote before. If you haven't checked it out, you can click here and look for Step 2: Software Requirement then come back and continue down below:


Step 3: Installing Libraries

To read from the DHT sensor, we’ll use the DHT library from Adafruit. To use this library you also need to install the Adafruit Unified Sensor library. To do so open your Arduino IDE and go to Sketch Include Library > Manage Libraries. The Library Manager will open.



Search for “DHT” on the Search box and install the DHT library from Adafruit.


Step 4: Circuit

Using the equipment you have prepared before, remake this circuit below. Notice that I am not using pin number 3 on the sensor.

Here you can see me using pin number 17 on the ESP32 using the green jumper to connect the board to pin number 2 on the sensor along with the resistor.


Notice below that Sensor pin 1 is connected to the outer Bread Board line using the yellow wire, where it meets the lower end of the resistor together with the red wire connected to the 3V3 pin on the ESP32.


Lastly, the second red wire connects GND on the Board to Sensor pin 4.
Step 5: Code


Now, after installing the necessary libraries, you can open an example code from the library by going to File > Examples > DHT Sensor library > DHTtester.
The following code should load. It reads temperature and humidity and displays the results in the Serial Monitor.




Note: Make sure to define the correct pin and DHTType you're using in your code.
Step 6: Compile, Upload & Observe


Finally, you're ready to compile and upload your code to your DevBoard. Open the Serial Monitor from Tools to observe measurements recorded by your sensor.




Above you can see the recordings I got. Make sure that the reading speed on your serial monitor is the same number as in your code. The number in the delay() function is the duration between every measurement will appear on your monitor.

Comments

Popular posts from this blog

Inserting Data from an ESP32 to a MySQL database using PHP and Arduino IDE

Receiving Data on ESP32 from a HTML form of its Web Server using Arduino IDE

Plotting Real Time Sensor Readings on Web Servers using ESP32 and Arduino IDE