Sub topic 3
Wiring the Sensor to the Arduino
This chapter assumes that you know the basic Arduino setup() and loop() structure, can use a breadboard, and can identify power, ground, and digital pins on an Arduino Uno. The examples use a DHT11 or DHT22 connected to an Uno.
Identify the sensor type
DHT sensors usually appear in two forms:
- A bare sensor has four pins and normally needs an external pull-up resistor.
- A breakout module has three pins, often labeled
VCC,DATA, andGND. The module usually includes the pull-up resistor.
The DHT11 is less accurate and has a smaller temperature and humidity range. The DHT22 costs more but generally provides better resolution and a wider range. The wiring method is the same, but always check the markings or datasheet because pin order can vary between packages.
Connect a bare DHT sensor
With the grille facing you and the pins pointing downward, many bare DHT sensors use this order:
VCCDATA- Not connected
GND
Do not rely on this orientation for an unknown part. Confirm the pinout before applying power.
Use this connection for an Arduino Uno:
| DHT sensor pin | Arduino connection | Purpose |
|---|---|---|
| VCC | 5V | Supplies power to the sensor |
| DATA | Digital pin 2 | Carries the sensor signal |
| GND | GND | Completes the circuit |
Add a pull-up resistor between VCC and DATA. A resistor between 4.7 kΩ and 10 kΩ is typical. The resistor holds the data line at a known high voltage when the sensor is not sending a signal.
The resistor can be placed anywhere on the breadboard as long as one end connects to VCC and the other connects to DATA. It does not go in series with the data wire.
Connect a breakout module
A three-pin module simplifies the circuit. Connect its labeled pins directly:
VCCto the Arduino5VpinDATAto Arduino digital pin 2GNDto an ArduinoGNDpin
Some modules label the signal pin S, OUT, or DATA. These labels mean the same function in this setup. Do not add a second pull-up resistor unless the module documentation says that one is required.
Check the circuit before uploading
With the Arduino disconnected from USB power, inspect the breadboard:
- The 5V and GND rails are connected to the correct Arduino pins.
- The sensor's ground wire reaches the Arduino ground.
- The data wire reaches the intended digital pin.
- The pull-up resistor joins 5V and DATA, not DATA and GND.
- No exposed jumper wires short the 5V and GND rails.
The sensor communicates digitally over one data wire. The Arduino does not measure a changing analog voltage. It and the sensor exchange precisely timed signal pulses, so a loose connection or incorrect pull-up resistor can cause failed readings even when the sensor is powered.
Exercise
You have a bare DHT22 with four pins. Which three sensor pins must be connected, and where should the pull-up resistor go?
Show answer
Connect VCC to 5V, DATA to Arduino digital pin 2, and GND to Arduino GND. Leave the unused pin disconnected. Connect the pull-up resistor between VCC and DATA.