Using 2 more HTU21DF Humidity and Temperature Sensors with Arduino

Project Video
Project Details

This is Arduino code to use 2 or more HTU21DF temperature and himidity sensor with Arduini.
Full hardware, two types of code and demonstation is shown in the video.
The code is available below this video. For other related codes please scrol lower in this screen.

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
Project Images
Image

Project Code


/***************************************************
  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 
#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 htu1 = Adafruit_HTU21DF();//create object for first HTU21DF sensor
Adafruit_HTU21DF htu2 = Adafruit_HTU21DF();//create object for second HTU21DF sensor
//Adafruit_HTU21DF htu3 = Adafruit_HTU21DF();//create object for third HTU21DF sensor (disabled, remove // from begining of code)

void setup() {
  Serial.begin(9600);
  Serial.println("HTU21D-F test for two modules");

  if (!htu.begin()) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
}

void loop() {
	//get value for sensor  1
    float temp1 = htu1.readTemperature();
    float rel_hum1 = htu1.readHumidity();

	//get value for sensor  2
    float temp2 = htu2.readTemperature();
    float rel_hum2 = htu2.readHumidity();	

	//get value for sensor  3
    float temp3 = htu3.readTemperature();
    float rel_hum3 = htu3.readHumidity();	
	
	//print values for sensor 1
    Serial.print("Sensor 1 Temp : "); Serial.print(temp1); Serial.print(" C");
    Serial.print("\t\t");
    Serial.print("Sensor 1 Humidity: "); Serial.print(rel_hum1); Serial.println(" \%");

	//print values for sensor 2
    Serial.print("Sensor 2 Temp : "); Serial.print(temp2); Serial.print(" C");
    Serial.print("\t\t");
    Serial.print("Sensor 2 Humidity: "); Serial.print(rel_hum2); Serial.println(" \%");	
	
	//print values for sensor 3
    //Serial.print("Sensor 3 Temp : "); Serial.print(temp3); Serial.print(" C");
    //Serial.print("\t\t");
    //Serial.print("Sensor 3 Humidity: "); Serial.print(rel_hum3); Serial.println(" \%");	
	
    delay(500);
}
Image