Honeywell HIH-4030 Humidity Sensor - Project Showcase - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Honeywell HIH-4030 Humidity Sensor


  • Please log in to reply
25 replies to this topic

#1 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 04 October 2010 - 04:34 AM

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;
        }
        
    }

Attached Files



#2 Spork

Spork

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 02 September 2011 - 03:04 AM

I'm wondering if somebody can comment on the assertion that the sensor will work fine with 3.3v when it's meant to be supplied 5v. Why does the fact that it's linear matter to whether it will work when supplied 3.3v? Does that mean that the max voltage out is linear with supplied voltage? I.e. one not need worry that supplying it with 3.3v will produce >3.3v out, which would exceed Netduino's analog pin tolerance? What's the down side of supplying it 3.3v -- just lower resolution? I don't doubt that it will work and I'll probably buy it and try it out, so thanks to the OP for posting the code. It's nice for a beginner (such as myself) to have a simple analog code example.

#3 Scott Green

Scott Green

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 06 September 2011 - 02:28 AM

PhantomTypist,

I want to run my sensor on +5v. Can you tell me how you arrived at the values you used for zeroVoltage as well as 2.1582 and 0.004426 in the maxVoltage calculation? Would love to figure out how to apply these to +5V

Thanks,
Scott...

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;
        }
        
    }



#4 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 11 September 2011 - 01:19 PM

Can you please elaborate how you were going to hook this up to the Netduino using 5 volts? The ADC on the Netduino does not except voltages greater than 3.3 volts. Anything larger, i.e. 5 volts, may/will cause damage. The managed driver I wrote is configured with values to run the HIH-403x and HIH-503x series at 3.3 volts, not 5 volts. If you want a driver that runs these sensors with 5 volts, you will need to reference the datasheet for the specific model you are using. Always go to the datasheet when in doubt. All the answers are there. Datasheets are like the holy grail. The datasheet for the HIH-403x series is specifically written for use with 5 volts, so you can get the values you need to use there instead of my values (which are for 3.3 volt operation.)

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 September 2011 - 04:17 PM

PhantomTypist, you probably messed up the sensor linearity with the power supply range.
Probably your software class is working (almost) correctly, but the hardware considerations are wrong.

===Power supply
The sensor is giving a linear output as:
Vout = F(RH)
where:
  • Vout is the voltage at the sensor output;
  • RH is the relative humidity;
  • F is a linear function.
The above formula is guaranteed by the sensor's specs only within a specific supply range, that is 4..5.8V. However, I'd suggest to use 5V, as the nominal supply suggested by the manufacturer.
The sensor could NOT be powered less than 4V, as the specs say. It means you cannot supply by the +3.3V of the Netduino.
So, please, connect the sensor supply to the +5V available on the Netduino board.


===Sensor output
It's also true that you cannot wire the sensor output directly to the analog input pin: you must add *at least* a voltage divider, using a couple of resistors. That is necessary to "scale" the voltage given by the sensor, so that it will fall *always* within then allowed (safe) Netduino range (i.e. 0..3.3V).

Oh, well...the sensor can't feed so much current, very few instead.
By the way, the ADC input sucks a little current in excess of 1uA typical.
Your goal is to scale the sensor range from 0..5V to 0..3.3V, that is a factor:
alpha = 3.3 / 5 = 0.66.
So, consider placing one R=100KOhm resistor from the Netduino's input to the ground. Then wire the sensor's output to the Netduino's input (same as before), using a:
Rs = R * (1 - alpha) / alpha = 100K * (1-0.66) /0.66 = 51KOhm


===Accuracy
Since the sensor itself is not temperature-compensated, unless you add a temperature sensor, the overall humidity reading will have a noticeable error. This may sounds as a fault, but it simplifies the external circuit.
If you need a higher precision, you should:
  • add a good temperature sensor;
  • add a voltage follower, to decouple the voltage divider;
  • use high precision resistors, and maybe a good trimpot (e.g. multi-spin);
  • adjust the code of the class to compensate the humidity value;
  • consider using a better ADCs than the Netduino's.
Hope it helps.
Cheers
Biggest fault of Netduino? It runs by electricity.

#6 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 11 September 2011 - 05:10 PM

Ok, whatever works. FYI, I have a HIH-5030 and HIH-4030 running side by side at 3.3 volts. Reporting same results. HIH-4030 datasheet says that because they can't guarantee that it will work running at 3.3 volts. I've been running them indoors and outdoors side by side since June 2011 and haven't seen any issues. As to temperature compensation, yes, I have them temperature compensated. Otherwise you won't be able to get accurate relative humidity readings either way you look at them.

#7 Scott Green

Scott Green

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 11 September 2011 - 08:44 PM

Ok, whatever works.

FYI, I have a HIH-5030 and HIH-4030 running side by side at 3.3 volts. Reporting same results. HIH-4030 datasheet says that because they can't guarantee that it will work running at 3.3 volts. I've been running them indoors and outdoors side by side since June 2011 and haven't seen any issues.

As to temperature compensation, yes, I have them temperature compensated. Otherwise you won't be able to get accurate relative humidity readings either way you look at them.



I have mine working @ 5 volts now. I dont use the netduino analog inputs. I am using a DS2450 Quad D/A converter between the humidity sensor and the netduino running the 1-wire firmware.

Also, I've found that the 5 volts on the netduino is crazy noisy. I put an o-scope on the 5 volt line out of the netduino, and it had .5 volt dips about every 20us. The ripple that was on the 5 volt line was causing huge swings in voltage coming out of the sensor. I switched to a 7805 voltage regulator and the humidity is not swinging all over the place.

Scott...

#8 Spork

Spork

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 14 September 2011 - 05:57 AM

Just hooked up my HIH-4030. GND to GND, VCC to 3.3V, OUT to A0. I'm running the code posted by Phantom Typist, above.

I took a few thousand samples and the distribution looks like this:

Posted Image

I believe that the actual RH at time of sampling was somewhere in the 30%s or 40%s, so the peak is probably in the right spot. Any ideas why I'd see so much variation up and down from there? Will breadboard and jumper wire connections cause this sort of variation vs, say, soldering?

#9 Spork

Spork

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 14 September 2011 - 06:09 AM

Just connected 3.3V to AREF and still get the same thing.

#10 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 22 December 2011 - 03:00 AM

Just connected 3.3V to AREF and still get the same thing.


Sorry for not seeing this reply. Could you please post your sample application that is running this logging. I'll run it on some of my units and report back. If you could also please document the exact steps you took and conditions that were used.

#11 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 22 December 2011 - 03:47 PM

Sorry for not seeing this reply. Could you please post your sample application that is running this logging. I'll run it on some of my units and report back. If you could also please document the exact steps you took and conditions that were used.


I you are concerned about Analog noise in the Netduino, there is a great analysis here:

http://highfieldtale...se-of-netduino/

-Valkyrie-MT

#12 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 23 December 2011 - 03:28 PM

Can anyone explain how this part works:

double maxVoltage = (2.1582 - (0.004426 * temp));

Thanks!
terry

#13 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 23 December 2011 - 03:55 PM

Can anyone explain how this part works:

double maxVoltage = (2.1582 - (0.004426 * temp));

Great question. I had just assumed it was straight out of the spec sheet, but it looks nothing like the spec sheet. IMHO, it's good practice to code it to look just like the spec sheet so you can see where it came from. It may still be derived from the spec sheet, but I can't figure out how.

Here is the equation from the spec sheet for the HIH-4030 (the one used on the Sparkfun sensor)

Voltage output = (VSUPPLY)(0.0062(sensor RH) + 0.16), typical at 25 ºC
Temperature compensation True RH = (Sensor RH)/(1.0546 – 0.00216T), T in ºC


-Valkyrie-MT

#14 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 23 December 2011 - 10:20 PM

Great question. I had just assumed it was straight out of the spec sheet, but it looks nothing like the spec sheet. IMHO, it's good practice to code it to look just like the spec sheet so you can see where it came from. It may still be derived from the spec sheet, but I can't figure out how.

Here is the equation from the spec sheet for the HIH-4030 (the one used on the Sparkfun sensor)


-Valkyrie-MT


Mark,

I am using the equations from the spec sheet and the sensor seems to track well against expected values. I added an offset to the Rh to initially match the known humidity. In the equations I used 3V3 for the Vsupply.

#15 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 24 December 2011 - 12:02 AM

The datasheet is only for 5V operation. I had to adjust the calculations to compensate for the 3.3V power supply. As I've said elsewhere before, go buy the HIH-5030/5031 off of Mouser or DigiKey. That sensor was designed for 3.3V operation. As for Spork's spikes, yes those may be coming from noise on the analog lines. I've seen similar when using both HIH-4030 (5V) and HIH-5030 (3.3V) sensors. Not totally sure though. I usually take a running average on the readings and compare it to the latest reading. If the latest reading is somewhat abnormal, I will end up requesting a new reading.

#16 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 09 January 2012 - 10:11 PM

The datasheet is only for 5V operation. I had to adjust the calculations to compensate for the 3.3V power supply.

As I've said elsewhere before, go buy the HIH-5030/5031 off of Mouser or DigiKey. That sensor was designed for 3.3V operation.

As for Spork's spikes, yes those may be coming from noise on the analog lines. I've seen similar when using both HIH-4030 (5V) and HIH-5030 (3.3V) sensors. Not totally sure though.

I usually take a running average on the readings and compare it to the latest reading. If the latest reading is somewhat abnormal, I will end up requesting a new reading.


Do you mind sharing how you came out with the adjusted numbers to compensate for the 3.3v power supply?

#17 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 10 January 2012 - 06:27 PM

I am using the HIH-4030 with 5v supply in analog pin # 3 passing the current temperature in degress celcius obtained from a TMP102. The results I get are all over the place. I read a 90% humidity and then after a minute I read 25%. The sensor is about 10 cm from the board on my desk.

Here is a snapshot of the graph of the reading I do every 5 seconds which I stream to Pachube:

Posted Image

The graph can also be seen LIVE at this URL:
https://pachube.com/feeds/43909

Any ideas what could be happening?

Maybe something is wrong with the way I am calculating the Relative Humidity. Does anybody has the code for the HIH-4030 with 5v supply?

Thank you in advance.

#18 zee

zee

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 08 April 2013 - 02:01 AM

Hi phantomtypist

 

I had a Humidity Sensor - HIH 4030 and decided to try it out for my research lab. Unfortunately, i faced with an error on this ( 'HumiditySensor.HIH4030._sensor' is never assigned to, and will always have its default value null ) I did change some of the code into SecretLabs. The red font is the error i am facing. Could you tell me what is the problem.

 

 

public class HIH4030 : IDisposable
    {
[color=#ff0000;]        private SecretLabs.NETMF.Hardware.AnalogInput _sensor;[/color]
        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)
        {
            SecretLabs.NETMF.Hardware.AnalogInput _sensor = new SecretLabs.NETMF.Hardware.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;
        }
 
Thanks!

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;        }            }


#19 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 08 April 2013 - 02:56 PM

Hi zee.

 

Since there aren't any static methods in the class and the class itself is not static, you must create an instance.  And you create it using the only constructor provided.  That constructor takes in one argument which is an analog pin.  The code in the constructor initializes the _sensor AnalogInput property.  So once you instantiate the class, _sensor will not be null.



#20 zee

zee

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 09 April 2013 - 09:32 AM

I did follow what u had mention earlier on but I could not get to the output. There was no error when i run it.

Could you show me how to code? Sorry for the trouble

 

Hi zee.

 

Since there aren't any static methods in the class and the class itself is not static, you must create an instance.  And you create it using the only constructor provided.  That constructor takes in one argument which is an analog pin.  The code in the constructor initializes the _sensor AnalogInput property.  So once you instantiate the class, _sensor will not be null.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.