Categories

Arduino and SI7021 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

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

Arduino Pins Module Pins
 3v3  Vin
 Gnd  Gnd
 SDA  SDA
 SCL  SCL

 

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
Humidity Temperature Sensor Breakout Barometric Pressure SI7021 for Arduino GY-21

Share

Arduino and SHT11 example

The SHT1x digital humidity sensor is a reflow solderable sensor. The SHT1x series consists of a low-cost version with the SHT10 humidity sensor, a standard version with the SHT11 humidity sensor, and a high-end version with the SHT15 humidity sensor. As with every other Sensirion sensor type from the SHTxx humidity sensor family, they are fully calibrated and provide a digital output.

The humidity sensors are seamlessly coupled to a 14-bit-analog-to-digital converter and a serial interface circuit. This results in superior signal quality, a fast response time, and insensitivity to external disturbances (EMC).

One thing to note is that these sensors have been effectively replaced by others in sensirion’s range such as the SHT31 but they still work and have good performance for hobbyists

 

Layout

 

Code

You need to install the library from – https://github.com/practicalarduino/SHT1x

This is the built in example

#include <SHT1x.h>
 
// Specify data and clock connections and instantiate SHT1x object
#define dataPin  10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
 
void setup()
{
   Serial.begin(38400); // Open serial connection to report values to host
   Serial.println("Starting up");
}
 
void loop()
{
  float temp_c;
  float temp_f;
  float humidity;
 
  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();
 
  // Print the values to the serial port
  Serial.print("Temperature: ");
  Serial.print(temp_c, DEC);
  Serial.print("C / ");
  Serial.print(temp_f, DEC);
  Serial.print("F. Humidity: ");
  Serial.print(humidity);
  Serial.println("%");
 
  delay(2000);
}

 

Testing

Open the serial monitor , all going well you should see something like this

Starting up
Temperature: 21.9199981689C / 71.5639953613F. Humidity: 47.88%
Temperature: 21.9499969482C / 71.5999984741F. Humidity: 47.88%
Temperature: 21.9499969482C / 71.5819931030F. Humidity: 47.85%

 

Links
SHT11 Digital Temperature and Humidity Sensor,Single bus output temperature and humidity module

Share

Arduino and PCF8563 RTC example

The PCF8563 is a CMOS Real-Time Clock (RTC) and calendar optimized for low power consumption. A programmable clock output, interrupt output, and voltage-low detector are also provided. All addresses and data are transferred serially via a two-line bidirectional I²C-bus. Maximum bus speed is 400 kbit/s.

This is an easy to use module for this device

Features

  • Provides year, month, day, weekday, hours, minutes, and seconds based on a 32.768 kHz quartz crystal
  • Century flag
  • Clock operating voltage: 1.0 V to 5.5 V at room temperature
  • Low backup current; typical 0.25 μA at VDD = 3.0 V and Tamb = 25 °C
  • 400 kHz two-wire I²C-bus interface (at VDD = 1.8 V to 5.5 V)
  • Programmable clock output for peripheral devices (32.768 kHz, 1.024 kHz, 32 Hz, and 1 Hz)
  • Alarm and timer functions
  • Integrated oscillator capacitor
  • Internal Power-On Reset (POR)
  • I²C-bus slave address: read A3h and write A2h
  • Open-drain interrupt pin

 

This is the schematic for a typical module

pcf8563 schematic

pcf8563 schematic

Here is how to connect the module to your Arduino

Connection

Arduino Pin Module Pin
 5v  Vcc
GND Gnd
A5 SCL
A4 SDA

 

Code

You do not need a library but I downloaded the library from https://bitbucket.org/orbitalair/arduino_rtc_pcf8563/downloads

This is one of the basic examples

/* Demonstration of Rtc_Pcf8563 Alarms. 
 *
 * The Pcf8563 has an interrupt output, Pin3.
 * Pull Pin3 HIGH with a resistor, I used a 10kohm to 5v.
 * I used a RBBB with Arduino IDE, the pins are mapped a 
 * bit differently.  Change for your hw.
 * SCK - A5, SDA - A4, INT - D3/INT1
 *
 * After loading and starting the sketch, use the serial monitor
 * to see the clock output.
 * 
 * setup:  see Pcf8563 data sheet.
 *         1x 10Kohm pullup on Pin3 INT
 *         No pullups on Pin5 or Pin6 (I2C internals used)
 *         1x 0.1pf on power
 *         1x 32khz chrystal
 *
 * Joe Robertson, jmr
 * orbitalair@bellsouth.net
 */
#include <Wire.h>
#include <Rtc_Pcf8563.h>
 
/* get a real time clock object */
Rtc_Pcf8563 rtc;
/* a flag for the interrupt */
volatile int alarm_flag=0;
 
/* the interrupt service routine */
void blink()
{
  alarm_flag=1;
}
 
void setup()
{
  pinMode(3, INPUT);           // set pin to input
  digitalWrite(3, HIGH);       // turn on pullup resistors
 
  Serial.begin(9600);
 
  /* setup int on pin 3 of arduino */
  attachInterrupt(1, blink, FALLING);
  /* clear out all the registers */
  rtc.initClock();
  /* set a time to start with.
   * day, weekday, month, century, year */
  rtc.setDate(14, 6, 3, 0, 10);
  /* hr, min, sec */
  rtc.setTime(1, 15, 40);
  /* set an alarm for 20 secs later...
   * alarm pin goes low when match occurs
   * this triggers the interrupt routine
   * min, hr, day, weekday 
   * 99 = no alarm value to be set
   */
  rtc.setAlarm(16, 99, 99, 99);
}
 
void loop()
{
  /* each sec update the display */
  Serial.print(rtc.formatTime());
  Serial.print("  ");
  Serial.print(rtc.formatDate());
  Serial.print("  0x");
  Serial.print(rtc.getStatus2(), HEX);
  Serial.print("\r\n");
  delay(1000);
  if (alarm_flag==1){
    clr_alarm();
  }
 
}
 
void clr_alarm()
{
  detachInterrupt(1);
  Serial.print("blink!\r\n");
 
  rtc.clearAlarm();
  delay(1000);
  alarm_flag=0;
  attachInterrupt(1, blink, FALLING);
}

 

Links
PCF8563 RTC Board PCF8563T CMOS Real-time Clock/Calendar Development Module

Share

Arduino and GP2Y0A21YK Distance Sensor

the GP2Y0A21 is an infrared proximity sensor made by Sharp. Part # GP2Y0A21YK has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. The sensor has a Japanese Solderless Terminal (JST) Connector.

FEATURES

• Digital Output
• LED Pulse Cycle Duration: 32 ms
• Range: 10 to 80 cm
• Typical response time: 39 ms
• Typical start up delay: 44 ms
• Average Current Consumption: 30 mA
• Detection Area Diameter @ 80 cm: 12 cm

 

Schematic

Code

/*  
VCC -- VCC  
GND -- GND  
Signal -- Analog 0 
 */
 
#define pin A0
 
void setup () 
{
  Serial.begin (9600);
  pinMode (pin, INPUT);
}
 
void loop () 
{
  uint16_t value = analogRead (pin);
  uint16_t range = get_gp2d12 (value);
  Serial.println (value);
  Serial.print (range);
  Serial.println (" mm");
  Serial.println ();
  delay (1000);
}
 
uint16_t get_gp2d12 (uint16_t value) 
{
  if (value < 10) value = 10;
  return ((67870.0 / (value - 3.0)) - 40.0);
}

 

Link
GP2Y0A21YK0F GP2Y0A21 Infrared Proximity Sensor IR Analog Distance Sensor VE713 P

Share