Crowtail- HTU21D Humidity&Temperature Sensor

From Elecrow
(Difference between revisions)
Jump to: navigation, search
(Specification)
(Usage)
Line 22: Line 22:
  
 
== Usage ==
 
== Usage ==
This demo is going to show you how to read temperature and humidity information from this Crowtail - Temperature and Humidity Sensor.
+
This demo is going to show you how to read temperature and humidity information from this Crowtail - HTU21D Humidity&Temperature Sensor.
  
 
1.Hardware Connection<br>
 
1.Hardware Connection<br>
The Temperature and Humidity sensor is connecting to digital port D5 of Crowtail - Base Shield.
+
The HTU21D Humidity&Temperature Sensor is connecting to digital port D5 of Crowtail - Base Shield.
  
[[File:Temperature and Humidity Sensor.jpg |600px]]
+
[[File:connection of HTU21D Humidity&Temperature Sensor.jpg |600px]]
  
2.Download [http://www.elecrow.com/wiki/index.php?title=File:Temperature_humidity_sensor.zip Temperature_humidity_sensor library] for Arduino boards with 16MHz XTAL; Unzip and put it in the libraries file of Arduino IDE by the path: ..\arduino-1.0\libraries;
+
2.Download the [http://www.elecrow.com/wiki/index.php?title=File:SparkFunHTU21D.zip HTU21D Humidity&Temperature Sensor] Library. Unzip and put it in the libraries file of Arduino IDE by the path: ..File/arduino IDE/Arduino/library/SparkFunHTU21D. You can also copy the following program to Arduino IDE and upload to your Arduino/Crowduino.
 +
<BR>
  
3.Open “DHTtester” example via the path: File --> Examples --> Humidity_Temperature_Sensor --> DHTtester.
+
3.Open “SparkFunHTU21D” example:
// Example testing sketch for various DHT humidity/temperature sensors
+
<pre>
+
 
#include "DHT.h"
+
#include <Wire.h>
 
+
#include "SparkFunHTU21D.h"
#define DHTPIN 5    // what pin we're connected to
+
 
 
+
//Create an instance of the object
// Uncomment whatever type you're using!
+
HTU21D myHumidity;
#define DHTTYPE DHT11  // DHT 11
+
 
//#define DHTTYPE DHT22  // DHT 22  (AM2302)
+
void setup()
//#define DHTTYPE DHT21  // DHT 21 (AM2301)
+
{
+
  Serial.begin(9600);
// Connect pin 1 (on the left) of the sensor to +5V
+
  Serial.println("HTU21D Example!");
// Connect pin 2 of the sensor to whatever your DHTPIN is
+
 
// Connect pin 4 (on the right) of the sensor to GROUND
+
  myHumidity.begin();
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
+
}
+
 
DHT dht(DHTPIN, DHTTYPE);
+
void loop()
+
{
void setup() {
+
   float humd = myHumidity.readHumidity();
  Serial.begin(9600);  
+
   float temp = myHumidity.readTemperature();
  Serial.println("DHTxx test!");
+
 
 
+
   Serial.print("Time:");
  dht.begin();
+
   Serial.print(millis());
}
+
   Serial.print(" Temperature:");
 
+
  Serial.print(temp, 1);
void loop() {
+
  Serial.print("C");
  // Reading temperature or humidity takes about 250 milliseconds!
+
  Serial.print(" Humidity:");
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
+
  Serial.print(humd, 1);
   float h = dht.readHumidity();
+
  Serial.print("%");
   float t = dht.readTemperature();
+
 
+
  Serial.println();
   // check if returns are valid, if they are NaN (not a number) then something went wrong!
+
  delay(1000);
   if (isnan(t) || isnan(h)) {
+
}
    Serial.println("Failed to read from DHT");
+
 
   } else {
+
</pre>
    Serial.print("Humidity: ");  
+
    Serial.print(h);
+
    Serial.print(" %\t");
+
    Serial.print("Temperature: ");  
+
    Serial.print(t);
+
    Serial.println(" *C");
+
  }
+
}
+
 
4.Upload it into your Arduino board and open the serial monitor to observe the temperature and relative humidity information of the environment.
 
4.Upload it into your Arduino board and open the serial monitor to observe the temperature and relative humidity information of the environment.
  
[[File:thresult.jpg |400px]]
+
[[File:result of HTU21D Humidity&Temperature Sensor.png |400px]]
  
 
== Resource  ==
 
== Resource  ==

Revision as of 09:36, 8 February 2017

Contents

Description

This module can help you detect the temperature and humidity of the environment of your house. The HTU21D is a low-cost, easy to use, highly accurate, digital humidity and temperature sensor. This sensor is ideal for environmental sensing and data logging and perfect for a weather stations or humidor control systems. All you need is two lines for I2C communication and you’ll have relative humidity readings and very accurate temperature readings as a bonus!

Model:Crowtail- XXXX

400px

Specification

  • Supply voltage: 1.5 to 3.6V.
  • Humidity measurement range: 0-100% RH
  • Temperature measurement range: -40 ℃ -105 ℃
  • The maximum power consumption: 2.7uW
  • Communication: I2C
  • Humidity accuracy range (10% RH to 95% RH): HTU21D ± 2% RH
  • Humidity hysteresis: ± 1% RH
  • Measurement time: 50ms
  • Annual drift: -0.5% RH / year
  • Response time: 5 s

Usage

This demo is going to show you how to read temperature and humidity information from this Crowtail - HTU21D Humidity&Temperature Sensor.

1.Hardware Connection
The HTU21D Humidity&Temperature Sensor is connecting to digital port D5 of Crowtail - Base Shield.

Connection of HTU21D Humidity&Temperature Sensor.jpg

2.Download the HTU21D Humidity&Temperature Sensor Library. Unzip and put it in the libraries file of Arduino IDE by the path: ..File/arduino IDE/Arduino/library/SparkFunHTU21D. You can also copy the following program to Arduino IDE and upload to your Arduino/Crowduino.

3.Open “SparkFunHTU21D” example:


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

//Create an instance of the object
HTU21D myHumidity;

void setup()
{
  Serial.begin(9600);
  Serial.println("HTU21D Example!");

  myHumidity.begin();
}

void loop()
{
  float humd = myHumidity.readHumidity();
  float temp = myHumidity.readTemperature();

  Serial.print("Time:");
  Serial.print(millis());
  Serial.print(" Temperature:");
  Serial.print(temp, 1);
  Serial.print("C");
  Serial.print(" Humidity:");
  Serial.print(humd, 1);
  Serial.print("%");

  Serial.println();
  delay(1000);
}

4.Upload it into your Arduino board and open the serial monitor to observe the temperature and relative humidity information of the environment.

Result of HTU21D Humidity&Temperature Sensor.png

Resource

Personal tools
Namespaces

Variants
Actions
Elecrow Store
Navigation
Elecrow Products
Toolbox