Week 9 - Input Devices
This Week i read data from the DHT22 Temperature and Humidity sensor with the Board i designed in week 6 and produced in Week 8. I programmed the board with the Arduino IDE.
In our group assignment, We showed, how to use an oscilloscope and an logic analyzer. Due to the fact, that i was overseas for a Conference I was just Responsible for The Website. So Crossreading, the Content and also Adding it to the Site and Pushing everything to our Internal Git.
Sensor Function and Data Communication (DHT22)
The DHT22 is a digital sensor used to measure temperature and humidity. It communicates with a microcontroller using a single digital pin through a proprietary. sThe communication process is timing-based and consists of a request-response sequence between the microcontroller and the sensor.
Communication Process:
-
The microcontroller initiates communication by sending a start signal, which involves pulling the data line low for at least 1 millisecond, then releasing it.
-
The DHT22 responds with a short handshake signal, indicating it is ready to transmit data.
-
The sensor then sends a 40-bit data stream, structured as follows:
-
16 bits for relative humidity data
-
16 bits for temperature data
-
8 bits for a checksum used for data integrity verification
-
Each bit is transmitted by the sensor using pulse-width modulation:
-
A binary 0 is represented by a short HIGH signal (~26–28 microseconds)
-
A binary 1 is represented by a longer HIGH signal (~70 microseconds)
This approach allows the sensor to send digital data without requiring a clock line.
Role of the Adafruit DHT Sensor Library
The Adafruit DHT sensor library simplifies the process of interfacing with the DHT22 by managing the low-level timing and communication protocol. Specifically, the library:
-
Sends the appropriate start signal to the DHT22.
-
Measures the length of each incoming pulse to reconstruct the binary data stream.
-
Parses the 40-bit signal into humidity and temperature values.
-
Verifies the checksum to ensure data accuracy.
-
Provides user-friendly functions, such as:
-
readTemperature()
– Returns the temperature in Celsius (or Fahrenheit if configured) -
readHumidity()
– Returns the relative humidity as a percentage
-
sources
- Adafruit DHT Sensor Library (GitHub)
- Adafruit DHT22 Sensor Product Page
- DHT22 (AM2302) Datasheet (PDF)
- Adafruit Learning Guide – DHT Sensors
Prepwork
board setup
First i have to setted up the Pi Pico 2 W as Borad. For that i used the RP2040 BoardLibrary from "Earle F. Philhower, III". Step 1 was to open the preferences and add "https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json" to "Additional boards manager URLs"

Second steo was to install the Boards in the Boards Manager.

libraries
The Library used in this sketch is the "DHT sensor library" by Adafruit. U can download it through the library manager
connnecting the and sensor
To Connect our Sensor, use the second GP-Pin, which is "DHT-DATA" and the power pins on our board (marked with "DHT-VCC" and DHT-GND). Every pin used for the DHT is colored Green.


#include <DHT.h> #define DHTPIN 1 #define DHTTYPE DHT22 float temp; float humidity; DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); dht.begin(); } void loop() { temp = dht.readTemperature(); humidity = dht.readHumidity(); Serial.print("Temperatur: "); Serial.print(temp); Serial.println(" *C"); Serial.print("Luftfeuchtigkeit: "); Serial.print(humidity); Serial.println(" %"); Serial.println(); delay(2000); }
Result
