Humidity Sensor (HIH-4030) + IOIO-OTG

256 views
Skip to first unread message

Al B

unread,
Aug 3, 2013, 3:06:35 AM8/3/13
to ioio-...@googlegroups.com
Has anyone used the Humidity Sensor (HIH-4030) with the IOIO?

 I'm trying to reproduce the Bildr example (http://bildr.org/2012/11/hih4030-arduino/), but I keep just getting the same -25.6 as the humidity value all the time.

float HIH4030_voltage = HIH4030_input.getVoltage() * supplyVolt / 1023;
float sensorRH = ((HIH4030_voltage - zeroOffset) / slope);
float humidity = sensorRH / (1.0546f - (0.00216f * degreesCelsius));

https://www.sparkfun.com/datasheets/Sensors/Weather/SEN-09569-HIH-4030-datasheet.pdf

TIA!

Al B

unread,
Aug 3, 2013, 2:59:22 PM8/3/13
to ioio-...@googlegroups.com
The problem seems to be with the converted voltage calculation (0.13548388 * 5.0 / 1023) so is a 10-bit (2^10) resolution correct for the IOIO?

IOIO VOLTAGE: 0.13548388
CONVERTED VOLTAGE: 6.6218904E-4
SENSOR RH: -25.785088
TRUE RH: -25.506996


private static final float supplyVolt = 5.0f;
private static final float adResolution = 1023;   //10-bit (2^10) resolution
private static final float slope = 0.0062f * supplyVolt;
private static final float zeroOffset = 0.16f * supplyVolt;

Al Linke

unread,
Aug 4, 2013, 11:51:31 PM8/4/13
to ioio-...@googlegroups.com
Hey Al, I haven't used this sensor myself but as you may know, IOIO analog inputs are not 5V tolerant so I'd first try running this sensor with 3.3V power and if that doesn't work, then you'll need to add a resistor ladder/voltage divider to keep the analog input from going higher than 3.3V. 

Rich Mayfield

unread,
Aug 5, 2013, 1:54:56 PM8/5/13
to ioio-...@googlegroups.com
You guys know what has a great voltage divider built in for this very purpose? Hint- Al B has one :)

-Rich

Al B

unread,
Aug 5, 2013, 4:18:45 PM8/5/13
to ioio-...@googlegroups.com
Hi Al,

I failed to mention that I am using Rich's shield adapter; which has a voltage divider built in it as he indicated (see attached pic).  However, thanks for pointing out the 5V tolerant.  I think the problem is with calculation (mV vs V vs adResolution, etc.) since the Bildr and other examples are for the Arduino and the IOIO might be handling things differently so I need to play with it.

Thanks again!



On Sunday, August 4, 2013 8:51:31 PM UTC-7, Al Linke wrote:
photo.JPG

Al B

unread,
Aug 14, 2013, 12:13:05 AM8/14/13
to ioio-...@googlegroups.com
This question might be more about Rich's shield adapter than for the IOIO board.  However, since Rich is subscribed to this group, then he or others may be able to chime in.

I'm getting a very low voltage from the IOIO input.  The sequence is:

Vin(5V)---->|HIH-4030|--->Vout(2.4V) ---> Shield Adapter(pin1) --->ladder resistors(5.1k and 10k) --->IOIO(pin 41) --->getVoltage() returns(0.129)

2.4 is a correct Vout value since it matches the 60%RH in the sensor datasheet and my Fluker's Hygrometer.  However, I not sure why the voltage drops so much (down to 0.129) when he goes through the shield (15.1K) resistors.  Should I add another resistor(s) to increase the Volts or am I calling the wrong API method?


Ytai Ben-Tsvi

unread,
Aug 14, 2013, 12:36:44 AM8/14/13
to ioio-...@googlegroups.com
Have you tried bypassing the shield for testing purposes? If you verify that the output is <=3.3V just before plugging in, then it should be safe to feed directly into pin for testing purposes.


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.

Al B

unread,
Aug 14, 2013, 1:08:20 AM8/14/13
to ioio-...@googlegroups.com
I just did that and got the correct value directly from IOIO so it's definitely caused by the shield.  I'm gonna contact Rich directly then.

IOIO(pin 41) --> 2.251V; which is about 46%RH right now.

Thanks Ytai!
photo.JPG
Screen Shot 2013-08-13 at 9.59.17 PM.png

Ytai Ben-Tsvi

unread,
Aug 14, 2013, 1:36:39 AM8/14/13
to ioio-...@googlegroups.com
I don't think it necessarily has anything to do with the shield, it might as well be that this sensor expects a very high impedance load, which the resistor ladder isn't (15K).
It seems from the datasheet that if you power the thing at 4V or so it's output will be in the valid range for the IOIO.
Another possibility (not ideal in terms of measurement precision) is to scale up the ladder (e.g. 47k:100k).
And last, a unity-gain amplifier is the "proper" way of doing this.


--

Ytai Ben-Tsvi

unread,
Aug 14, 2013, 1:37:20 AM8/14/13
to ioio-...@googlegroups.com
Or, sorry, not exactly unity-gain, you actually want to attenuate.

Rich Mayfield

unread,
Aug 14, 2013, 2:45:00 AM8/14/13
to ioio-...@googlegroups.com
Yeah, if you can get the sensor to output a voltage range that works for the ioio, then that's preferable to using the scaling resistors. You can always bypass them. That being said, here's how I test my adapters:


2. Disconnect everything but the shield and the IOIO...run the app. When it's connected, all the "No Data" fields should change to voltage readouts.

3. Take a jumper wire and run it from the 3.3V pin to one of the analog inputs. 

4. That voltage should read 1.96 if the scaling dip switch is active and 3.3 if it's not.

As Ytai has alluded to, sensor design is a tricky thing. I tried to pick a good voltage divider for things that I do and use them for, but it might not always be the best for your application. If you're really getting into it, just remember, you can always bypass the voltage divider.

Marius Vosylius

unread,
Apr 7, 2014, 7:42:16 AM4/7/14
to ioio-...@googlegroups.com
Ytai, I have same sensor HIH4030, and I cant even get Voltage, does it means that my sensor is not working? 

Heres my code below:

class Looper extends BaseIOIOLooper { 

private AnalogInput aiH

@Override

protected void setup() throws ConnectionLostException { 

aiH = ioio_.openAnalogInput(41); 

       

    runOnUiThread(new Runnable() { 

    public void run() { 

    Toast.makeText(getApplicationContext(), 

    "HIH4030 Connected!", Toast.LENGTH_SHORT).show(); 

    }        

    }); 

}


public void loop() throws ConnectionLostException { 

runOnUiThread(new Runnable() { 

public void run() {

try

txtVoltage.setText("Voltage " + String.format("%.2f", aiH.getVoltage()) + " V"); 

txtHumidity.setText(String.format("%.2f", (aiH.getVoltage() - 0.958) / 0.0307)  + "% RH"); 

progressBarHumid.setProgress((int)((float)(aiH.getVoltage() * 100 / 3.3 )));

} catch (InterruptedException e) { 

e.printStackTrace(); 

} catch (ConnectionLostException e) { 

e.printStackTrace(); 

}

        }        

    }); 

        try

        Thread.sleep(500); 

        } catch (InterruptedException e) { 

        e.printStackTrace(); 

        } 

}  

Cant even get Toast message to appear. 
 
 

Marius Vosylius

unread,
Apr 7, 2014, 9:30:38 AM4/7/14
to ioio-...@googlegroups.com
AI B, can you please share with your code, just want to see what I'm doing wrong. Thanks.

Ytai Ben-Tsvi

unread,
Apr 7, 2014, 11:59:48 AM4/7/14
to ioio-...@googlegroups.com
If the toast does appear, this has nothing to do with the rest of the code. IOIOSimpleApp does about the same as your code (reads from pin 40 instead of 41). Better try that one first.


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Marius Vosylius

unread,
Apr 7, 2014, 12:45:11 PM4/7/14
to ioio-...@googlegroups.com
Thanks Ytai, I changed my pin to 40 and used simple app to get reading which is 0.017+. How will i go to get humidity please?

Marius Vosylius

unread,
Apr 7, 2014, 12:45:28 PM4/7/14
to ioio-...@googlegroups.com

Marius Vosylius

unread,
Apr 7, 2014, 12:48:32 PM4/7/14
to ioio-...@googlegroups.com
Sorry Ytai, I gave you wrong reading, its actually 0.50+

Ytai Ben-Tsvi

unread,
Apr 7, 2014, 1:08:24 PM4/7/14
to ioio-...@googlegroups.com

Read the beginning of this thread, I think most of the information is there. Don't forget to use a voltage divider in order to scale the voltage into the 0-3.3V range that the IOIO can handle. You can also put a capacitor in parallel to the low side resistor of that ladder to improve accuracy and overcome the high impedance problem.

On Apr 7, 2014 9:48 AM, "Marius Vosylius" <marius....@gmail.com> wrote:
Sorry Ytai, I gave you wrong reading, its actually 0.50+

--

Marius Vosylius

unread,
Apr 7, 2014, 1:18:12 PM4/7/14
to ioio-...@googlegroups.com

I'm using 3.3v pin. What resistor I need to use?

You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/yEnGR1s-QT8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.

Ytai Ben-Tsvi

unread,
Apr 7, 2014, 8:17:57 PM4/7/14
to ioio-...@googlegroups.com
I don't see in the datasheet anything to mention correct operation at 3.3V. So I recommend you use 5V, 47k:150k divider or so (will scale your voltage reading by 0.761), with a ceramic capacitor (say, anywhere between10nF and 10uF) in parallel with the low-side resistor.

Matanel

unread,
Apr 16, 2014, 9:52:57 AM4/16/14
to ioio-...@googlegroups.com
Hay,
I am used in STH21 - Humidity and Temperature Sensor, and it's worked to me.
Do you want my project that read this sensor?

Marius Vosylius

unread,
Apr 16, 2014, 10:12:01 AM4/16/14
to ioio-...@googlegroups.com

Please, it would be great to have few examples.

--

Matanel

unread,
Apr 18, 2014, 4:36:40 AM4/18/14
to ioio-...@googlegroups.com
The following app show temperature and relative humidity using SHT21 sensor.
STH21 connecting to IOIO by I2C protocol. The app include CRC-8.

SHT21 pins:
VCC - IOIO 3.3V
SDA - IOIO pin 4 
SCL - IOIO Pin 5
Gnd - IOIO Gnd

Enjoy.
 
IOIOSHT21.rar
SHT21.png
Reply all
Reply to author
Forward
0 new messages