/// <summary> /// Read temperature compensated relative humidity /// </summary> /// <param name="VDD">VDD for SHT11</param> /// <returns>Relative Humidity in percent</returns> public double ReadRelativeHumidity(SHT11VDD_Voltages VDD) { double c1; double c2; double c3; double t1; double t2; // Check if we have 8 or 12 bits humidity if (((byte)ReadStatusRegister() & 0x01) == 0x01) { // 8 bit c1 = -2.0468F; c2 = 0.5872F; c3 = -4.0845E-4F; t1 = 0.01F; t2 = 0.00128F; } else { // 12 bit c1 = -2.0468F; c2 = 0.0367F; c3 = -1.5955E-6F; t1 = 0.01F; t2 = 0.00008F; } // Read Humidity from SHT11 double SOrh = ReadHumidityRaw(); // Calculate relative humidity double RHlinear = c1 + (c2 * SOrh) + (c3 * (SOrh * SOrh)); // Read Temperature for temperature compensation double Tc = ReadTemperature(VDD, SHT11TemperatureUnits.Celcius); // Calculate temperature compensated humidity double RHtrue = ((Tc - 25.0F) * (t1 + (t2 * SOrh))) + RHlinear; // Return Relative Humidity return(RHtrue); }
/// <summary> /// Read Temperature /// </summary> /// <param name="VDD">VDD Voltage for SHT11</param> /// <param name="TemperatureUnit">Temperature units to return</param> /// <returns>Temperature in TemperatureUnit units</returns> public double ReadTemperature(SHT11VDD_Voltages VDD, SHT11TemperatureUnits TemperatureUnit) { double readTemp = 0.0F; double multplier = 0.0F; if (TemperatureUnit == SHT11TemperatureUnits.Celcius) { switch (VDD) { case SHT11VDD_Voltages.VDD_2_5V: readTemp = -39.4F; break; case SHT11VDD_Voltages.VDD_3_5V: readTemp = -39.7F; break; case SHT11VDD_Voltages.VDD_3V: readTemp = -39.6F; break; case SHT11VDD_Voltages.VDD_4V: readTemp = -39.8F; break; case SHT11VDD_Voltages.VDD_5V: readTemp = -40.1F; break; } } if (TemperatureUnit == SHT11TemperatureUnits.Farenheid) { switch (VDD) { case SHT11VDD_Voltages.VDD_2_5V: readTemp = -38.9F; break; case SHT11VDD_Voltages.VDD_3_5V: readTemp = -39.5F; break; case SHT11VDD_Voltages.VDD_3V: readTemp = -39.3F; break; case SHT11VDD_Voltages.VDD_4V: readTemp = -39.6F; break; case SHT11VDD_Voltages.VDD_5V: readTemp = -40.2F; break; } } // Check if we have 12 or 14 bits temperature if (((byte)ReadStatusRegister() & 0x01) == 0x01) { // 12 Bit switch (TemperatureUnit) { case SHT11TemperatureUnits.Farenheid: multplier = 0.072F; break; case SHT11TemperatureUnits.Celcius: multplier = 0.04F; break; } } else { // 14 Bit switch (TemperatureUnit) { case SHT11TemperatureUnits.Farenheid: multplier = 0.018F; break; case SHT11TemperatureUnits.Celcius: multplier = 0.01F; break; } } // Calculate actual temperature readTemp += (double)ReadTemperatureRaw() * multplier; // Return temperature return readTemp; }
/// <summary> /// Read temperature compensated relative humidity /// </summary> /// <param name="VDD">VDD for SHT11</param> /// <returns>Relative Humidity in percent</returns> public double ReadRelativeHumidity(SHT11VDD_Voltages VDD) { double c1; double c2; double c3; double t1; double t2; // Check if we have 8 or 12 bits humidity if (((byte)ReadStatusRegister() & 0x01) == 0x01) { // 8 bit c1 = -2.0468F; c2 = 0.5872F; c3 = -4.0845E-4F; t1 = 0.01F; t2 = 0.00128F; } else { // 12 bit c1 = -2.0468F; c2 = 0.0367F; c3 = -1.5955E-6F; t1 = 0.01F; t2 = 0.00008F; } // Read Humidity from SHT11 double SOrh = ReadHumidityRaw(); // Calculate relative humidity double RHlinear = c1 + (c2 * SOrh) + (c3 * (SOrh * SOrh)); // Read Temperature for temperature compensation double Tc = ReadTemperature(VDD, SHT11TemperatureUnits.Celcius); // Calculate temperature compensated humidity double RHtrue = ((Tc - 25.0F) * (t1 + (t2 * SOrh))) + RHlinear; // Return Relative Humidity return RHtrue; }
/// <summary> /// Read Temperature /// </summary> /// <param name="VDD">VDD Voltage for SHT11</param> /// <param name="TemperatureUnit">Temperature units to return</param> /// <returns>Temperature in TemperatureUnit units</returns> public double ReadTemperature(SHT11VDD_Voltages VDD, SHT11TemperatureUnits TemperatureUnit) { double readTemp = 0.0F; double multplier = 0.0F; if (TemperatureUnit == SHT11TemperatureUnits.Celcius) { switch (VDD) { case SHT11VDD_Voltages.VDD_2_5V: readTemp = -39.4F; break; case SHT11VDD_Voltages.VDD_3_5V: readTemp = -39.7F; break; case SHT11VDD_Voltages.VDD_3V: readTemp = -39.6F; break; case SHT11VDD_Voltages.VDD_4V: readTemp = -39.8F; break; case SHT11VDD_Voltages.VDD_5V: readTemp = -40.1F; break; } } if (TemperatureUnit == SHT11TemperatureUnits.Farenheid) { switch (VDD) { case SHT11VDD_Voltages.VDD_2_5V: readTemp = -38.9F; break; case SHT11VDD_Voltages.VDD_3_5V: readTemp = -39.5F; break; case SHT11VDD_Voltages.VDD_3V: readTemp = -39.3F; break; case SHT11VDD_Voltages.VDD_4V: readTemp = -39.6F; break; case SHT11VDD_Voltages.VDD_5V: readTemp = -40.2F; break; } } // Check if we have 12 or 14 bits temperature if (((byte)ReadStatusRegister() & 0x01) == 0x01) { // 12 Bit switch (TemperatureUnit) { case SHT11TemperatureUnits.Farenheid: multplier = 0.072F; break; case SHT11TemperatureUnits.Celcius: multplier = 0.04F; break; } } else { // 14 Bit switch (TemperatureUnit) { case SHT11TemperatureUnits.Farenheid: multplier = 0.018F; break; case SHT11TemperatureUnits.Celcius: multplier = 0.01F; break; } } // Calculate actual temperature readTemp += (double)ReadTemperatureRaw() * multplier; // Return temperature return(readTemp); }