Using the HDC3021 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_HDC302x library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the sensor using the STEMMA QT connector.
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Library Installation
You can install the Adafruit_HDC302x library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_HDC302x, and select the Adafruit HDC302x library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
If the dependencies are already installed, make sure you update them through the Arduino Library Manager before loading the example!
#include <Adafruit_HDC302x.h> Adafruit_HDC302x hdc = Adafruit_HDC302x(); void setup() { Serial.begin(115200); Serial.println("Adafruit HDC302x Simple Test"); if (! hdc.begin(0x44, &Wire)) { Serial.println("Could not find sensor?"); while (1); } delay(1000); } void loop() { double temp = 0.0; double RH = 0.0; hdc.readTemperatureHumidityOnDemand(temp, RH, TRIGGERMODE_LP0); Serial.print("Temperature: "); Serial.print(temp); Serial.println(" °C"); Serial.print("Humidity: "); Serial.print(RH); Serial.println(" %"); delay(2000); }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. After the HDC3021 is recognized over I2C, you'll see the temperature and humidity readings print to the Serial Monitor every two seconds.
Page last edited January 22, 2025
Text editor powered by tinymce.