Home ArduinoB4R B4R and Arduino HDC1008 temperature sensor example

B4R and Arduino HDC1008 temperature sensor example

The HDC1000 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The device measures humidity based on a novel capacitive sensor. The humidity and temperature sensors are factory calibrated.

The sensing element of the HDC1000 is placed on the bottom part of the device, which makes the HDC1000 more robust against dirt, dust, and other environmental contaminants. The HDC1000 is functional within the full –40°C to +125°C temperature range.

Key Features

  • Relative Humidity (RH) Operating Range 0% to 100%
  • 14 Bit Measurement Resolution
  • Relative Humidity Accuracy ±3%
  • Temperature Accuracy ±0.2°C
  • Supply Voltage 3 V to 5 V
  • I2C Interface

Connection information

The easiest way is to purchase some sort of breakout, here is how you connect the module to your Arduino

arduino and hdc1008

arduino and hdc1008

 

Code

Import the Adafruit HDC 1008 libraries into the ARduino as you would normally do – these are available from https://github.com/adafruit/Adafruit_HDC1000_Library

This example uses some inline c which makes the job of re-using existing libraries easy

[codesyntax lang=”qbasic”]

#Region Project Attributes
	#AutoFlushLogs: True
	#CheckArrayBounds: True
	#StackBufferSize: 300
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'Public variables can be accessed from all modules.
	Public Serial1 As Serial
	Public timer1 As Timer
	Public hdctemp As Float
	Public hdchumi As Float
End Sub

Private Sub AppStart
	Serial1.Initialize(115200)
	Log("AppStart")
	RunNative("setup",Null)
	timer1.Initialize("timer1_Tick",1000)
	timer1.Enabled = True
End Sub

Private Sub Timer1_Tick
	RunNative("loop",Null)
	Log("Temperature is: ", hdctemp, "°C")
	Log("Humidity is: ", hdchumi, " %")
End Sub

#if C
#include <Wire.h>
#include "Adafruit_HDC1000.h"
Adafruit_HDC1000 hdc = Adafruit_HDC1000();
void setup(B4R::Object* o){
hdc.begin();
}
  
void loop (B4R::Object* o) {
  
   b4r_main::_hdchumi =hdc.readHumidity();
   b4r_main::_hdctemp =hdc.readTemperature();
}

#End if

[/codesyntax]

 

Look at the log window after you compile and run, you should see this

 

Temperature is: 25.2185°C
Humidity is: 30.8899 %
Temperature is: 25.1581°C
Humidity is: 30.4077 %
Temperature is: 25.0977°C
Humidity is: 29.8279 %
Temperature is: 25.0574°C
Humidity is: 29.3396 %
Temperature is: 24.9969°C
Humidity is: 28.9368 %
Temperature is: 24.9466°C
Humidity is: 28.4546 %
Temperature is: 24.8761°C
Humidity is: 28.0701 %
Temperature is: 24.8459°C
Humidity is: 27.6794 %
Temperature is: 24.8157°C
Humidity is: 27.2949 %
Temperature is: 24.7653°C
Humidity is: 26.9043 %

 

 

Links

Adafruit HDC1008 Temperature & Humidity Sensor Breakout Board

You may also like