HDC1008 sensor readings displayed on a LCD4884 shield

In this article we will connect an HDC1008 sensor and connect it to a Nokia 5100 shield. We will display the humidity and temperature in celsius on the display

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

Parts List

Here are a list of parts that we used for this simple project

Name Product Link
Arduino uno 1pcs UNO R3 CH340G+MEGA328P for Arduino UNO R3 (NO USB CABLE)
LCD4884 LCD4884 LCD Joystick Shield v2.0 4884 LCD Expansion Board
HDC1008 HDC1008 Temperature Humidity Sensor Breakout Board for Arduino
Connecting cable Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cable for Arduino

Layout

This is a slightly different LCD4884 shield than I have used previously but it works in exactly the same manner. The HDC1008 is an I2C sensor so is easy to connect to the shield.

LCD4884 shield and HDC1008
LCD4884 shield and HDC1008

Code

You need to add the Adafruit GFX and PCD8544 libraries via the library manager. We did not use a library for the HDC1008 sensor

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Wire.h> 
 
 
// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(2, 3, 4, 5, 6); //dfrobot lcd4884 shield
 
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define hdcAddr 0x40
 
void setup()   
{
  Serial.begin(9600);
  Wire.begin();             // join i2c bus (address optional for master) 
  display.begin();
  // Starts I2C communication
  Wire.beginTransmission(hdcAddr);
  // Select configuration register
  Wire.write(0x02);
  // Temperature, humidity enabled, resolultion = 14-bits, heater on
  Wire.write(0x30);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(300);
  // init done
  // you can change the contrast around to adapt the display
  display.setContrast(50);
  display.clearDisplay();   // clears the screen and buffer
  // text display tests
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.setTextColor(WHITE, BLACK); // 'inverted' text
  display.println("HDC1008 TEST");
  display.display();
  delay(100);
}
 
 
void loop() 
{
  unsigned int data[2];
 
  Wire.beginTransmission(hdcAddr);
  // Send temp measurement command
  Wire.write(0x00);
  Wire.endTransmission();
  delay(500);
 
  // Request 2 bytes of data
  Wire.requestFrom(hdcAddr, 2);
 
  // Read 2 bytes of data for temperature
  if (Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }
 
  int temp = (data[0] * 256) + data[1];
  float celsTemp = (temp / 65536.0) * 165.0 - 40;
 
  Wire.beginTransmission(hdcAddr);
  // Send humidity measurement command
  Wire.write(0x01);
  Wire.endTransmission();
  delay(500);
 
  // Request 2 bytes of data
  Wire.requestFrom(hdcAddr, 2);
  // Read 2 bytes of data to get humidity
  if (Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }
  // Convert the data
  float humidity = (data[0] * 256) + data[1];
  humidity = (humidity / 65536.0) * 100.0;  
 
  // Display temperature
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.setCursor(0,15);
  display.print(celsTemp,2);
  display.println(" C");
  display.print(humidity,2);
  display.println(" %");
  display.display();
 
}

Video

This example video shows the sensor readings on the LCD