We will begin by creating the circuit illustrated in Figure 9.2 on our breadboard:
The following is the breadboard layout for this circuit that we are about to build:
Here are the steps to follow, which match the numbered black circles in Figure 9.3:
- Place your DHT11 or DHT22 sensor into your breadboard.
- Place the 10kΩ resistor (R1) into the breadboard. One end of the resistor shares the same row as the DHT sensor's DATA pin. We will discuss this resistor and why it's marked as optional in Figure 9.2 after we complete the circuit build.
- Connect a 3.3-volt pin on your Raspberry Pi to the positive rail of the power rail.
- Connect the 10kΩ resistor (R1) to the positive power rail.
- Connect the DHT Vcc pin to the positive power rail.
- Connect a GND pin on your Raspberry Pi to the negative power rail.
- Connect the GND pin on the DHT sensor to the negative power rail.
- Finally, connect the DHT sensor's DATA pin to the GPIO 21 on your Raspberry Pi.
This now completes our DHT sensor circuit build.
The 10kΩ pull-up resistor is optional because the DHT software library we are using already enables Raspberry Pi's internal pull-up resistor by default. I've included the pull-up resistor in the circuit schematic because it's included in the circuit examples in many DHT11/DHT22 datasheets. If you need a refresher on pull-up resistors, please revisit Chapter 6, Electronics 101 for the Software Engineer.
Once you have created your circuit, we are ready to run and explore the code to measure temperature and humidity.