HDC1080 humidity and temperature sensor micro:bit 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

Schematics

 

microbit and hdc1080

microbit and hdc1080

 

Code

 

#include<Wire.h>
 
// HDC1000 I2C address is 0x40(64)
#define Addr 0x40
 
void setup()
{
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
 
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x02);
// Temperature, humidity enabled, resolultion = 14-bits, heater on
Wire.write(0x30);
// Stop I2C Transmission
Wire.endTransmission();
delay(300);
}
 
void loop()
{
unsigned int data[2];
 
// Starts I2C communication
Wire.beginTransmission(Addr);
// Send temp measurement command
Wire.write((byte)0x00);
// Stop I2C Transmission
Wire.endTransmission();
delay(500);
 
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
 
// Read 2 bytes of data
// temp msb, temp lsb
if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data
int temp = (data[0] * 256) + data[1];
float cTemp = (temp / 65536.0) * 165.0 - 40;
float fTemp = cTemp * 1.8 + 32;
 
// Starts I2C communication
Wire.beginTransmission(Addr);
// Send humidity measurement command
Wire.write(0x01);
// Stop I2C Transmission
Wire.endTransmission();
delay(500);
 
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
 
// Read 2 bytes of data
// humidity msb, humidity lsb
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;
 
// Output data to serial monitor
Serial.print("Relative Humidity :");
Serial.print(humidity);
Serial.println(" %RH");
Serial.print("Temperature in Celsius :");
Serial.print(cTemp);
Serial.println(" C");
Serial.print("Temperature in Fahrenheit :");
Serial.print(fTemp);
Serial.println(" F");
delay(500);
}

 

 

Output

In the serial monitor

Temperature in Celsius :20.95 C
Temperature in Fahrenheit :69.71 F
Relative Humidity :34.31 %RH
Temperature in Celsius :26.02 C
Temperature in Fahrenheit :78.84 F
Relative Humidity :36.02 %RH
Temperature in Celsius :27.09 C
Temperature in Fahrenheit :80.77 F
Relative Humidity :35.77 %RH

 

Links

1PCS HDC1080 high-precision temperature and humidity sensor module

micro:bit and TM1637 7 segment display example

A common display module that you can buy on the internet contain the Tm1638 driver chip, I was interested in this one which is the TM1637 which appears to be a more basic version which can only control a display, the TM1638 can also control LED’s, buttons and two displays at the same time.

This is a common anode 4-digit tube display module which uses the TM1637 driver chip; Only 2 connections are required to control the 4-digit 8-segment displays

Here is the module

Features of the module

Display common anode for the four red LED
Powered supply by 3.3V/5V
Four common anode tube display module is driven by IC TM1637
Can be used for Arduino devices, two signal lines can make the MCU control 4 8 digital tube. Digital tube 8 segment is adjustable
Here is how to hook the module up, the good news is this worked with my LOLIN32 and 3.3v

 

Schematic

microbit and TM1637

microbit and TM1637

 

Code

There is a library for this IC, you can get it from https://github.com/avishorp/TM1637 , as usual there is a built in example but here is a simple sketch

#include <TM1637Display.h>
 
const int CLK = 3; //Set the CLK pin connection to the display
const int DIO = 4; //Set the DIO pin connection to the display
 
int numCounter = 0;
 
TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
 
void setup()
{
display.setBrightness(0x0a); //set the diplay to maximum brightness
}
 
void loop()
{
for(numCounter = 0; numCounter < 1000; numCounter++) //Iterate numCounter
{
display.showNumberDec(numCounter); //Display the numCounter value;
delay(1000);
}
}

 

 

Links

1pcs 4 Bits TM1637 Red Digital Tube LED Display Module & Clock for Arduino LED Free Shipping

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 TEMT6000 ambient light sensor example

TEMT6000X01 ambient light sensor is a silicon NPN epitaxial planar phototransistor in a miniature transparent 1206 package for surface mounting. It is sensitive to visible light much like the human eye and has peak sensitivity at 570 nm.

Here is a picture of a module

Here is a schematic of the module

APPLICATIONS

Ambient light sensor for control of display backlight dimming in LCD displays and keypad backlighting of mobile devices and in industrial on/off-lighting operation.

• Automotive sensors
• Mobile phones
• Notebook computers
• PDA’s
• Cameras
• Dashboards

Connection

Code

#define LIGHTSENSORPIN A1 //Ambient light sensor reading
void setup()
{
pinMode(LIGHTSENSORPIN, INPUT);
Serial.begin(9600);
}
void loop()
{
float reading = analogRead(LIGHTSENSORPIN); //Read light level
float square_ratio = reading / 1023.0; //Get percent of maximum value (1023)
square_ratio = pow(square_ratio, 2.0);
Serial.println(reading);
delay(1000);
}

 

Output

Open the serial monitor and you should see something like this

41.00
42.00
4.00
1.00
21.00
38.00
41.00
41.00
40.00

 

Links

TEMT6000 Light Sensor

https://www.vishay.com/docs/81579/temt6000.pdf