Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO with Adafruit HTU21D-F Sensor for Temperature and Humidity Monitoring

View and Edit Project In Cirkit DesignerImage of Arduino UNO with Adafruit HTU21D-F Sensor for Temperature and Humidity Monitoring

Circuit Documentation

Summary

This document provides a detailed overview of a simple circuit designed to interface an Arduino UNO with an Adafruit HTU21D-F Temperature & Humidity Sensor. The Arduino UNO acts as the central processing unit, reading temperature and humidity data from the HTU21D-F sensor and outputting the information to the Serial Monitor. The sensor communicates with the Arduino over the I2C protocol, utilizing the SCL and SDA lines for clock and data transmission, respectively.

Component List

Arduino UNO

Adafruit HTU21D-F Temperature & Humidity Sensor

Wiring Details

Arduino UNO

Adafruit HTU21D-F Temperature & Humidity Sensor

Documented Code

/* 
  This Arduino sketch interfaces with the Adafruit HTU21D-F Temperature & Humidity Sensor.
  It reads temperature in Celsius and relative humidity in percentage, then outputs the
  values to the Serial Monitor every 500 milliseconds.
*/

#include <Wire.h>
#include "Adafruit_HTU21DF.h"

// Create an instance of the Adafruit_HTU21DF class
Adafruit_HTU21DF htu = Adafruit_HTU21DF();

void setup() {
  // Start the serial communication
  Serial.begin(9600);

  // Initialize the HTU21D-F sensor
  if (!htu.begin()) {
    Serial.println("Couldn't find sensor!");
    while (1); // Hang if sensor is not detected
  }
}

void loop() {
  // Read temperature (Celsius) from the sensor
  float temp = htu.readTemperature();
  // Read relative humidity (%) from the sensor
  float rel_hum = htu.readHumidity();

  // Print the temperature and humidity to the Serial Monitor
  Serial.print("Temp: "); Serial.print(temp); Serial.print(" C");
  Serial.print("\t\t");
  Serial.print("Humidity: "); Serial.print(rel_hum); Serial.println(" %");

  // Wait for 500 milliseconds before reading again
  delay(500);
}

This code is designed to run on the Arduino UNO and interfaces with the Adafruit HTU21D-F sensor to read temperature and humidity data. The data is then printed to the Serial Monitor in a human-readable format. The sensor is initialized in the setup() function, and readings are taken and printed in the loop() function every 500 milliseconds.