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:

  1. The microcontroller initiates communication by sending a start signal, which involves pulling the data line low for at least 1 millisecond, then releasing it.

  2. The DHT22 responds with a short handshake signal, indicating it is ready to transmit data.

  3. 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:

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:

sources

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"

404

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

404

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.

404 404
                #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

404