portfolio

Wiring a DHT22 (4 Pin)

Course Content
Session 1: Introduction to ESP32
Objective: Get familiar with the ESP32 microcontroller and set up the development environment.
0/5
Session 2: Interfacing with Sensors and Displays
Learn how to connect a DHT22 sensor and an OLED display to the ESP32.
0/4
Session 4: Programming the OLED Display
Objective: Write code to display information on the OLED display.
0/4
Session 5: Integrating Sensor Data with OLED Display
Objective: Combine sensor readings with OLED display functionality.
0/1
Session 6: Setup WIFI Capability
0/1
Session 7: Adding a Webserver
0/1
Session 8: Wrap-up
0/1
ESP32 Basics
About Lesson

Wiring a 4-pin DHT22 sensor to an ESP32 is straightforward, similar to the 3-pin version, with the addition of an unused pin and the need for an external pull-up resistor. Here’s a guide on how to wire the 4-pin DHT22 to the ESP32:

Pin Layout of the DHT22 (4-pin):

  1. Pin 1: VCC – Power supply (3.3V or 5V)
  2. Pin 2: DATA – Data signal (to ESP32 GPIO pin)
  3. Pin 3: NC (Not Connected) – Not used
  4. Pin 4: GND – Ground (connected to the common ground)

Components Needed:

  • DHT22 (4-pin) sensor
  • ESP32 microcontroller
  • Jumper wires
  • 4.7kΩ to 10kΩ pull-up resistor (required between VCC and the DATA pin)

Wiring the DHT22 to ESP32:

  1. Pin 1 (VCC) → Power:

    • Connect Pin 1 of the DHT22 to the 3.3V pin of the ESP32 (or 5V, depending on the sensor specification, but ESP32 operates at 3.3V logic).
  2. Pin 2 (DATA) → ESP32 GPIO Pin:

    • Connect Pin 2 (DATA) of the DHT22 to any available GPIO pin on the ESP32 (e.g., GPIO 4).
    • Add a 4.7kΩ to 10kΩ pull-up resistor between Pin 1 (VCC) and Pin 2 (DATA) for stable data transmission.
  3. Pin 3 (NC) → Leave Unconnected:

    • Pin 3 is not connected to anything, so leave it unconnected.
  4. Pin 4 (GND) → Ground:

    • Connect Pin 4 of the DHT22 to one of the GND pins on the ESP32.

Example ESP32 Wiring:

  • DHT22 Pin 1 (VCC) → ESP32 3.3V or 5V
  • DHT22 Pin 2 (DATA) → ESP32 GPIO 4 (or any other GPIO pin)
  • DHT22 Pin 3 (NC) → Leave unconnected
  • DHT22 Pin 4 (GND) → ESP32 GND

Notes:

  • Ensure that you use a stable 3.3V or 5V power source, depending on the sensor’s requirements.
  • The 4.7kΩ to 10kΩ pull-up resistor is required for stable communication on the DATA pin with the 4-pin DHT22 version.
  • You can change the GPIO pin in the code to match your wiring setup.

With this setup, the ESP32 will be able to read the temperature and humidity data from the DHT22 sensor and display it in the Serial Monitor.