Microbit and TMP175 digital temperature sensor example

The TMP75 and TMP175 devices are digital temperature sensors ideal for NTC and PTC thermistor replacement. The devices offer a typical accuracy of ±1°C without requiring calibration or external component signal conditioning. IC temperature sensors are highly linear and do not require complex calculations or look-up tables to derive the temperature. The on-chip 12-bit ADC offers resolutions down to 0.0625°C. The devices are available in the industry standard LM75 SOIC-8 and MSOP-8 footprint.

The TMP175 and TMP75 feature SMBus, Two-Wire, and I2C interface compatibility. The TMP175 device allows up to 27 devices on one bus. The TMP75 allows up to eight 8 on one bus. The TMP175 and TMP75 both feature an SMBus Alert function.

The TMP175 and TMP75 devices are ideal for extended temperature measurement in a variety of communication, computer, consumer, environmental, industrial, and instrumentation applications.

Features

  • TMP175: 27 Addresses
  • TMP75: 8 Addresses, NIST Traceable
  • Digital Output: SMBus™, Two-Wire™, and I2C
    Interface Compatibility
  • Resolution: 9 to 12 Bits, User-Selectable
  • Accuracy:
    • ±1°C (Typical) from –40°C to 125°C
    • ±2°C (Maximum) from –40°C to 125°C
  • Low Quiescent Current: 50-µA, 0.1-µA Standby
  • Wide Supply Range: 2.7 V to 5.5 V
  • Small 8-Pin MSOP and 8-Pin SOIC Packages

 

Connection

Module Connection Microbit Connection
VCC 3v3
GND Gnd
SDA SDA – 20
SCL SCL – 19

 

Code

#include <Wire.h> 
 
byte TempHi;              // Variable hold data high byte
byte TempLo;              // Variable hold data low byte
boolean P_N;              // Bit flag for Positive and Negative
unsigned int Decimal;     // Variable hold decimal value
 
void Cal_Temp();
/*******************************************************************************
                      Setup
*******************************************************************************/ 
void setup() 
{ 
  Serial.begin(9600);
  Wire.begin();             // join i2c bus (address optional for master) 
  delay(1000);
} 
 
/*******************************************************************************
                      Main Loop
*******************************************************************************/  
void loop() 
{
  const int I2C_address = 0x37;  // I2C write address 
 
  delay(100);
  Wire.beginTransmission(I2C_address);
  Wire.write(1);             // Setup configuration register
  Wire.write(0x60);          // 12-bit
  Wire.endTransmission(); 
 
  Wire.beginTransmission(I2C_address);
  Wire.write((byte)0);             // Setup Pointer Register to 0
  Wire.endTransmission(); 
 
  while (1)
  {
    delay(1000);
 
    // Read temperature value
    Wire.requestFrom(I2C_address, 2);
    while(Wire.available())          // Checkf for data from slave
    {                                
      TempHi = Wire.read();       // Read temperature high byte
      TempLo = Wire.read();       // Read temperature low byte
    } 
    Cal_Temp ();
 
    // Display temperature
    Serial.print("The temperature is ");
    if (P_N == 0)
      Serial.print("-");
    Serial.print(TempHi,DEC);
    Serial.print(".");
    Serial.print(Decimal,DEC);
    Serial.println(" degree C");
  }  
}
 
void Cal_Temp()
{
  if (TempHi&0x80)          // If bit7 of the TempHi is HIGH then the temperature is negative
    P_N = 0;
  else                      // Else the temperature is positive
    P_N = 1;
 
  TempHi = TempHi & 0x7F;   // Remove sign
  TempLo = TempLo & 0xF0;   // Filter out last nibble
  TempLo = TempLo >>4;      // Shift right 4 times
  Decimal = TempLo;
  Decimal = Decimal * 625;  // Each bit = 0.0625 degree C
 
}

 

Output

Open the serial monitor and you will see something like this

The temperature is 23.5000 degree C
The temperature is 23.5625 degree C
The temperature is 25.3125 degree C
The temperature is 26.7500 degree C
The temperature is 27.8125 degree C
The temperature is 28.5000 degree C
The temperature is 28.9375 degree C
The temperature is 29.3750 degree C
The temperature is 29.6875 degree C
The temperature is 29.9375 degree C
The temperature is 30.1250 degree C
The temperature is 30.3125 degree C

 

Link

1pcs CJMCU-175 TMP175 27 Address Digital Temperature Sensor

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