How use HTU21DF Humidity and Temperature Sensor with Arduino (Basic Code)
HTU21DF Humidity and Temperature Sensor with Arduino (Basic Code)
This is basic code to measure temperature and himidity usiung HTUD21DF sensor. Full hardware, two types of code and demonstation is shonw in the video. The code is available below this video. To see custom code shown in video click Here.
Topics Covered in this tutorial
- 00:00 Introduction
- 01:45 Hardware explaine
- 03:45 Wiring explained 04:33 Code Explained (basic code)
- 09:04 Demonstration of basic code
- 10:04 Custom Code explained
- 13:04 Demonstration of custom code
Related HTU21DF Videos
-Custom code using HTU21DF Humidity and Temperature Sensor with Arduino-Using 2 more HTU21DF Humidity and Temperature Sensor with Arduino
-LCD1602 or LCD2004 with HTU21DF Humidity and Temperature Sensor with Arduino
-Display Temperature from HTU21D as bargraph on LCD with Arduino
Resources for this sketch
- HTU21DF Datasheet (PDF)
- Adafruit HTU21DF Library (getHub)
- Adafruit HTU21DF Library (Robojax.com)
- Difference between HTU21DF and HTU21D
/***************************************************
This is an example for the HTU21D-F Humidity & Temp Sensor
Designed specifically to work with the HTU21D-F sensor from Adafruit
----> https://www.adafruit.com/products/1899
These displays use I2C to communicate, 2 pins are required to
interface
****************************************************/
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
// Connect Vin to 3-5VDC
// Connect GND to ground
// Connect SCL to I2C clock pin (A5 on UNO)
// Connect SDA to I2C data pin (A4 on UNO)
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
void setup() {
Serial.begin(9600);
Serial.println("HTU21D-F test");
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
}
void loop() {
float temp = htu.readTemperature();
float rel_hum = htu.readHumidity();
Serial.print("Temp: "); Serial.print(temp); Serial.print(" C");
Serial.print(" ");
Serial.print("Humidity: "); Serial.print(rel_hum); Serial.println(" \%");
delay(500);
}