Skip to main content
Chemistry LibreTexts

15.1: DHT22 Temperature and Humidity Sensor

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)


    The DHT22 sensor consists of a capacitive humidity sensor and a thermistor with a built in Analog to Digital (A2D) converter that uses a proprietary 1-wire communication protocol to transmit the signal to a microcontroller or microcomputer. The sampling frequency is rather slow (0.5 Hz or once every 2 seconds) but it is a good first sensor.


    clipboard_ee259921f19bd418753e4cda235eb3b01.pngFigure \(\PageIndex{1}\): The DHT22 is sold as either a sensor (4 pin) or as a sensor module (3 pin) with a built in circuit board. If you buy the 4 pin module you need to place a 10 k\(\Omega\) resistor between the VCC and data pin(Belford CC-BY)



    • 3 to 5 V power 
    • 2.5 mA max current
    • 0-100% humidity range with 2-5% accuracy
    • -40 to 80 deg C temp range with \(\pm\) deg C accuracy
    • 0.5 Hz sampling frequency


    Any time you need to connect a sensor to your Raspberry Pi, you should start with searching the web for the pinout of that sensor. If you search for "DHT22 pinout" you will find many images similar to the one below.

    clipboard_ee7b11a6b9d8bcb7470b1461f276df36e.pngFigure \(\PageIndex{2}\): Fritzing diagram of DHT22 (CC0; E. Waters)
    • Pin#1 VCC (Voltage Common Collector) - power input of 3.3 or 5 V (use red wire)
    • Pin#2 Data Out pin - connecting to a GPIO pin and a pull-up resistor (use white or yellow wire)
    • Pin#3 N/C  - not connected
    • Pin#4 Ground pin (use black wire) 

    Communication Protocol

    the GPIO pin has two values, high (3.3 V) and low (0V)In a one wire protocol the length of the high voltage determines if a value is one or zero (figure \(\PageIndex{3}\). These bits combine to form bytes (8 bits) and need to transfer both humidity and temperature data.  A typical output value can be, 8bit humidity integer data + 8 bit humidity decimal data + 8 bit temperature integer data + 8 bit fractional temperature data + 8 bit parity bit (components 101).

    clipboard_ebf658697550eb2d60ecf7fcb6d35d884.pngFigure \(\PageIndex{3}\): The duration of the high voltage defines if the bit value is one or zero. these values come from Qengineering's Github, but the principle is a short high voltage is zero and a long one is 1 (Belford cc 0.0)

    So initially the GPIO pin is functioning as an output, to start the process, and then it functions as an input, and reads the data stream.  At the end the voltage returns to a high value, which is the role of the pull-up resister attached to the data pin.


    This page titled 15.1: DHT22 Temperature and Humidity Sensor is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?