Relative Humidity Project

So, how hard would it be to hook up a Relative Humidity Sensor to a Sun SPOT? I was asked that question not long ago, and of course I said "Easy. Shouldn't take long at all!"

So then I had to put my money where my (big) mouth was. So I Googled "Humidity Sensor" and found Precon USA that had both analog and digital Temperature and Humidity sensors. And they are cheap (relatively) at only $29.95 each. So, of course, I ordered two.

They arrived a few days later, and looking at the datasheet, it appeared that even I could hook it up relatively easily. Four leads, analog output, voltage-based. Easy.

Here's what the sensor looks like out of the box:

DSCN0701.JPG

No, the quarter didn't come with it, but everyone uses a US Quarter to show the relative size, so I have to as well.

Next it was time to test it out. So before doing any serious wiring, I hooked it up with jumpers to get some data off of it and see if I could make it work. Turns out it was easier than I thought. Once hooked in with jumpers (which looks like this)

DSCN0702.JPG

I grabbed a snippet of code to access the sensors, and ran it. The code is as follows:

    protected void startApp() throws MIDletStateChangeException { 
        ITemperatureInput temp = EDemoBoard.getInstance().getADCTemperature();
        IScalarInput rh = EDemoBoard.getInstance().bindScalarInput(EDemoBoard.A3);
        IScalarInput tmp = EDemoBoard.getInstance().bindScalarInput(EDemoBoard.A2);
        IScalarInput vref = EDemoBoard.getInstance().bindScalarInput(EDemoBoard.A1);       
        while ( true ) {
            try {
                double rhVal = ((double)rh.getValue()/(double)vref.getValue()) \* 100;
                double tmpVal = (((double)tmp.getValue()-115) / (double)vref.getValue()) \* 100;
                System.out.println("current RH       : " + rhVal  + "%");
                System.out.println("current Temp     : " + tmpVal + " deg. C");
                System.out.println("Onboard Temp     : " + temp.getCelsius());
                Thread.sleep(3000);
            } catch ( Exception e ) {
            }
        }
    }
Yes, that is pretty much the entire application (minus the import statements and other surrounding cruft). Granted it doesn't do much other than print out the Relative Humidity reading and the two temperature readings every 3 seconds, but it only took me about 5 minutes to write it. The only interesting things to note are that the Relative Humidity and Temperature readings are scaled values based on the voltage, so I just pulled a lead from the 5.5+ pin to analog pin 1, and I have my reference voltage.

So once I had that all working, I decided to wire it up a little more permanently, so I put some jumpers on a connector, soldered a 4-lead socket to the leads, and hot glued the whole thing to the header. In order, it looks like this:

DSCN0703.JPG DSCN0704.JPG DSCN0705.JPG

Finally, I just plugged the sensor into the socket, and the header onto the Sun SPOT, and I was done. I now have a Sun SPOT that measures temperature twice, and Relative Humidity.

DSCN0706.JPG
And it took me less than an hour. So I guess I was right in the beginning when I said I could do it, and it wouldn't take long at all!

[17th Rule of Friendship: A friend will refrain from telling you he picked up the same amount of life insurance coverage you did for half the price when yours is noncancellable. -- Esquire, May 1977]

Comments:

Post a Comment:
Comments are closed for this entry.
About

user9157252

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today