Arduino UNO with HTU21D-F Sensor for Temperature and Humidity Monitoring
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit that integrates an Arduino UNO microcontroller with an Adafruit HTU21D-F Temperature & Humidity Sensor. The purpose of the circuit is to measure temperature and humidity levels and output the data to the Serial Monitor. The Arduino UNO serves as the central processing unit, while the HTU21D-F sensor provides accurate readings of the environmental conditions.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
- Purpose: Acts as the main controller for interfacing with the HTU21D-F sensor and processing data.
Adafruit HTU21D-F Temperature & Humidity Sensor
- Description: A high-precision sensor for measuring relative humidity and temperature.
- Pins: VCC, 3.3V, GND, SCL, SDA.
- Purpose: Provides temperature and humidity readings to the Arduino UNO.
Wiring Details
Arduino UNO
- 5V connected to HTU21D-F VCC
- GND connected to HTU21D-F GND
- SCL connected to HTU21D-F SCL
- SDA connected to HTU21D-F SDA
Adafruit HTU21D-F Temperature & Humidity Sensor
- VCC connected to Arduino UNO 5V
- GND connected to Arduino UNO GND
- SCL connected to Arduino UNO SCL
- SDA connected to Arduino UNO SDA
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);
}
The code provided is an Arduino sketch written for the Arduino UNO microcontroller. It includes the necessary libraries and initialization for the HTU21D-F sensor. The setup() function initializes the sensor and begins serial communication, while the loop() function reads the temperature and humidity data and prints it to the Serial Monitor at 500-millisecond intervals.