Microbit and HDC1080 humidity and temperature sensor example

The HDC1080 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The HDC1080 operates over a wide supply range, and is a low cost, low power alternative to competitive solutions in a wide range of common applications. The humidity and temperature sensors are factory calibrated.

Features
Relative Humidity Accuracy ±2% (typical)
Temperature Accuracy ±0.2°C (typical)
Excellent Stability at High Humidity
14 Bit Measurement Resolution
100 nA Sleep Mode Current

 

Connection

 

 MIcrobit connection  Module connection
 3v3 3v3
 GND  GND
 SDA – 20  SDA
 SCL – 21  SCL

 

Code

I needed to modify the   https://github.com/closedcube/ClosedCube_HDC1080_Arduino library, otherwise there was compilation errors

You need to change Wire.write(0x00); to Wire.write((byte)0x00); – Modified HDC1080 library

This is the default example

 

#include <Wire.h>
#include "ClosedCube_HDC1080.h"
 
ClosedCube_HDC1080 hdc1080;
 
void setup()
{
Serial.begin(9600);
Serial.println("ClosedCube HDC1080 Arduino Test");
 
// Default settings:
// - Heater off
// - 14 bit Temperature and Humidity Measurement Resolutions
hdc1080.begin(0x40);
 
Serial.print("Manufacturer ID=0x");
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
Serial.print("Device ID=0x");
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
 
printSerialNumber();
 
}
 
void loop()
{
Serial.print("T=");
Serial.print(hdc1080.readTemperature());
Serial.print("C, RH=");
Serial.print(hdc1080.readHumidity());
Serial.println("%");
delay(3000);
}
 
void printSerialNumber() {
Serial.print("Device Serial Number=");
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
char format[12];
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
Serial.println(format);
}

 

 

 

Output

Open the serial monitor window and you should expect to see something like this

ClosedCube HDC1080 Arduino Test
Manufacturer ID=0x54T=23.06C, RH=51.07%
T=23.06C, RH=51.07%
T=23.08C, RH=51.05%
T=23.08C, RH=51.15%
T=23.10C, RH=51.15%
T=23.11C, RH=51.15%
T=23.11C, RH=51.05% ClosedCube_HDC1080_Arduino-master

 

Links

1PC 2.7 V to 5.5 V HDC1080 high precision temperature and humidity sensor humidity temperature module

http://www.ti.com/lit/gpn/hdc1080

http://www.ti.com/lit/pdf/snau189

Micro:bit and Si7021 I2C Humidity and Temperature Sensor example

The Si7021 I2C Humidity and Temperature Sensor is a monolithic CMOS IC integrating humidity and temperature sensor elements, an analog-to-digital converter, signal processing, calibration data, and an I2C Interface.

The patented use of industry-standard, low-K polymeric dielectrics for sensing humidity enables the construction of low-power, monolithic CMOS Sensor ICs with low drift and hysteresis, and excellent long term stability, it would be a great sensor to have on the roller. It would be able to measure everything before I go out for a ride around town.

Features

Relative Humidity Sensor:
Si7013/21: ± 3% RH (maximum) @ 0-80% RH
Si7020: ± 4% RH (maximum) @ 0-80% RH
Si7006: ± 5% RH (maximum) @ 0-80% RH

Temperature Sensor:
Si7013/20/21: ±0.4°C accuracy (maximum) @ -10 to +85°C
Si7006: ±1.0°C accuracy (maximum) @ -10 to +85°C
0 to 100% RH operating range
Up to -40 to +125°C operating range
Wide operating voltage range (1.9 to 3.6V)
Low Power Consumption: 2.2µW average power at 3.3V and 1 sample per second
I2C host interface
Integrated on-chip heater
3mm x 3mm QFN package
Excellent long term stability
Factory calibrated
Optional factory-installed filter/cover
Lifetime protection during reflow and in operation
Protects against contamination from dust, dirt, household chemicals and other liquids
AEC-Q100 automotive qualified (Si7013/20/21)

 

Connection

Must use 3v3 for Vin

microbit and SI7021

microbit and SI7021

 

Code

#include <Wire.h>
const int ADDR =0x40;
int X0,X1,Y0,Y1,Y2,Y3;
double X,Y,X_out,Y_out1,Y_out2;
void setup()
{
Serial.begin(9600);
Wire.begin();
delay(100);
Wire.beginTransmission(ADDR);
Wire.endTransmission();
}
void loop()
{
/**Send command of initiating temperature measurement**/
Wire.beginTransmission(ADDR);
Wire.write(0xE3);
Wire.endTransmission();
Serial.print("Temp");
Serial.print("\t");
Serial.println("Humidity");
/**Read data of temperature**/
Wire.requestFrom(ADDR,2);
if(Wire.available()<=2);
{
X0 = Wire.read();
X1 = Wire.read();
X0 = X0<<8;
X_out = X0+X1;
}
/**Calculate and display temperature**/
X=(175.72*X_out)/65536;
X=X-46.85;
Serial.print(X);
Serial.print("C");
Serial.print("\t");
/**Send command of initiating relative humidity measurement**/
Wire.beginTransmission(ADDR);
Wire.write(0xE5);
Wire.endTransmission();
/**Read data of relative humidity**/
Wire.requestFrom(ADDR,2);
if(Wire.available()<=2);
{
Y0 = Wire.read();
Y2=Y0/100;
Y0=Y0%100;
Y1 = Wire.read();
Y_out1 = Y2*25600;
Y_out2 = Y0*256+Y1;
}
/**Calculate and display relative humidity**/
Y_out1 = (125*Y_out1)/65536;
Y_out2 = (125*Y_out2)/65536;
Y = Y_out1+Y_out2;
Y=Y-6;
Serial.print(Y);
Serial.println("%");
delay(300);
Serial.println();
delay(1000);
}

 

Output

Open the serial monitor, you should see something like this

Temp    Humidity
23.12C    52.83%

Temp    Humidity
24.04C    53.13%

Temp    Humidity
26.28C    53.83%

Temp    Humidity
27.42C    54.57%

Temp    Humidity
28.27C    55.32%

Temp    Humidity
27.94C    56.11%

 

Links

GY-21 Humidity Sensor with I2C Interface Si7021 for Arduino Industrial High Precision

micro:bit and DS18B20 temperature sensor example

The DS18B20 is a  temperature sensor that can be used in various simple projects.  This part uses the 1 wire (I2C) bus and you can connect multiple sensors up to your Arduino.

The part is also relatively low cost and only requires an additional 4k7 pull up resistor. In the example below we shall make a basic example that reads the temperature and outputs via serial and can be verified using the serial monitor in the Arduino IDE.

Lets look at the parts list

Parts List

Label Part Type
DS1 DS18B20 1-Wire Temperature Sensor
Part1 micro:bit
R1 4.7k Ω Resistor

Layout

As always be careful not to get the connections incorrect, you can refer to the pinout for the device below to help . The DS18B20 can be powered by between 3.0V and 5.5V so you can simply connect its GND pin to 0V and the VDD pin to +5V from the Wemos Mini

Here is the connection diagram showing how to connect your wemos to the resistor and sensor.

 

Schematic

microbit and ds18b20

microbit and ds18b20

Code

#include <OneWire.h>
 
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
 
OneWire  ds(A3);  // on pin D4 (a 4.7K resistor is necessary)
 
void setup(void) 
{
  Serial.begin(9600);
}
 
void loop(void) 
{
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
 
  if ( !ds.search(addr)) 
  {
    ds.reset_search();
    delay(250);
    return;
  }
 
 
  if (OneWire::crc8(addr, 7) != addr[7]) 
  {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) 
  {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end  
  delay(1000);
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad
 
  for ( i = 0; i < 9; i++) 
  {           
    data[i] = ds.read();
  }
 
  // Convert the data to actual temperature
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) 
    {
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } 
  else 
  {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
 
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
}

Output

Open the serial monitor and you should see something like this

Temperature = 19.44 Celsius, 66.99 Fahrenheit

Temperature = 20.37 Celsius, 68.68 Fahrenheit

Temperature = 22.75 Celsius, 72.95 Fahrenheit

Temperature = 24.50 Celsius, 76.10 Fahrenheit

Temperature = 25.75 Celsius, 78.35 Fahrenheit

Temperature = 26.81 Celsius, 80.26 Fahrenheit

Temperature = 27.62 Celsius, 81.72 Fahrenheit

 

Links
1PCS DS18B20 temperature measurement sensor module For arduino

micro:bit and SHT21 humidity and temperature sensor example

The digital SHT2x humidity sensor series is used in high volumes in a wide variety of applications and has today become the de facto industry standard. The SHT2x series consists of a low-cost version with the SHT20 humidity sensor, a standard version with the SHT21 humidity sensor, and a high-end version with the SHT25 humidity sensor. The open cavity mold package – which encapsulates the complete chip except for the humidity sensor area – protects the capacitive humidity sensor against external impact and facilitates excellent long-term stability. The SHT2x sensors are available both in large and small volumes.This is the breakout for the sensor that I bought.

The SHT2x humidity sensor series contains a capacitive-type humidity sensor, a band-gap temperature sensor, and specialized analog and digital integrated circuits – all on a single CMOSens® chip. This yields superior sensor performance in terms of accuracy and stability as well as minimal power consumption.

Here is a simple schematic, again be careful as Vcc is 3.3v with this device

 

Schematic

 

microbit and sht21

microbit and sht21

 

 

Code

 

I used the following library – https://github.com/markbeee/SHT21

#include <Wire.h>
#include "SHT21.h"
 
SHT21 SHT21;
 
void setup()
{
 SHT21.begin();
 Serial.begin(9600);
}
 
void loop()
{
 Serial.print("Humidity(%RH): ");
 Serial.print(SHT21.getHumidity());
 Serial.print(" Temperature(C): ");
 Serial.println(SHT21.getTemperature());
 
 delay(1000);
}

 

Output

 

Humidity(%RH): 39.43 Temperature(C): 20.85
Humidity(%RH): 39.49 Temperature(C): 20.83
Humidity(%RH): 39.77 Temperature(C): 22.19
Humidity(%RH): 40.14 Temperature(C): 23.34
Humidity(%RH): 40.51 Temperature(C): 24.21
Humidity(%RH): 40.78 Temperature(C): 24.26
Humidity(%RH): 40.87 Temperature(C): 24.09
Humidity(%RH): 40.90 Temperature(C): 23.91

 

Links

these come in at about $5 for a useful breakout board with this sensor

New SHT21 Digital Humidity And Temperature Sensor Module Replace