This is code for the Honeywell HIH-4030 humidity sensor (SparkFun SKU: SEN-09569).
Please note that the sensor is supposed to be used with 5v input, but it works just fine with 3.3v input because the output is linear.
The code below is tailored to 3.3v input.
/// <summary> /// Honeywell HIH-4030 humidity sensor (SEN-09569). /// Please note that the sensor is supposed to be used with 5v input, /// but it works just fine with 3.3v input because the output is linear. /// The code below is tailored to 3.3v input. /// </summary> public class HIH4030 : IDisposable { private AnalogInput _sensor; private bool _disposed; protected virtual void Dispose(bool disposing) { // Check if Dipose has already been called. if (!_disposed) { if (disposing) { _sensor.Dispose(); _disposed = true; } } } ~HIH4030() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); // tell the GC not to finalize. } public HIH4030(Cpu.Pin analogPin) { _sensor = new AnalogInput(analogPin); _sensor.SetRange(0, 3300); } /// <summary> /// Calculates the relative humidity with temperature compensation. /// </summary> /// <param name="temp">Current temperature in Celsius.</param> /// <returns>Returns the relative humidity as a percentage.</returns> public double RelativeHumidity(float temp) { // Get the humidity sensor reading. int sensorReading = _sensor.Read(); // Calculate the humidity sensor voltage. double sensorVoltage = (((double)sensorReading / 3300) * 3.3); // Define the voltage the sensor returns at 0% humidity. double zeroVoltage = 0.528; /* It has been observed that some sensors are consistently * inaccurate and off by a certain voltage than what they * should be. Use this variable to compensate for what the * voltage should be if needed. */ double calibrationVoltage = 0.00; /* Determine the maxium voltage of the sensor with temperature compensation. */ double maxVoltage = (2.1582 - (0.004426 * temp)); /* Determine the temperature compensated relative humidity as a percentage. */ double rh = ((sensorVoltage + calibrationVoltage - zeroVoltage) / maxVoltage) * 100; return rh; } }
Hi, can you explain me, based on the spec sheet how you calculate the constants inf formulas? i have a hih-5030 but i can't understand how determinate the values for this sensor...
Regards
Virgilio