Brief Description
How many times did the weatherman say to you not accurate temperature and relative humidity? Raspberry Pi 2 + HDC1008 temperature and humidity sensor to the rescue!
Using this project, you will be able to monitor your temperature and humidity at home via the internet from any place.
Hardware
You will need Raspberry Pi 2 Model B, HDC1008 temperature and humidity sensor, a breadboard, 8+ jumper wires. I am also using Adafruit Pi Cobbler Plus Kit, but it is optional.
Software
Microsoft Visual Studio 2015 (Community edition is fine).
Wiring
A0, A1 pins are responsible for setting sensor chip I2C address. In my case, they both connected to the ground (GPIO #9), so I2C bus address is 0x40. I do not use RDY pin, so I have connected it together with GND pin to the ground too (GPIO #9). I2C SDA and SCL pins are connected to the correspondent I2C Raspberry GPIO pins (GPIO#3 and GPIO#5). VIN pin is wired to the 3.3V power GPIO pin(GPIO# 17).
Temperature & Humidity Measurement
HDC1008 sensor chip has I2C interface. Check out this great I2C tutorial to learn the basics how it works. I have created the library that can be used in order to read sensor measurements. The library is available on GitHub and on NuGet. The sample code which uses the library:
using (var sensor = await Hdc100X.Get(BusAddress.Address40)) { // infinite loop for temperature and humidity measurement once per 500 ms for (;;) { try { var measurment = await sensor.MeasureAsync(); Debug.WriteLine("{0} : {1}", measurment.Temperature, measurment.Humidity); } catch (Exception ex) { //Ooops...something bad happened } await Task.Delay(500); } }
Posting Measurements To Azure EventHub
The sample showing how the HDC100x driver can be used with Raspberry Pi 2 in order to continuously post measurement data to Azure EventHub. The application itself is a UWP background task application. Data is being posted to EventHub using the ConnectTheDots sample application.
Azure Setup
ConnectTheDots already has the infrastructure for setting up Azure EventHub. Just follow instructions.
Sample Project Configuration
Go to StartupTask.cs and enter your Azure/EventHub settings:
var connectTheDotsHelper = new ConnectTheDotsHelper(serviceBusNamespace: "[your service bus namespace]", eventHubName: "[yor event hub name]", keyName: "[your shared access policy key name]", key: "[your shared access policy key]", displayName: "[any display name]", organization: "[your organization]", location: "[your location]", sensorList: sensors);
Real-time Results Observation
ConnectTheDots provides the web application which allows to observe temperature and humidity measurements in a real-time. Just deploy it to Azure and you will be all set.
Here is the screenshot of my measurements harvested from the EventHub by the web application. Spikes on graphs correspond to the moment when I blew on the sensor:
Comments