Shop OBEX P1 Docs P2 Docs Learn Events
Stamp2 Cloud & Dew Sensor — Parallax Forums

Stamp2 Cloud & Dew Sensor

everesteverest Posts: 141
edited 2009-06-02 15:10 in BASIC Stamp
All,

Given how much help I've gotten on the forum, I thought I'd post the code for my latest project, which is working just perfectly at this point. . .at least so far!! This project consists of a Sensiron temp/humidity sensor, and a 10 degree IR sensor, both stock units purchased from Parallax. The Sensiron is wired to pins 4 and 5, and the MLX90614 is wired to pins 1, 2, and 3. I've added a total of 6 LEDs to pins 10-15 to this as well to provide a nice visual indicator of the currently measure environmental conditions, those are option if you were add an LCD or just hook it to a computer to see the debug output, which shows all the measured environmental data.

This will ultimately be included in my observatory for the purposes of detecting adverse conditions to stargazing, specifically cloud cover and heavy dew/moisture. If the MLX90614 is pointed straight up in the air, the unit will report on the cloud conditions: cloudy, overcast, or clear. Pin 12 will light up if either clouds or heavy dew/moisture is detected.

The debug output includes:

Ambient Temperature
Ambient Humidity
Current Dew Point
Sky Temperature
Cloud Conditions

I've been testing the unit and it's extremely accurate, detecting all but the thinnest of clouds, but it usually even catches those. You can adjust the sensitivity as noted in the code.

I do have a question. . .I'm looking to make this code more efficient and use less space on my Stamp2. . .any suggestions along those lines (or anything else) would be much appreciated. Thanks!

-Jeff

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-02 04:01
    When you have routine that have the same thing in it put that in a sub routine and call it up
    you save 1% of memory buy doing that

    This can be put in a sub routine you had it three times in you· code

    LOW 15
    LOW 14
    LOW 13
    LOW 12



    You may find·other thing that are the same and you do same thing

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/2/2009 4:06:34 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2009-06-02 05:07
    As sam pointed out, you can optimize some of your pin settings, although with what sam mentioned you could do it in a single line by setting the nib (rather than bit).

    Your if/else s can be optimized (and clarified) by making them elseif s:
    DEBUG "Cloud Conditions: "
    
    IF (TempDelta = 999) THEN
      DEBUG "Unknown", CR
      PAUSE 2000
      GOTO Restart
    ENDIF
    
    LOW 12
    LOW 11
    LOW 10
    cloudSafe = 0
    
    
    
    IF TempDelta > 6000 THEN   ' Ambient temps are cooler than sky temps, definitely overcast!
      DEBUG "Cloudy", CR
      cloudSafe = 1
    ELSEIF (TempDelta >= 35) THEN   ' More than a 35, 36 or 37 degree differential usually means clear skies!
      DEBUG "Clear", CR
      IF (humSafe = 0) THEN
        HIGH 12
        HIGH 11
      ENDIF
    
    ELSEIF (TempDelta >= 30) THEN    ' 25 degres is getting overcast. . .
      DEBUG "Overcast", CR
      HIGH 12
    ELSE   ' This just about always means clouds. . .
      DEBUG "Cloudy", CR
    ENDIF
    
    GOTO Restart
    
  • everesteverest Posts: 141
    edited 2009-06-02 15:10
    Wow, that is much cleaner! Thanks!

    -Jeff
Sign In or Register to comment.