Skip to content

Temperature and Humidity Sensor TinyShield Tutorial

The Temperature and Humidity Sensor TinyShield allows you to measure temperature and humidity from the TinyDuino. Since the same Si7020-A10 sensor can measure both humidity and temperature, this TinyShield sensor is a perfect addition to weather-detecting projects.

To learn more about the TinyDuino Platform, click here


Description

This TinyShield lets you measure temperature and humidity from the TinyDuino.  Based around the Silicon Labs Si7020-A10 sensor, this allows for accurate temperature measurement (+- 0.4C) and precision relative humidity readings.  

This TinyShield incorporates level shifters and a local power supply to ensure proper and safe operation over the entire TinyDuino operating voltage range up to 5V.

To see what other TinyShields are compatible with this TinyShield, see the TinyShield Compatibility Matrix

Technical Details Si7020-A10 Specs
  • Precision Relative Humidity Sensor 
    • +-4% RH, 0-80% RH
    • 0 - 100% RH operating range
  • High Accuracy Temperature Sensor
    • +-0.4C, -10 to +85C
  • Factory Calibrated
  • Integrated on-chip heater
  • Excellent long term stability
TinyDuino Power Requirements
  • Voltage: 3.0V - 5.5V
  • Current:
    • 150uA (Active Mode).
    • 60nA (Standby)
    • Due to the low current, this board can be run using the TinyDuino coin cell option
Pins Used
  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line
Dimensions
  • 20mm x 20mm (.787 inches x .787 inches)
  • Max Height (from lower bottom TinyShield Connector to upper top TinyShield Connector): 5.11mm (0.201 inches)
  • Weight: 1 gram (.04 ounces)

Notes

  • You can also use this shield without the TinyDuino – there are 0.1″ spaced connections for power, ground, and the two I2C signals along the side of the TinyShield to allow you to connect a different system.
    • Warning: Revision 4 boards have a mistake on the silkscreen, the pin marked VCC is actually SCL, the pin marked SCL is actually SDA, and the pin marked SDA is actually VCC. If you connect this up the way it is marked you will not damage the board.
  • This sensor has a hole in the top of it for measuring humidity, care should be taken to not get debris in this opening. 

Materials

TinyZero and Temperature and Humidity Sensor TinyShield

Hardware

Software


Assembly (Hardware)

On top of your processor board of choice (i.e. TinyZero), place the Temperature and Humidity Sensor TinyShield, snapping them together with the tan 32-pin connectors. Plug a MicroUSB cable into the USB port and then plug the cable into a free USB port on your computer. Make sure the processor is switched on.

An assembled stack of a TinyZero and Temperature and Humidity Sensor TinyShield.


Software (Setup and Downloads)

Open the Arduino IDE so you can download, and install the Temperature and Humidity sensor library. (You should already have the IDE installed if you've gone through a setup tutorial for a processor board.)

Click the following link to download the zipped Si7021 Arduino Library. Now to install it into your Arduino library and make it usable, click the Sketch tab in the IDE, select Include Library > Add .ZIP Library. Then locate the Si7021.zip folder wherever it downloaded, and press "Open". The library should now be installed. Yay!


The Code

Download the .zip file of the example program and open it in the Arduino IDE.

Code
/*
  TinyCircuits Si7020 Temperature and Humidity Sensor TinyShield Example Sketch

  This demo shows how to read temperature and humidity data from the Si7020 
  sensor using the Si7020 library: https://github.com/LowPowerLab/SI7021

  The program will print the temperature & humidity, then enable the heater for 
  30 seconds and print the temperature & humidity to show the difference the 
  internal heater can make. The heater will then be disabled with a cool down 
  period of 30 seconds.

  Rewritten May 2021 to include built-in heater functionality by L. Wienclaw

  https://TinyCircuits.com
*/

#include <Wire.h>
#include <SI7021.h>

SI7021 sensor;

// Make Serial Monitor compatible for all TinyCircuits processors
#if defined(ARDUINO_ARCH_AVR)
  #define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#endif

void setup() {
  SerialMonitorInterface.begin(115200);
  Wire.begin();
  SerialMonitorInterface.print("Initializing sensor... ");
  if(!sensor.begin()){
    SerialMonitorInterface.println("Sensor not found!");
    while(true);
  }
  SerialMonitorInterface.println("Success!");

  // this driver should work for SI7020 and SI7021, this returns 20 or 21
  int deviceid = sensor.getDeviceId();
//    SerialMonitorInterface.println(deviceid);
}

void loop() {
    // read and print temp and humidity
    float temperature = sensor.getCelsiusHundredths() / 100.0;
    SerialMonitorInterface.print(temperature);
    SerialMonitorInterface.print(" deg Celsius\t");
    int humidity = sensor.getHumidityPercent();
    SerialMonitorInterface.print(humidity);
    SerialMonitorInterface.println("% relative humidity");

    // enable internal heater for testing
    sensor.setHeater(true);
    delay(30000);
    sensor.setHeater(false);

    // see if heater changed temperature
    // read and print temp and humidity
    temperature = sensor.getCelsiusHundredths() / 100.0;
    SerialMonitorInterface.print(temperature);
    SerialMonitorInterface.print(" deg Celsius\t");
    humidity = sensor.getHumidityPercent();
    SerialMonitorInterface.print(humidity);
    SerialMonitorInterface.println("% relative humidity -- (after heater on)");

    //cool down
    delay(30000);

    // get humidity and temperature in one shot, saves power because sensor takes temperature when doing humidity anyway
//    si7021_env data = sensor.getHumidityAndTemperature();
//    delay(5000);
}

Upload the program using the Tools selections:

Tools selections for TinyZero (Your COM# will probably be different)

Once the upload is complete, open up the Serial Monitor (Ctrl+Shift+M) at 115200 baud, and you'll be able to observe the data gathered by the sensor!

Data from the Temperature and Humidity Sensor TinyShield here at TinyCircuits

The program will print the temperature & humidity, then enable the heater for 30 seconds and print the temperature & humidity to show the difference the internal heater can make. The heater will then be disabled with a cool down period of 30 seconds.

The Si7020 contains an integrated resistive heating element that may be used to raise the temperature of the sensor. This element can be used to test the sensor, to drive off condensation, or to implement dew-point measurement when the Si7020 is used in conjunction with a separate temperature sensor such as another Si7020 (the heater will raise the temperature of the internal temperature sensor). Turning on the heater will reduce the tendency of the humidity sensor to accumulate an offset due to "memory" of sustained high humidity conditions.

Now you can keep track of the environment in your next project!


Downloads


Contact Us

If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

Thanks for making with us!