Arduino I²c + temperature and humidity sensor Si7021

Source: Internet
Author: User

SI7021 is a temperature and humidity sensor chip produced by Silicon Labs. Its main features:

    • Humidity accuracy: Error typ. +/-2%RH, Max +/-3%rh (0~80%RH), factory corrected
    • Temperature accuracy: Error typ. +/-0.3%°c, Max +/-0.4%°c ( -10°c~85°c), factory corrected
    • Measuring range: Temperature range 0~100%rh, maximum temperature range -40°c~125°c
    • Operating voltage: 1.9~3.6v
    • Low power consumption: Low 150μa at work, 60nA at standby
    • Interface: I²C, maximum rate support 400kbps
    • Long-term stability: humidity ≤0.25%rh/yr, temperature ≤0.01°c/yr
    • Package: 3x3 mm DFN
    • On-Chip integrated heaters (heater)
    • Optional hydrophobic protective cover

AndArduinoThe connection

Since the operating voltage of the Arduino Uno is 5V, and the Si7021 cannot operate at 5V, the connection requires a level shift. The method of conversion is to connect between Si7021 and Arduino via the I²c Logic level converter. The principle of bi-directional logic level translators can be consulted in the application notes of Philips Semiconductor "bi-directional levels shifter for I²C bus and other systems". The converter ends up with the pull-up resistor required by the I²C bus.

Functional commissioning

1. During the Si7021 measurement process, you can choose to have the SCL pull down (hold Master mode) or not to respond to the message from the MCU (No to master mode).

2. The relative humidity measurement includes the temperature measurement, and the temperature measurement can be carried out separately.

3. For relative humidity or temperature measurement, whether the MCU sends an ACK to the measured low byte determines whether the Si7021 returns a CRC check code. When reading the temperature value of the last relative humidity measurement, the Si7021 does not reply to the CRC check code. Half of the following code is related to CRC validation and is not required, and the CRC algorithm is not optimized.

4. When Si7021 is used for environmental measurement, chip placement, PCB thermal barrier design has a significant impact on measurement accuracy, response time, see the official "si70xx Humidity Sensor Designer's Guide" document.

Test code
1 /*2 measurement of relative humidity and temperature using Si70213 */4 5#include <Wire.h>6 7 #defineaddress_si7021 0x408 #defineMeasure_rh_hold 0xe59 #defineRead_t_from_pre_rh_measurement 0xE0Ten  One byteBuffer[] = {0,0,0}; A byteCrchumi; -  -Word Outhumi =0; theWord outtemp =0; - floatValuehumi =0; - floatValuetemp =0; -  + voidSetup () - { + Wire.begin (); ASerial.begin (115200); at } -  - voidLoop () - { -     //perform a RH measurement and read back the RH value - wire.begintransmission (address_si7021); in Wire.write (measure_rh_hold); - wire.endtransmission (); to  +Wire.requestfrom (address_si7021,3); -     if(Wire.available () >=3) the     { *buffer[0] = ();//High byte $buffer[1] = ();//Low bytePanax Notoginsengbuffer[2] = ();//CRC -     } theOuthumi = (buffer[0]<<8) | buffer[1]; +Crchumi = CRC8 (buffer,3); A      the     //read temperature from previous RH measurement + wire.begintransmission (address_si7021); - Wire.write (read_t_from_pre_rh_measurement); $ wire.endtransmission (); $  -Wire.requestfrom (address_si7021,2); -     if(Wire.available () >=2) the     { -buffer[0] = ();//High byteWuyibuffer[1] = ();//Low byte; no CRC the     } -Outtemp = (buffer[0]<<8) | buffer[1]; Wu  -Valuehumi =125.0*outhumi/65536-6; AboutValuetemp =175.72*outtemp/65536-46.85; $  -Serial.print (Valuehumi); Serial.print ("\%rh\t"); -Serial.print (valuetemp); Serial.println ("' C"); -  A     if(Crchumi = =0) +     { theSerial.println ("CRC checked."); -     } $     Else the     { theSerial.println ("CRC error!"); the     } the  -Delay4000); in } the  the byteCRC8 (byte*data,bytelen) About { the     bytecrc[8]; the     byteresult =0; the     bytei; +     byteDoinvert; -String bitstring =makestring (data, Len); the Bayi      for(i =0; I <8; i++) the     { theCrc[i] =0; -     } -  the      for(i =0; I < bitstring.length (); i + +) the     { theDoinvert = (byte(Bitstring[i] = ='1') ^ crc[7]; thecrc[7] = crc[6]; -crc[6] = crc[5]; thecrc[5] = crc[4] ^Doinvert; thecrc[4] = crc[3] ^Doinvert; thecrc[3] = crc[2];94crc[2] = crc[1]; thecrc[1] = crc[0]; thecrc[0] =Doinvert; the     }98  About      for(i =0; I <8; i++) -     {101 Bitwrite (result, I, crc[i]);102     }103 104     returnresult; the }106 107String makestring (byte*data,bytelen)108 {109     intI, J; the String Tempstring[len];111String bitstring=""; the 113      for(i =0; i < Len; i++) the     { theTempstring[i] =String (Data[i], BIN); the         intZeros =8-tempstring[i].length ();117          for(j =0; J < Zeros; J + +)118         {119Tempstring[i] ='0'+Tempstring[i]; -         }121     }122 123      for(i =0; i < Len; i++)124     { thebitstring = bitstring +Tempstring[i];126     }127  -     returnbitstring;129}
View Code

If the connection is normal, the Si7021 will trigger the measurement every 4 seconds and print the result via the serial port:


Silicon labs-si7021 Datasheet
Application note:bi-directional level shifter for I²c bus and other systems
Application note:si70xx Humidity Sensor Designer ' s Guide
Online CRC Calculation

Arduino I²c + temperature and humidity sensor Si7021

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.